From 373b890e1d0470ac222a5b8fc388e9ffe2350ca4 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Wed, 10 Apr 2019 17:09:36 -0500 Subject: [PATCH] Log command before execution --- src/invidious/helpers/helpers.cr | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index f515f28a..3c75e7a7 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -502,11 +502,11 @@ end def analyze_table(db, logger, table_name, struct_type = nil) # Create table if it doesn't exist if !db.query_one?("SELECT true FROM information_schema.tables WHERE table_name = $1", table_name, as: Bool) + logger.write("CREATE TABLE #{table_name}\n") + db.using_connection do |conn| conn.as(PG::Connection).exec_all(File.read("config/sql/#{table_name}.sql")) end - - logger.write("CREATE TABLE #{table_name}\n") end if !struct_type @@ -526,8 +526,8 @@ def analyze_table(db, logger, table_name, struct_type = nil) if name != column_array[i]? if !column_array[i]? new_column = column_types.select { |line| line.starts_with? name }[0] - db.exec("ALTER TABLE #{table_name} ADD COLUMN #{new_column}") logger.write("ALTER TABLE #{table_name} ADD COLUMN #{new_column}\n") + db.exec("ALTER TABLE #{table_name} ADD COLUMN #{new_column}") next end @@ -544,27 +544,27 @@ def analyze_table(db, logger, table_name, struct_type = nil) # There's a column we didn't expect if !new_column - db.exec("ALTER TABLE #{table_name} DROP COLUMN #{column_array[i]} CASCADE") logger.write("ALTER TABLE #{table_name} DROP COLUMN #{column_array[i]}\n") + db.exec("ALTER TABLE #{table_name} DROP COLUMN #{column_array[i]} CASCADE") column_array = get_column_array(db, table_name) next end - db.exec("ALTER TABLE #{table_name} ADD COLUMN #{new_column}") logger.write("ALTER TABLE #{table_name} ADD COLUMN #{new_column}\n") - db.exec("UPDATE #{table_name} SET #{column_array[i]}_new=#{column_array[i]}") + db.exec("ALTER TABLE #{table_name} ADD COLUMN #{new_column}") logger.write("UPDATE #{table_name} SET #{column_array[i]}_new=#{column_array[i]}\n") - db.exec("ALTER TABLE #{table_name} DROP COLUMN #{column_array[i]} CASCADE") + db.exec("UPDATE #{table_name} SET #{column_array[i]}_new=#{column_array[i]}") logger.write("ALTER TABLE #{table_name} DROP COLUMN #{column_array[i]} CASCADE\n") - db.exec("ALTER TABLE #{table_name} RENAME COLUMN #{column_array[i]}_new TO #{column_array[i]}") + db.exec("ALTER TABLE #{table_name} DROP COLUMN #{column_array[i]} CASCADE") logger.write("ALTER TABLE #{table_name} RENAME COLUMN #{column_array[i]}_new TO #{column_array[i]}\n") + db.exec("ALTER TABLE #{table_name} RENAME COLUMN #{column_array[i]}_new TO #{column_array[i]}") column_array = get_column_array(db, table_name) end else - db.exec("ALTER TABLE #{table_name} DROP COLUMN #{column_array[i]} CASCADE") logger.write("ALTER TABLE #{table_name} DROP COLUMN #{column_array[i]} CASCADE\n") + db.exec("ALTER TABLE #{table_name} DROP COLUMN #{column_array[i]} CASCADE") end end end