-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automatic payments cancellation
- Loading branch information
1 parent
a26a557
commit b35bb73
Showing
16 changed files
with
760 additions
and
17 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
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
9 changes: 9 additions & 0 deletions
9
internal/db/migrations/2023-10-20-alter-organizations-table.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,9 @@ | ||
-- +migrate Up | ||
ALTER TABLE | ||
public.organizations | ||
ADD | ||
COLUMN payment_cancellation_period int; | ||
|
||
-- +migrate Down | ||
ALTER TABLE | ||
public.public.organizations DROP COLUMN payment_cancellation_period; |
45 changes: 45 additions & 0 deletions
45
internal/db/migrations/2023-10-20-update-payments-status-type.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,45 @@ | ||
-- Update the payments_status type. | ||
-- Add a new value 'CANCELED'. | ||
|
||
-- +migrate Up | ||
ALTER TYPE payment_status | ||
ADD | ||
VALUE 'CANCELED'; | ||
|
||
-- +migrate Down | ||
UPDATE | ||
payments | ||
SET | ||
status = 'FAILED'::payment_status | ||
WHERE | ||
status = 'CANCELED'::payment_status; | ||
|
||
ALTER TYPE payment_status RENAME TO old_payment_status; | ||
|
||
CREATE TYPE payment_status AS ENUM ( | ||
'DRAFT', | ||
'READY', | ||
'PENDING', | ||
'PAUSED', | ||
'SUCCESS', | ||
'FAILED' | ||
); | ||
|
||
-- +migrate StatementBegin | ||
CREATE OR REPLACE FUNCTION create_payment_status_history(time_stamp TIMESTAMP WITH TIME ZONE, pay_status payment_status, status_message VARCHAR) | ||
RETURNS jsonb AS $$ | ||
BEGIN | ||
RETURN json_build_object( | ||
'timestamp', time_stamp, | ||
'status', pay_status, | ||
'status_message', status_message | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
-- +migrate StatementEnd | ||
|
||
ALTER TABLE payments RENAME COLUMN status TO status_old; | ||
ALTER TABLE payments ADD COLUMN status payment_status DEFAULT payment_status('DRAFT'); | ||
UPDATE payments SET status = status_old::text::payment_status; | ||
ALTER TABLE payments DROP COLUMN status_old; | ||
DROP TYPE old_payment_status CASCADE; |
Oops, something went wrong.