diff --git a/common/configuration/dal/dal_test.go b/common/configuration/dal/dal_test.go index 4016e51720..8539361a2e 100644 --- a/common/configuration/dal/dal_test.go +++ b/common/configuration/dal/dal_test.go @@ -100,6 +100,13 @@ func TestModuleConfiguration(t *testing.T) { assert.Equal(t, sortedList[i].Name, gotList[i].Name) } }) + + t.Run("HandlesConflicts", func(t *testing.T) { + err := dal.SetModuleConfiguration(ctx, optional.Some("echo"), "my_config", []byte(`""`)) + assert.NoError(t, err) + err = dal.SetModuleConfiguration(ctx, optional.Some("echo"), "my_config", []byte(`""`)) + assert.NoError(t, err) + }) } func TestModuleSecrets(t *testing.T) { diff --git a/common/configuration/sql/queries.sql b/common/configuration/sql/queries.sql index 9bcbaed4e2..9862adbd46 100644 --- a/common/configuration/sql/queries.sql +++ b/common/configuration/sql/queries.sql @@ -14,7 +14,8 @@ ORDER BY module, name; -- name: SetModuleConfiguration :exec INSERT INTO module_configuration (module, name, value) -VALUES ($1, $2, $3); +VALUES ($1, $2, $3) +ON CONFLICT (module, name) DO UPDATE SET value = $3; -- name: UnsetModuleConfiguration :exec DELETE FROM module_configuration diff --git a/common/configuration/sql/queries.sql.go b/common/configuration/sql/queries.sql.go index 5086e3f57e..99f3c30475 100644 --- a/common/configuration/sql/queries.sql.go +++ b/common/configuration/sql/queries.sql.go @@ -112,6 +112,7 @@ func (q *Queries) ListModuleSecrets(ctx context.Context) ([]ModuleSecret, error) const setModuleConfiguration = `-- name: SetModuleConfiguration :exec INSERT INTO module_configuration (module, name, value) VALUES ($1, $2, $3) +ON CONFLICT (module, name) DO UPDATE SET value = $3 ` func (q *Queries) SetModuleConfiguration(ctx context.Context, module optional.Option[string], name string, value []byte) error {