-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #882 from 0xPolygonID/IN-136-uniqueness-in-title-o…
…f-payment-options feat: Field name of payment is unique.
- Loading branch information
Showing
7 changed files
with
79 additions
and
11 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
21 changes: 21 additions & 0 deletions
21
internal/db/schema/migrations/202501030640326_payment_options_name_unique.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,21 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
|
||
-- Update the name column with unique names | ||
WITH duplicates AS (SELECT id, name, ROW_NUMBER() OVER (PARTITION BY name ORDER BY id) AS row_num | ||
FROM payment_options) | ||
UPDATE payment_options | ||
SET name =payment_options.name || '_' || duplicates.row_num - 1 | ||
FROM duplicates | ||
WHERE payment_options.id = duplicates.id | ||
AND duplicates.row_num > 1; | ||
|
||
ALTER TABLE payment_options | ||
ADD CONSTRAINT payment_options_name_unique UNIQUE (name); | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
ALTER TABLE payment_options | ||
DROP CONSTRAINT payment_options_name_unique; | ||
-- +goose StatementEnd |
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