-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into cowboy-credits
- Loading branch information
Showing
7 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
prisma/migrations/20241231223214_invoice_user_cancel/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- AlterTable | ||
ALTER TABLE "Invoice" ADD COLUMN "userCancel" BOOLEAN; | ||
|
||
-- Migrate existing rows | ||
UPDATE "Invoice" SET "userCancel" = false; | ||
|
||
-- Add constraint to ensure consistent cancel state | ||
ALTER TABLE "Invoice" ADD CONSTRAINT "Invoice_cancel" CHECK ( | ||
("cancelled" = true AND "cancelledAt" IS NOT NULL AND "userCancel" IS NOT NULL) OR | ||
("cancelled" = false AND "cancelledAt" IS NULL AND "userCancel" IS NULL) | ||
); | ||
|
||
-- Add trigger to set userCancel to false by default when cancelled updated and userCancel not specified | ||
CREATE OR REPLACE FUNCTION invoice_set_user_cancel_default() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
IF NEW.cancelled AND NEW."userCancel" IS NULL THEN | ||
NEW."userCancel" := false; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER invoice_user_cancel_trigger | ||
BEFORE UPDATE ON "Invoice" | ||
FOR EACH ROW | ||
EXECUTE FUNCTION invoice_set_user_cancel_default(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters