mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Remove spree_variants default value and constraint
Some of the production database have default value for `weight` and `unit_value` has well as check constraint. We want to remove them to bring the database schema inline with schema.rb
This commit is contained in:
27
db/migrate/20241211060023_remove_variant_default_value.rb
Normal file
27
db/migrate/20241211060023_remove_variant_default_value.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
class RemoveVariantDefaultValue < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
change_table :spree_variants do |t|
|
||||
t.change_null :weight, true
|
||||
t.change_default :weight, nil
|
||||
t.change_null :unit_value, true
|
||||
t.change_default :unit_value, nil
|
||||
end
|
||||
execute <<-SQL
|
||||
ALTER TABLE spree_variants
|
||||
DROP CONSTRAINT IF EXISTS check_unit_value_for_nan;
|
||||
ALTER TABLE spree_variants
|
||||
DROP CONSTRAINT IF EXISTS check_weight_for_nan;
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
change_table :spree_variants do |t|
|
||||
t.change_null :weight, false
|
||||
t.change_default :weight, "0.0"
|
||||
t.change_null :unit_value, false
|
||||
t.change_default :unit_value, "1.0"
|
||||
t.check_constraint("unit_value <> 'NaN'::double precision", name: "check_unit_value_for_nan")
|
||||
t.check_constraint("weight <> 'NaN'::numeric", name: "check_weight_for_nan")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user