Skip to content

Commit

Permalink
Merge pull request #569 from supabase/fix/allow-deleting-of-check-con…
Browse files Browse the repository at this point in the history
…straints

fix: allow deletion of check constraints
  • Loading branch information
alaister committed Apr 11, 2023
2 parents 2e54b2d + dd2af8c commit ec14254
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib/PostgresMetaColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ COMMIT;`
is_nullable?: boolean
is_unique?: boolean
comment?: string
check?: string
check?: string | null
}
): Promise<PostgresMetaResult<PostgresColumn>> {
const { data: old, error } = await this.retrieve({ id })
Expand Down Expand Up @@ -353,9 +353,12 @@ BEGIN
)} DROP CONSTRAINT %s', v_conname);
END IF;
${
check !== null
? `
ALTER TABLE ${ident(old!.schema)}.${ident(old!.table)} ADD CONSTRAINT ${ident(
`${old!.table}_${old!.name}_check`
)} CHECK (${check});
`${old!.table}_${old!.name}_check`
)} CHECK (${check});
SELECT conkey into v_conkey FROM pg_constraint WHERE conname = ${literal(
`${old!.table}_${old!.name}_check`
Expand All @@ -366,6 +369,9 @@ BEGIN
ASSERT v_conkey[1] = ${literal(
old!.ordinal_position
)}, 'error creating column constraint: check condition cannot refer to other columns';
`
: ''
}
END
$$;
`
Expand Down

0 comments on commit ec14254

Please sign in to comment.