mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-13 04:36:00 +08:00
Add migration for results with empty names [SCI-9443]
This commit is contained in:
parent
9966229324
commit
472985e0c2
1 changed files with 30 additions and 0 deletions
30
db/migrate/20231003114337_set_default_names_for_results.rb
Normal file
30
db/migrate/20231003114337_set_default_names_for_results.rb
Normal 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
|
Loading…
Reference in a new issue