A platform for community discussion. Free, open, simple.
DEV: ignore some tables when updating timestamps using db_timestamps_mover.rb (#13714)
Andrei Prigorshnev8a0349a01f73
diff --git a/script/db_timestamps_mover.rb b/script/db_timestamps_mover.rbindex b1afef25c43..62c91de6f90 100644--- a/script/db_timestamps_mover.rb+++ b/script/db_timestamps_mover.rb@@ -9,9 +9,9 @@ Commands:ENDclass TimestampsUpdater- TABLE_SCHEMA = 'public'-- def initialize+ def initialize(schema, ignore_tables)+ @schema = schema+ @ignore_tables = ignore_tables@raw_connection = PG.connect(host: ENV['DISCOURSE_DB_HOST'] || 'localhost',port: ENV['DISCOURSE_DB_PORT'] || 5432,@@ -31,7 +31,9 @@ class TimestampsUpdatercolumns = all_columns_of_type(data_type)columns.each do |c|table = c["table_name"]+ next if @ignore_tables.include? tablecolumn = c["column_name"]+move_timestamps table, column, daysendend@@ -50,7 +52,7 @@ class TimestampsUpdaterFROM information_schema.columns AS cJOIN information_schema.tables AS tON c.table_name = t.table_name- WHERE c.table_schema = '#{TABLE_SCHEMA}'+ WHERE c.table_schema = '#{@schema}'AND c.data_type = '#{data_type}'AND t.table_type = 'BASE TABLE'SQL@@ -75,12 +77,19 @@ def is_date?(string)true if Date.parse(string) rescue falseend+def create_updater+ ignore_tables = %w[application_requests user_visits]+ TimestampsUpdater.new "public", ignore_tables+end+if ARGV.length == 2 && ARGV[0] == "yesterday" && is_date?(ARGV[1])date = Date.parse(ARGV[1])- TimestampsUpdater.new.move_to_yesterday date+ updater = create_updater+ updater.move_to_yesterday dateelsif ARGV.length == 1 && is_i?(ARGV[0])days = ARGV[0].to_i- TimestampsUpdater.new.move_by days+ updater = create_updater+ updater.move_by dayselseputs usageexit 1