add database constraint for variant unit_value

This commit is contained in:
Andy Brett
2021-04-14 10:27:07 -07:00
parent 8e14e0e950
commit a9fe6c787d
2 changed files with 11 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
class AddUnitValueConstraint < ActiveRecord::Migration[5.0]
def up
execute "UPDATE spree_variants SET unit_value = 1 WHERE unit_value <= 0"
execute "ALTER TABLE spree_variants ADD CONSTRAINT positive_unit_value CHECK (unit_value > 0)"
end
def down
execute "ALTER TABLE spree_variants DROP CONSTRAINT positive_unit_value"
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20210326094519) do
ActiveRecord::Schema.define(version: 20210414171109) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"