-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.py
40 lines (33 loc) · 1.25 KB
/
cleanup.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
from sqlalchemy import create_engine
from sqlalchemy.exc import OperationalError
from sqlalchemy import MetaData
from admin.utils import extract_database_name
from dbs import DB_DICT
for connection_name in DB_DICT:
connection_string = DB_DICT[connection_name]
db_type = connection_string.split(":")[0]
db = extract_database_name(connection_name)
choice = input(
"Do you want to delete " + db_type + " database " + db + " Y/N"
)
if choice.lower() == "y":
try:
engine = create_engine(connection_string)
conn = engine.connect()
MetaData().drop_all(engine)
conn.invalidate()
engine.dispose()
except OperationalError as err:
print("Could not delete " + db_type + " database " + db)
import traceback
traceback.print_exc()
continue
"""
#note: could not find a way to import the metadata even from inside the app folder
* maybe have a cleanup endpoint from inside the app
for table in reversed(meta.sorted_tables):
print(table.info['bind_key'])
#choice = input("Do you want to delete " + db_type + " table " + db + " Y/N") # noqa 401
#if choice.lower() == 'y':
# engine.execute(table.delete())
"""