-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Update data explorer queries to new table if exists (#197)
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
db/post_migrate/20240717071658_update_data_explorer_topic_voting_queries.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |