DEV: Update data explorer queries to new table if exists (#197)

This commit is contained in:
Natalie Tay 2024-07-18 00:01:48 +08:00 committed by GitHub
parent 3d3037729c
commit 4ebcd1187b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
class UpdateDataExplorerTopicVotingQueries < ActiveRecord::Migration[7.0]
def up
has_data_explorer_queries = DB.query_single(<<~SQL).first
SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_name = 'data_explorer_queries'
);
SQL
DB.exec(<<~SQL) if has_data_explorer_queries
UPDATE data_explorer_queries
SET sql = REPLACE(
REPLACE(sql, 'discourse_voting_topic_vote_count', 'topic_voting_topic_vote_count'),
'discourse_voting_votes', 'topic_voting_votes'
)
WHERE sql LIKE '%discourse_voting_topic_vote_count%'
OR sql LIKE '%discourse_voting_votes%';
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end