Skip to content

Commit 2389493

Browse files
committed
DEV: Drop old tables that have been renamed
1 parent 52349b9 commit 2389493

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
class RenameReassignSequences < ActiveRecord::Migration[7.0]
4+
def up
5+
reassign_sequence("discourse_voting_topic_vote_count_id_seq", "topic_voting_topic_vote_count")
6+
reassign_sequence("discourse_voting_votes_id_seq", "topic_voting_votes")
7+
reassign_sequence("discourse_voting_category_settings_id_seq", "topic_voting_category_settings")
8+
end
9+
10+
def down
11+
raise ActiveRecord::IrreversibleMigration, "Cannot revert sequence reassignment"
12+
end
13+
14+
private
15+
16+
def reassign_sequence(sequence_name, new_table_name)
17+
execute <<~SQL
18+
ALTER SEQUENCE #{sequence_name}
19+
OWNED BY #{new_table_name}.id;
20+
SQL
21+
end
22+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class DropOldDiscourseVotingTables < ActiveRecord::Migration[7.0]
4+
def up
5+
drop_table :discourse_voting_topic_vote_count, if_exists: true
6+
drop_table :discourse_voting_votes, if_exists: true
7+
drop_table :discourse_voting_category_settings, if_exists: true
8+
end
9+
10+
def down
11+
raise ActiveRecord::IrreversibleMigration
12+
end
13+
end

0 commit comments

Comments
 (0)