-
Notifications
You must be signed in to change notification settings - Fork 34
/
db_init.py
32 lines (23 loc) · 852 Bytes
/
db_init.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
exit("COMMENT THIS LINE IN ORDER TO RE-INIT DATABASE TABLES")
import asyncio
import logging
from configurator import make_config
logging.basicConfig(level=logging.INFO)
if not make_config("config.ini"):
logging.error("Errors while parsing config file. Exiting.")
exit(1)
import heroku_config
# import models n stuff
from db import ormar_config
from models.member import Member
# DROP & INIT tables (async mysql)
async def reinit_db_tables():
async with ormar_config.engine.begin() as conn:
await conn.run_sync(ormar_config.metadata.drop_all)
await conn.run_sync(ormar_config.metadata.create_all)
await ormar_config.engine.dispose()
asyncio.run(reinit_db_tables())
exit("DONE")
# for sqlite use this :3
# ormar_config.metadata.drop_all(ormar_config.engine)
# ormar_config.metadata.create_all(ormar_config.engine)