-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdb_create.py
More file actions
executable file
·36 lines (30 loc) · 1.08 KB
/
Copy pathdb_create.py
File metadata and controls
executable file
·36 lines (30 loc) · 1.08 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
#!flask/bin/python
from migrate.versioning import api
from app import db, app
import os.path
def setdb():
# This function creates an app database and the migration data repository
# these two variables are required by the sqlalchemy library and point to
# the save directories in which the db and migration repository will be
# stored.
SQLALCHEMY_DATABASE_URI=app.config['SQLALCHEMY_DATABASE_URI']
SQLALCHEMY_MIGRATE_REPO=app.config['SQLALCHEMY_MIGRATE_REPO']
# db creation comes first
try:
db.create_all()
except:
print 'Error creating app database'
# followed by the migration repository
try:
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
except:
print 'Error creating migration data repository'
def main():
# this function call will be removed in production code
setdb()
if __name__ == "__main__":
main()