This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tools.py
61 lines (43 loc) · 1.56 KB
/
tools.py
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
import argparse
import os
import subprocess
def run_migrations(args):
print("Running migrations with Alembic")
print("===============================\n")
env = os.environ.copy()
env["PYTHONPATH"] = "."
env["PATH"] = "{}:{}".format(os.path.expanduser("~/.local/bin"), env["PATH"])
sp = subprocess.Popen(["alembic", "upgrade", "head"], env=env)
sp.wait()
def create_migrations(args):
print("Creating revision with Alembic")
print("==============================\n")
message = args.message
env = os.environ.copy()
env["PYTHONPATH"] = "."
env["PATH"] = "{}:{}".format(os.path.expanduser("~/.local/bin"), env["PATH"])
sp = subprocess.Popen(["alembic", "revision", "--autogenerate", "-m", message], env=env)
sp.wait()
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="tools.py"
)
subparsers = parser.add_subparsers()
# Alembic: Run Migrations
parser_run_migrations = subparsers.add_parser(
"run-migrations", help="Run latest migrations"
)
parser_run_migrations.set_defaults(func=run_migrations)
# Alembic: Create Migrations
parser_create_migrations = subparsers.add_parser(
"create-migrations", help="Create a migrations revision"
)
parser_create_migrations.add_argument(
"message", help="Provide a summary message for the migration"
)
parser_create_migrations.set_defaults(func=create_migrations)
args = parser.parse_args()
if hasattr(args, "func"):
args.func(args)
else:
parser.print_usage()