mirror of
https://ghfast.top/https://github.com/discourse/discourse-topic-voting.git
synced 2026-07-17 11:37:03 +08:00
Renaming discourse_voting to topic_voting since there are two forms of voting in Discourse - posts and topics. This PR also moves a OnceOff into a post migration. The post migration will be executed, but should ideally be a no-op. This allows us to not have to maintain the OnceOff as it had to be modified before with a previous migration. I considered removing this file altogether, but I don't think there is anything negative from just converting it into a migration, and it might be useful in the unlikely scenario that a forum from the past has never ran the OnceOff before.
73 lines
2 KiB
Ruby
73 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "migration/table_dropper"
|
|
|
|
class RenameVotingTables < ActiveRecord::Migration[7.0]
|
|
def up
|
|
unless table_exists?(:topic_voting_topic_vote_count)
|
|
Migration::TableDropper.read_only_table(:discourse_voting_topic_vote_count)
|
|
execute <<~SQL
|
|
CREATE TABLE topic_voting_topic_vote_count
|
|
(LIKE discourse_voting_topic_vote_count INCLUDING ALL);
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
INSERT INTO topic_voting_topic_vote_count
|
|
SELECT *
|
|
FROM discourse_voting_topic_vote_count
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
ALTER TABLE topic_voting_topic_vote_count
|
|
ALTER COLUMN id
|
|
SET DEFAULT nextval('discourse_voting_topic_vote_count_id_seq')
|
|
SQL
|
|
|
|
add_index :topic_voting_topic_vote_count, :topic_id, unique: true
|
|
end
|
|
|
|
unless table_exists?(:topic_voting_votes)
|
|
Migration::TableDropper.read_only_table(:discourse_voting_votes)
|
|
execute <<~SQL
|
|
CREATE TABLE topic_voting_votes
|
|
(LIKE discourse_voting_votes INCLUDING ALL);
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
INSERT INTO topic_voting_votes
|
|
SELECT *
|
|
FROM discourse_voting_votes
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
ALTER TABLE topic_voting_votes
|
|
ALTER COLUMN id
|
|
SET DEFAULT nextval('discourse_voting_votes_id_seq')
|
|
SQL
|
|
end
|
|
|
|
unless table_exists?(:topic_voting_category_settings)
|
|
Migration::TableDropper.read_only_table(:discourse_voting_category_settings)
|
|
execute <<~SQL
|
|
CREATE TABLE topic_voting_category_settings
|
|
(LIKE discourse_voting_category_settings INCLUDING ALL);
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
INSERT INTO topic_voting_category_settings
|
|
SELECT *
|
|
FROM discourse_voting_category_settings
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
ALTER TABLE topic_voting_category_settings
|
|
ALTER COLUMN id
|
|
SET DEFAULT nextval('discourse_voting_category_settings_id_seq')
|
|
SQL
|
|
end
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|