-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelper.sh
More file actions
executable file
·208 lines (171 loc) · 5.16 KB
/
Copy pathhelper.sh
File metadata and controls
executable file
·208 lines (171 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
build() {
# this is old, use fetch-local and podman compose
if [[ "$1" == "local" ]]; then
(cd ../fetch-local \
&& exec ./helper.sh build-inventory-api);
fi
if [[ "$1" == "develop" ]]; then
# this is old, revisit later
./dev-build.sh;
fi
if [[ "$1" == "test" ]]; then
# this is old, revisit later
./test-build.sh;
fi
}
build-db() {
(cd ../fetch-local && exec ./helper.sh build-inventory-db);
}
refresh-db() {
# Wipe db and build
(cd ../fetch-local && exec ./helper.sh wipe-inventory-db);
# Give the db a moment to catch its breath
sleep 5;
# Then rebuild from podman compose for schema
(cd ../fetch-local \
&& exec ./helper.sh build-inventory-api);
}
seed-fake-data() {
# this gets called from fetch-local
# don't call this directly
# do not indent on shell str
SEED_FAKE_DATA="
from app import main
from app.seed.seed_fake_data import seed_fake_data
seed_fake_data()
";
podman exec -it fetch-inventory-api python -c "$SEED_FAKE_DATA";
}
run-storage-migration() {
# do not indent on shell str
RUN_DATA_MIGRATION="
from app import main
from app.seed.seed_data import seed_data
seed_data()
";
podman exec -it fetch-inventory-api python -c "$RUN_DATA_MIGRATION";
}
run-tray-migration() {
# do not indent on shell str
RUN_TRAY_MIGRATION="
from app import main
from app.seed.seed_data import seed_containers
seed_containers()
";
podman exec -it fetch-inventory-api python -c "$RUN_TRAY_MIGRATION";
}
run-item-migration() {
# do not indent on shell str
RUN_ITEM_MIGRATION="
from app import main
from app.seed.seed_data import seed_items
seed_items()
";
podman exec -it fetch-inventory-api python -c "$RUN_ITEM_MIGRATION";
}
run-available-space-migration() {
# do not indent on shell str
RUN_SPACE_MIGRATION="
from app import main
from app.seed.seed_data import seed_initial_available_space_calc
seed_initial_available_space_calc()
";
podman exec -it fetch-inventory-api python -c "$RUN_SPACE_MIGRATION";
}
run-addressing-migration() {
# do not indent on shell str
RUN_ADDRESS_MIGRATION="
from app import main
from app.seed.seed_data import seed_location_address_values
seed_location_address_values()
";
podman exec -it fetch-inventory-api python -c "$RUN_ADDRESS_MIGRATION";
}
run-barcode-cleanup() {
RUN_BARCODE_CLEANUP="
from app import main
from app.seed.seed_data import seed_unused_barcode_cleanup
seed_unused_barcode_cleanup()
";
podman exec -it fetch-inventory-api python -c "$RUN_BARCODE_CLEANUP";
}
extract-data-migration() {
# This can take like 20 minutes
# dump in postgres native sql format
# you may have to jump into the container shell and do this manually
(podman exec -i inventory-database pg_dump -U postgres -d inventory_service -Fc > /tmp/fetch_dump_$(date +%m-%d-%Y).dump);
# compress to xz
(podman exec -i inventory-database xz /tmp/fetch_dump_$(date +%m-%d-%Y).dump);
# podman doesn't create host directory, so you have to do this
(mkdir -p ~/Desktop/fetch_migration);
# copy the compressed dump to host
(podman cp inventory-database:/tmp/fetch_dump_$(date +%m-%d-%Y).dump.xz ~/Desktop/fetch_migration/fetch_dump_$(date +%m-%d-%Y).dump.xz);
}
extract-migration-errors() {
# podman doesn't create host directory, so you have to do this
(mkdir -p ~/Desktop/fetch_migration);
# If there are none, this will have an error
(podman cp fetch-inventory-api:/code/app/seed/errors ~/Desktop/fetch_migration);
}
makemigrations() {
USE_MIGRATION_URL=true alembic revision --autogenerate -m $1
}
migrate() {
USE_MIGRATION_URL=true alembic upgrade head
}
current() {
USE_MIGRATION_URL=true alembic current
}
downgrade-1() {
USE_MIGRATION_URL=true alembic downgrade -1
}
api() {
# gets you inside the inventory_service api shell
podman exec -it fetch-inventory-api /bin/bash;
}
database() {
# gets you inside the db container shell
podman exec -it inventory-database /bin/bash;
}
psql() {
# gets you into the pg engine psql on the container
podman exec -it -u postgres inventory-database psql -a inventory_service
}
drop-db() {
podman exec -it -u postgres inventory-database psql -d postgres -c "DROP DATABASE IF EXISTS inventory_service WITH (FORCE);" -c "CREATE DATABASE inventory_service;"
}
unzip-dump() {
# decompresses without destruction. Not necessary. pg_restore can read compressed.
xz -dk ~/Desktop/fetch_migration/$1
}
pg-restore() {
# restores database on database container from compressed dump
(podman cp ~/Desktop/fetch_migration/$1 inventory-database:/tmp/$1);
(podman exec -it -u postgres inventory-database sh -c "xz -dc /tmp/$1 | pg_restore -U postgres -d inventory_service");
}
inspect-table() {
tablename=$1
podman exec -ti -u postgres inventory-database psql -a inventory_service -c "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '${tablename}';"
}
inspect-records() {
tablename=$1
podman exec -ti -u postgres inventory-database psql -a inventory_service -c "SELECT * FROM $1;"
}
idle() {
# poetry shell;
# python;
podman exec -it fetch-inventory-api python;
}
test() {
pytest
}
encrypt() {
value=$1
echo -n $value | base64
}
decrypt() {
value=$1
echo `echo $value | base64 --decode`
}
"$@"