FIX: Drop columns only after app has been deployed with updated code.
This commit is contained in:
parent
303282670f
commit
53086fdb98
|
@ -23,3 +23,27 @@ if uncat_id == -1 || !Category.exists?(uncat_id)
|
|||
Category.exec_sql "INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
|
||||
VALUES ('uncategorized_category_id', 3, #{category_id}, now(), now())"
|
||||
end
|
||||
|
||||
# 60 minutes after our migration runs we need to exectue this code...
|
||||
duration = Rails.env.production? ? 60 : 0
|
||||
if Category.exec_sql("
|
||||
SELECT 1 FROM schema_migration_details
|
||||
WHERE EXISTS(
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE table_schema = 'public' AND table_name = 'categories' AND column_name = 'uploaded_logo_id'
|
||||
) AND
|
||||
name = 'AddUploadsToCategories' AND
|
||||
created_at < (current_timestamp at time zone 'UTC' - interval '#{duration} minutes')
|
||||
").to_a.length > 0
|
||||
|
||||
|
||||
Category.transaction do
|
||||
STDERR.puts "Removing superflous category columns!"
|
||||
%w[
|
||||
logo_url
|
||||
background_url
|
||||
].each do |column|
|
||||
Category.exec_sql("ALTER TABLE categories DROP column IF EXISTS #{column}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue