-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigration.py
38 lines (30 loc) · 924 Bytes
/
migration.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
from db import engine
from db.model import Basic, Episode, Rating
from termcolor import colored
from util.config import config
from util.log import logger
if __name__ == '__main__':
tables = [
Basic,
Episode,
Rating,
]
connection = engine.connect()
for table in tables:
table_name = table.__tablename__
tc = colored(table_name, 'green', attrs=['bold'])
if engine.dialect.has_table(
connection,
table_name=table_name,
schema=config.db.schema
):
logger.info(tc + ' table is already exist')
continue
logger.info(tc + ' table is creating')
try:
table.__table__.create(engine)
except Exception as e:
m = tc + ' table could not created. Please check bellow.'
logger.error(m)
logger.exception(e)
connection.close()