Skip to content

Commit

Permalink
Add check constraints to order_items, products, and stocks for data i…
Browse files Browse the repository at this point in the history
…ntegrity
  • Loading branch information
binos30 committed Jan 26, 2025
1 parent 3c34789 commit 13cbca2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions db/migrate/20250126034803_add_check_constraints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AddCheckConstraints < ActiveRecord::Migration[7.2]
def change
add_check_constraint :order_items, "product_price >= 0", name: "product_price_non_negative"
add_check_constraint :order_items, "quantity > 0", name: "quantity_positive"
add_check_constraint :products, "price >= 0", name: "price_non_negative"
add_check_constraint :stocks, "quantity >= 0", name: "quantity_non_negative"
end
end
6 changes: 5 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 13cbca2

Please sign in to comment.