Imrpove migrations
This commit is contained in:
1 parent
db316b2914
commit
9aa3da5191
4 files changed
+13
-39
No files matched your search
@@ -18,16 +18,12 @@ Sequel.migration do
|
||||
foreign_key :recorded_by, :members,
|
||||
type: :Bignum
|
||||
|
||||
DateTime :ended_at
|
||||
String :end_reason
|
||||
|
||||
index :status
|
||||
|
||||
# Un seul dossier en attente ou une seule adhésion
|
||||
# en cours par adhérent.
|
||||
# Un seul dossier en attente ou une seule adhésion acceptée.
|
||||
index :member_id,
|
||||
unique: true,
|
||||
where: { status: ["pending", "accepted"], ended_at: nil }
|
||||
where: { status: ["pending", "accepted"] }
|
||||
|
||||
constraint :memberships_status_valid,
|
||||
Sequel.lit("status IN ('pending', 'accepted', 'rejected')")
|
||||
@@ -37,15 +33,7 @@ Sequel.migration do
|
||||
"(status = 'pending' AND decided_at IS NULL " \
|
||||
"AND recorded_by IS NULL) " \
|
||||
"OR (status IN ('accepted', 'rejected') " \
|
||||
"AND decided_at IS NOT NULL AND recorded_by IS NOT NULL)"
|
||||
)
|
||||
|
||||
constraint :memberships_end_consistent,
|
||||
Sequel.lit(
|
||||
"(ended_at IS NULL AND end_reason IS NULL) " \
|
||||
"OR (status = 'accepted' AND ended_at IS NOT NULL " \
|
||||
"AND end_reason IN ('resignation', 'death', " \
|
||||
"'dissolution', 'exclusion'))"
|
||||
"AND decided_at IS NOT NULL)"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user