Skip to content

Commit

Permalink
Merge pull request #4449 from willkg/1459275-fix
Browse files Browse the repository at this point in the history
bug 1459272: fix migration
  • Loading branch information
willkg committed May 17, 2018
2 parents 42ab16f + 23afcca commit 47978b8
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion alembic/versions/fd76c8bb0d78_bug_1459276_reports.py
Expand Up @@ -41,10 +41,33 @@ def upgrade():
)

op.execute('DROP TABLE IF EXISTS reports_bad')
op.execute('DROP TABLE IF EXISTS reports_clean')
op.execute('DROP TABLE IF EXISTS reports_duplicates')
op.execute('DROP TABLE IF EXISTS reports_user_info')

# Get rid of all tables that start with 'reports_clean'
connection = op.get_bind()
cursor = connection.connection.cursor()
cursor.execute("""
SELECT table_name
FROM information_schema.tables
WHERE table_name like 'reports_clean%'
""")
all_table_names = []
for records in cursor.fetchall():
all_table_names.append(records[0])

# Sort table names so 'reports_clean' is last since the others depend on it and
# delete them in that order
all_table_names.sort(reverse=True)
for table_name in all_table_names:
op.execute('DROP TABLE IF EXISTS {}'.format(table_name))

# Now remove the entry from report_partition_info so the crontabber job
# doesn't try to create a new partition
op.execute("""
DELETE FROM report_partition_info WHERE table_name = 'reports_clean'
""")

# Get rid of all tables that start with 'reports'
connection = op.get_bind()
cursor = connection.connection.cursor()
Expand Down

0 comments on commit 47978b8

Please sign in to comment.