-
Notifications
You must be signed in to change notification settings - Fork 42
/
db_create.py
47 lines (44 loc) · 1.55 KB
/
db_create.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
#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from config import SQLALCHEMY_DATABASE_DIR
from config import SQLALCHEMY_DATABASE_VERSION
from app import db
import data as ins_records
import os.path
import time
# import db_upgrade as upgrade_db
def create_database():
iniciar = False
if not os.path.exists(SQLALCHEMY_DATABASE_DIR):
iniciar = True
db.create_all()
# time.sleep(3)
# ins_records.insert_tech()
response = False
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
ins_records.insert_version()
time.sleep(0.5)
if iniciar:
ins_records.insert_tech()
ins_records.insert_tactic()
ins_records.insert_inteligence()
ins_records.insert_threat()
ins_records.insert_plan()
ins_records.insert_task()
ins_records.insert_user()
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
ins_records.insert_version()
response = True
else:
try:
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
except:
print("migration database record already exist")
try:
upgrade_db.upgrade_version()
except:
print("database upgrade error")
return response