mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 13:41:31 +08:00
DEV: ignore some tables when updating timestamps using db_timestamps_mover.rb (#13714)
Some tables have constraints on columns with a date which can cause problems when moving timestamps. By now I think it's enough to just ignore them.
This commit is contained in:
parent
7911124d3d
commit
8a0349a01f
|
@ -9,9 +9,9 @@ Commands:
|
||||||
END
|
END
|
||||||
|
|
||||||
class TimestampsUpdater
|
class TimestampsUpdater
|
||||||
TABLE_SCHEMA = 'public'
|
def initialize(schema, ignore_tables)
|
||||||
|
@schema = schema
|
||||||
def initialize
|
@ignore_tables = ignore_tables
|
||||||
@raw_connection = PG.connect(
|
@raw_connection = PG.connect(
|
||||||
host: ENV['DISCOURSE_DB_HOST'] || 'localhost',
|
host: ENV['DISCOURSE_DB_HOST'] || 'localhost',
|
||||||
port: ENV['DISCOURSE_DB_PORT'] || 5432,
|
port: ENV['DISCOURSE_DB_PORT'] || 5432,
|
||||||
|
@ -31,7 +31,9 @@ class TimestampsUpdater
|
||||||
columns = all_columns_of_type(data_type)
|
columns = all_columns_of_type(data_type)
|
||||||
columns.each do |c|
|
columns.each do |c|
|
||||||
table = c["table_name"]
|
table = c["table_name"]
|
||||||
|
next if @ignore_tables.include? table
|
||||||
column = c["column_name"]
|
column = c["column_name"]
|
||||||
|
|
||||||
move_timestamps table, column, days
|
move_timestamps table, column, days
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -50,7 +52,7 @@ class TimestampsUpdater
|
||||||
FROM information_schema.columns AS c
|
FROM information_schema.columns AS c
|
||||||
JOIN information_schema.tables AS t
|
JOIN information_schema.tables AS t
|
||||||
ON c.table_name = t.table_name
|
ON c.table_name = t.table_name
|
||||||
WHERE c.table_schema = '#{TABLE_SCHEMA}'
|
WHERE c.table_schema = '#{@schema}'
|
||||||
AND c.data_type = '#{data_type}'
|
AND c.data_type = '#{data_type}'
|
||||||
AND t.table_type = 'BASE TABLE'
|
AND t.table_type = 'BASE TABLE'
|
||||||
SQL
|
SQL
|
||||||
|
@ -75,12 +77,19 @@ def is_date?(string)
|
||||||
true if Date.parse(string) rescue false
|
true if Date.parse(string) rescue false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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])
|
if ARGV.length == 2 && ARGV[0] == "yesterday" && is_date?(ARGV[1])
|
||||||
date = Date.parse(ARGV[1])
|
date = Date.parse(ARGV[1])
|
||||||
TimestampsUpdater.new.move_to_yesterday date
|
updater = create_updater
|
||||||
|
updater.move_to_yesterday date
|
||||||
elsif ARGV.length == 1 && is_i?(ARGV[0])
|
elsif ARGV.length == 1 && is_i?(ARGV[0])
|
||||||
days = ARGV[0].to_i
|
days = ARGV[0].to_i
|
||||||
TimestampsUpdater.new.move_by days
|
updater = create_updater
|
||||||
|
updater.move_by days
|
||||||
else
|
else
|
||||||
puts usage
|
puts usage
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user