Skip to content

Commit 4e208c2

Browse files
Update constraint.md
1 parent 84340cb commit 4e208c2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

constraint.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,18 @@ ADD CONSTRAINT hello_type_check CHECK(type = ANY(ARRAY['a']));
7676
```
7777

7878

79-
## Patterns
79+
## Column patterns
8080

81-
- two columns must be null or vice versa
81+
- two columns must be null or vice versa (a AND b)
8282
- three or more columns must be null or vice versa (create one new column flag to indicate those exists, or better, put them in another table)
8383
- is draft and published at(hint, you only need one)
8484
- active and deleted at (maybe both)
85+
- usecase: publishing products. when is no longer draft, all the columns must be filled, otherwise errors.
86+
- XOR for polymorphic associations, vs table inheritance
87+
88+
89+
# Row patterns
90+
91+
- min max rows
92+
- at least n row fulfilling condition (usecase: one pending status booking)
93+
- max one row with condition (unique, and partial unique)

0 commit comments

Comments
 (0)