Add migration for results with empty names [SCI-9443]

This commit is contained in:
Oleksii Kriuchykhin 2023-10-04 15:25:29 +02:00
parent 9966229324
commit 472985e0c2

View file

@ -0,0 +1,30 @@
# frozen_string_literal: true
class SetDefaultNamesForResults < ActiveRecord::Migration[7.0]
def up
ActiveRecord::Base.connection.execute(
"UPDATE result_texts SET name = results.name
FROM results
WHERE result_texts.result_id = results.id
AND (result_texts.name = '' OR result_texts.name IS NULL)
AND results.name IS NOT NULL AND results.name != ''"
)
ActiveRecord::Base.connection.execute(
"UPDATE tables SET name = results.name
FROM results
INNER JOIN result_tables ON results.id = result_tables.result_id
WHERE result_tables.table_id = tables.id
AND (tables.name = '' OR tables.name IS NULL)
AND results.name IS NOT NULL AND results.name != ''"
)
ActiveRecord::Base.connection.execute(
"UPDATE results SET name = 'Untitled result' WHERE results.name = '' OR results.name IS NULL"
)
end
def down
raise ActiveRecord::IrreversibleMigration
end
end