@ -335,7 +335,7 @@ def check_enum(db, logger, enum_name, struct_type = nil)
return # TODO
if ! db . query_one? ( " SELECT true FROM pg_type WHERE typname = $1 " , enum_name , as : Bool )
logger . puts( " CREATE TYPE #{ enum_name } " )
logger . info( " check_enum: CREATE TYPE #{ enum_name } " )
db . using_connection do | conn |
conn . as ( PG :: Connection ) . exec_all ( File . read ( " config/sql/ #{ enum_name } .sql " ) )
@ -348,7 +348,7 @@ def check_table(db, logger, table_name, struct_type = nil)
begin
db . exec ( " SELECT * FROM #{ table_name } LIMIT 0 " )
rescue ex
logger . puts( " CREATE TABLE #{ table_name } " )
logger . info( " check_table: check_table: CREATE TABLE #{ table_name } " )
db . using_connection do | conn |
conn . as ( PG :: Connection ) . exec_all ( File . read ( " config/sql/ #{ table_name } .sql " ) )
@ -368,7 +368,7 @@ def check_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 ]
logger . puts( " ALTER TABLE #{ table_name } ADD COLUMN #{ new_column } " )
logger . info( " check_table: ALTER TABLE #{ table_name } ADD COLUMN #{ new_column } " )
db . exec ( " ALTER TABLE #{ table_name } ADD COLUMN #{ new_column } " )
next
end
@ -386,29 +386,29 @@ def check_table(db, logger, table_name, struct_type = nil)
# There's a column we didn't expect
if ! new_column
logger . puts( " ALTER TABLE #{ table_name } DROP COLUMN #{ column_array [ i ] } " )
logger . info( " check_table: ALTER TABLE #{ table_name } DROP COLUMN #{ column_array [ i ] } " )
db . exec ( " ALTER TABLE #{ table_name } DROP COLUMN #{ column_array [ i ] } CASCADE " )
column_array = get_column_array ( db , table_name )
next
end
logger . puts( " ALTER TABLE #{ table_name } ADD COLUMN #{ new_column } " )
logger . info( " check_table: ALTER TABLE #{ table_name } ADD COLUMN #{ new_column } " )
db . exec ( " ALTER TABLE #{ table_name } ADD COLUMN #{ new_column } " )
logger . puts( " UPDATE #{ table_name } SET #{ column_array [ i ] } _new= #{ column_array [ i ] } " )
logger . info( " check_table: UPDATE #{ table_name } SET #{ column_array [ i ] } _new= #{ column_array [ i ] } " )
db . exec ( " UPDATE #{ table_name } SET #{ column_array [ i ] } _new= #{ column_array [ i ] } " )
logger . puts( " ALTER TABLE #{ table_name } DROP COLUMN #{ column_array [ i ] } CASCADE " )
logger . info( " check_table: ALTER TABLE #{ table_name } DROP COLUMN #{ column_array [ i ] } CASCADE " )
db . exec ( " ALTER TABLE #{ table_name } DROP COLUMN #{ column_array [ i ] } CASCADE " )
logger . puts( " ALTER TABLE #{ table_name } RENAME COLUMN #{ column_array [ i ] } _new TO #{ column_array [ i ] } " )
logger . info( " check_table: ALTER TABLE #{ table_name } RENAME COLUMN #{ column_array [ i ] } _new TO #{ column_array [ i ] } " )
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
logger . puts( " ALTER TABLE #{ table_name } DROP COLUMN #{ column_array [ i ] } CASCADE " )
logger . info( " check_table: ALTER TABLE #{ table_name } DROP COLUMN #{ column_array [ i ] } CASCADE " )
db . exec ( " ALTER TABLE #{ table_name } DROP COLUMN #{ column_array [ i ] } CASCADE " )
end
end
@ -418,7 +418,7 @@ def check_table(db, logger, table_name, struct_type = nil)
column_array . each do | column |
if ! struct_array . includes? column
logger . puts( " ALTER TABLE #{ table_name } DROP COLUMN #{ column } CASCADE " )
logger . info( " check_table: ALTER TABLE #{ table_name } DROP COLUMN #{ column } CASCADE " )
db . exec ( " ALTER TABLE #{ table_name } DROP COLUMN #{ column } CASCADE " )
end
end