-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcleanup_tables.py
56 lines (49 loc) · 1.57 KB
/
cleanup_tables.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
48
49
50
51
52
53
54
55
56
# coding: utf-8
import re
from app import get_db_cursor
if __name__ == "__main__":
table_names = """
jump_account_package
jump_apc_authorships
jump_counter
jump_counter_input
jump_journal_prices
jump_journal_prices_input
jump_package_scenario
jump_perpetual_access
jump_perpetual_access_input
jump_raw_file_upload_object
jump_scenario_computed
jump_scenario_details_paid
jump_user_institution_permission
jump_user_institution_permission
jump_oa_all_vars
jump_oa_no_submitted_no_bronze
jump_oa_no_submitted_with_bronze
jump_oa_with_submitted_no_bronze
jump_oa_with_submitted_with_bronze
jump_authorship
jump_citing
jump_institution
ricks_affiliation
journalsdb_computed
jump_consortium_members
permissions_input
""".split()
show_tables = """SELECT DISTINCT tablename
FROM pg_table_def
WHERE schemaname = 'public'
ORDER BY tablename;
"""
with get_db_cursor() as cursor:
cursor.execute(show_tables)
rows = cursor.fetchall()
# make a list of str
tables = [w[0] for w in rows]
# filter to tables in table_names
tables = list(filter(lambda x: re.match("|".join(table_names), x), tables))
# filter to likely backup tables
likely_backups = [table for table in tables if table not in table_names]
print("{} tables\n".format(len(likely_backups)))
for table in likely_backups:
print(f"drop table {table};")