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.
This commit is contained in:
Natalie Tay 2024-12-03 22:20:13 +08:00 committed by GitHub
parent 52349b9d1b
commit 6d52b8cfa8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 0 deletions

View File

@ -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

View File

@ -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