Skip to content

Commit

Permalink
fix: integration should be unique per environment
Browse files Browse the repository at this point in the history
The unique constraint for integration is for unique_key, environment_id
and deleted_at which can be null. However null values are not considered
equal by default by postgres. :/

from postgres doc at https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-UNIQUE-CONSTRAINTS
> By default, two null values are not considered equal in this
comparison. That means even in the presence of a unique constraint it is
possible to store duplicate rows that contain a null value in at least
one of the constrained columns. This behavior can be changed by adding
the clause NULLS NOT DISTINCT
  • Loading branch information
TBonnin committed Mar 20, 2024
1 parent f1bf2db commit e919108
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.up = async function (knex) {
return knex
.raw('ALTER TABLE _nango_configs DROP CONSTRAINT IF EXISTS _nango_configs_unique_key_environment_id_deleted_at_unique')
.then(() =>
knex.raw(
'ALTER TABLE _nango_configs ADD CONSTRAINT _nango_configs_unique_key_environment_id_deleted_at_unique UNIQUE NULLS NOT DISTINCT (unique_key, environment_id, deleted_at)'
)
);
};

exports.down = async function () {};

0 comments on commit e919108

Please sign in to comment.