From 6d52b8cfa8b3e2920aa3f12fc52673b88f53f776 Mon Sep 17 00:00:00 2001 From: Natalie Tay Date: Tue, 3 Dec 2024 22:20:13 +0800 Subject: [PATCH] DEV: Drop old tables that have been renamed (#221) It is now safe to drop the old table. The new tables are prefixed with topic-voting-, the old tables are discourse-voting-. This commit also transfers the sequences to the new tables. --- ...0241203125415_rename_reassign_sequences.rb | 22 +++++++++++++++++++ ...125523_drop_old_discourse_voting_tables.rb | 13 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 db/migrate/20241203125415_rename_reassign_sequences.rb create mode 100644 db/post_migrate/20241203125523_drop_old_discourse_voting_tables.rb diff --git a/db/migrate/20241203125415_rename_reassign_sequences.rb b/db/migrate/20241203125415_rename_reassign_sequences.rb new file mode 100644 index 0000000..e2dd754 --- /dev/null +++ b/db/migrate/20241203125415_rename_reassign_sequences.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class RenameReassignSequences < ActiveRecord::Migration[7.0] + def up + reassign_sequence("discourse_voting_topic_vote_count_id_seq", "topic_voting_topic_vote_count") + reassign_sequence("discourse_voting_votes_id_seq", "topic_voting_votes") + reassign_sequence("discourse_voting_category_settings_id_seq", "topic_voting_category_settings") + end + + def down + raise ActiveRecord::IrreversibleMigration + end + + private + + def reassign_sequence(sequence_name, new_table_name) + execute <<~SQL + ALTER SEQUENCE #{sequence_name} + OWNED BY #{new_table_name}.id; + SQL + end +end diff --git a/db/post_migrate/20241203125523_drop_old_discourse_voting_tables.rb b/db/post_migrate/20241203125523_drop_old_discourse_voting_tables.rb new file mode 100644 index 0000000..432b6e3 --- /dev/null +++ b/db/post_migrate/20241203125523_drop_old_discourse_voting_tables.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class DropOldDiscourseVotingTables < ActiveRecord::Migration[7.0] + def up + drop_table :discourse_voting_topic_vote_count, if_exists: true + drop_table :discourse_voting_votes, if_exists: true + drop_table :discourse_voting_category_settings, if_exists: true + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end