-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrator.py
More file actions
32 lines (24 loc) · 714 Bytes
/
migrator.py
File metadata and controls
32 lines (24 loc) · 714 Bytes
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
import sys
from models.product import Product
from models.alert import Alert
from models.price import Price
all_models = [Product, Alert, Price]
def up():
# Migrate all products
for model in all_models:
if not model.table_exists():
model.create_table()
def down():
for model in all_models[::-1]:
if model.table_exists():
model.drop_table()
if __name__ == "__main__":
if not sys.argv:
print("You must provide an argument: up or down.")
direction = sys.argv[1]
if direction.lower() == 'up':
up()
elif direction.lower() == 'down':
down()
else:
print("Unknown command. Available commands are: up or down")