FIX: DB migration fails if old site setting has empty value (#18296)

This commit is contained in:
Gerhard Schlager 2022-09-21 14:06:14 +02:00 committed by GitHub
parent eab33af5bf
commit b3831362a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -4,12 +4,12 @@ class RenameDigestAfterDaysToDigestAfterMinutes < ActiveRecord::Migration[4.2]
def up def up
rename_column :user_options, :digest_after_days, :digest_after_minutes rename_column :user_options, :digest_after_days, :digest_after_minutes
execute "UPDATE user_options SET digest_after_minutes = digest_after_minutes * 1440 WHERE digest_after_minutes IS NOT NULL" execute "UPDATE user_options SET digest_after_minutes = digest_after_minutes * 1440 WHERE digest_after_minutes IS NOT NULL"
execute "UPDATE site_settings SET value = value::integer * 1440 WHERE name = 'default_email_digest_frequency' AND value IS NOT NULL" execute "UPDATE site_settings SET value = value::integer * 1440 WHERE name = 'default_email_digest_frequency' AND value IS NOT NULL AND value <> ''"
end end
def down def down
rename_column :user_options, :digest_after_minutes, :digest_after_days rename_column :user_options, :digest_after_minutes, :digest_after_days
execute "UPDATE user_options SET digest_after_days = digest_after_days / 1440 WHERE digest_after_days IS NOT NULL" execute "UPDATE user_options SET digest_after_days = digest_after_days / 1440 WHERE digest_after_days IS NOT NULL"
execute "UPDATE site_settings SET value = value::integer / 1440 WHERE name = 'default_email_digest_frequency' AND value IS NOT NULL" execute "UPDATE site_settings SET value = value::integer / 1440 WHERE name = 'default_email_digest_frequency' AND value IS NOT NULL AND value <> ''"
end end
end end