Skip to content

Commit

Permalink
fix: remove consrc usage (postgres,cockroachdb) (#4333)
Browse files Browse the repository at this point in the history
Replace usage of pg_constraint.consrc with pg_get_constraintdef() in all
cases. PostgreSQL 12 no longer supports consrc. Use the same code in
CockroachDB for consistency.

Closes: #4332
  • Loading branch information
luzat authored and pleerock committed Nov 25, 2019
1 parent ce7ee67 commit ce7cb16
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/driver/cockroachdb/CockroachQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ export class CockroachQueryRunner extends BaseQueryRunner implements QueryRunner
}).join(" OR ");

const constraintsSql = `SELECT "ns"."nspname" AS "table_schema", "t"."relname" AS "table_name", "cnst"."conname" AS "constraint_name", ` +
`CASE "cnst"."contype" WHEN 'x' THEN pg_get_constraintdef("cnst"."oid", true) ELSE "cnst"."consrc" END AS "expression", ` +
`pg_get_constraintdef("cnst"."oid") AS "expression", ` +
`CASE "cnst"."contype" WHEN 'p' THEN 'PRIMARY' WHEN 'u' THEN 'UNIQUE' WHEN 'c' THEN 'CHECK' WHEN 'x' THEN 'EXCLUDE' END AS "constraint_type", "a"."attname" AS "column_name" ` +
`FROM "pg_constraint" "cnst" ` +
`INNER JOIN "pg_class" "t" ON "t"."oid" = "cnst"."conrelid" ` +
Expand Down Expand Up @@ -1507,7 +1507,7 @@ export class CockroachQueryRunner extends BaseQueryRunner implements QueryRunner
return new TableCheck({
name: constraint["constraint_name"],
columnNames: checks.map(c => c["column_name"]),
expression: constraint["expression"] // column names are not escaped, may cause problems
expression: constraint["expression"].replace(/^\s*CHECK\s*\((.*)\)\s*$/i, "$1")
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/driver/postgres/PostgresQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
}).join(" OR ");

const constraintsSql = `SELECT "ns"."nspname" AS "table_schema", "t"."relname" AS "table_name", "cnst"."conname" AS "constraint_name", ` +
`CASE "cnst"."contype" WHEN 'x' THEN pg_get_constraintdef("cnst"."oid", true) ELSE "cnst"."consrc" END AS "expression", ` +
`pg_get_constraintdef("cnst"."oid") AS "expression", ` +
`CASE "cnst"."contype" WHEN 'p' THEN 'PRIMARY' WHEN 'u' THEN 'UNIQUE' WHEN 'c' THEN 'CHECK' WHEN 'x' THEN 'EXCLUDE' END AS "constraint_type", "a"."attname" AS "column_name" ` +
`FROM "pg_constraint" "cnst" ` +
`INNER JOIN "pg_class" "t" ON "t"."oid" = "cnst"."conrelid" ` +
Expand Down Expand Up @@ -1586,7 +1586,7 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
return new TableCheck({
name: constraint["constraint_name"],
columnNames: checks.map(c => c["column_name"]),
expression: constraint["expression"] // column names are not escaped, may cause problems
expression: constraint["expression"].replace(/^\s*CHECK\s*\((.*)\)\s*$/i, "$1")
});
});

Expand Down

0 comments on commit ce7cb16

Please sign in to comment.