-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
46 lines (36 loc) · 1.04 KB
/
manage.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
import argparse
import os
from dotenv import load_dotenv
def deploy(dbinit = False):
"""Run deployment tasks."""
from app import create_app, db
from flask_migrate import upgrade, migrate, init, stamp
# get settings from the .env file
load_dotenv()
my_config = os.getenv('CONFIG_LEVEL', None)
print(f"my_config in deploy = {my_config} - deploy")
app = create_app(config_name = my_config)
app.app_context().push()
db.create_all()
# init database first time print(f"init = {dbinit}")
if dbinit:
init()
# migrate database to latest revision
stamp()
migrate()
upgrade()
def main():
# Create an ArgumentParser object
parser = argparse.ArgumentParser(description='Run deployment tasks.')
# Add a command-line argument for the deploy function
parser.add_argument('--dbinit', action='store_true', help='Run dB deployment tasks.')
# Parse the command-line arguments
args = parser.parse_args()
print(args)
# Check if the --deploy flag is provided
if args.dbinit:
deploy(True)
else:
deploy(False)
if __name__ == '__main__':
main()