generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: setting global config and secrets when using db config provider (#…
…2237) # Problem Setting global config when using db config provider allows creating the same config name over and over again. e.g. ```bash ❯ ftl config set KEY "OKAY1" --db ❯ ftl config get KEY "OKAY1" ❯ ftl config set KEY "OKAY2" --db ❯ ftlprod config get KEY "OKAY1" ``` running `ftl config list` reveals the problem: ```bash ❯ ftlprod config list KEY KEY ``` This problem occurs because of the compound unique constraint [here](https://github.com/TBD54566975/ftl/blob/8dd18e78e9404832f378101e3cee6f1a8b514f66/backend/controller/sql/schema/20231103205514_init.sql#L518). In PostgreSQL, `NULL` values are treated as distinct, so when you have a unique constraint on multiple columns where one of the columns can be `NULL`, each `NULL` is treated as a different value. This means that multiple rows can have `NULL` in the module column and the same value in the name column without violating the unique constraint. # Fix This PR proposes treating a `NULL` module value as `''` when creating the unique compound constraint > [!NOTE] > I believe the following would also work > ```sql > > ALTER TABLE module_configuration > ALTER COLUMN module SET DEFAULT ''; > ``` > [!NOTE] > I went with `''` to prevent colliding with potential module names and i chose _not_ to default module to `''` to prevent application code from treating `''` as a not nil value though go does treat `''` as the zero value for a string but im not sure how that works with `optional.Option`. --------- Co-authored-by: Jiyoon Koo <[email protected]> Co-authored-by: Wes <[email protected]>
- Loading branch information
1 parent
c38a754
commit 06303c6
Showing
7 changed files
with
260 additions
and
114 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
backend/controller/sql/schema/20240801160101_edit-db-secrets-and-configuration.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,10 @@ | ||
-- migrate:up | ||
|
||
CREATE UNIQUE INDEX module_config_name_unique | ||
ON module_configuration ((COALESCE(module, '')), name); | ||
|
||
CREATE UNIQUE INDEX module_secret_name_unique | ||
ON module_secrets ((COALESCE(module, '')), name); | ||
|
||
-- migrate:down | ||
|
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
Oops, something went wrong.