Skip to content

Commit

Permalink
FIX: don't remap readonly columns
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogStriP committed May 3, 2019
1 parent d82da69 commit bfcbfd7
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/db_helper.rb
Expand Up @@ -9,12 +9,23 @@ class DbHelper
ORDER BY table_name, column_name
SQL

TRIGGERS_SQL ||= <<~SQL
SELECT trigger_name
FROM information_schema.triggers
WHERE trigger_name LIKE '%_readonly'
SQL

def self.remap(from, to, anchor_left: false, anchor_right: false, excluded_tables: [])
like = "#{anchor_left ? '' : "%"}#{from}#{anchor_right ? '' : "%"}"

triggers = DB.query(TRIGGERS_SQL).map(&:trigger_name).to_set

text_columns = Hash.new { |h, k| h[k] = [] }

DB.query(REMAP_SQL).each do |r|
text_columns[r.table_name] << r.column_name
unless triggers.include?("#{r.table_name}_#{r.column_name}_readonly")
text_columns[r.table_name] << r.column_name
end
end

text_columns.each do |table, columns|
Expand All @@ -39,10 +50,14 @@ def self.remap(from, to, anchor_left: false, anchor_right: false, excluded_table
end

def self.regexp_replace(pattern, replacement, flags: "gi", match: "~*", excluded_tables: [])
triggers = DB.query(TRIGGERS_SQL).map(&:trigger_name).to_set

text_columns = Hash.new { |h, k| h[k] = [] }

DB.query(REMAP_SQL).each do |r|
text_columns[r.table_name] << r.column_name
unless triggers.include?("#{r.table_name}_#{r.column_name}_readonly")
text_columns[r.table_name] << r.column_name
end
end

text_columns.each do |table, columns|
Expand Down

2 comments on commit bfcbfd7

@tgxworld
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZogStriP
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.