Skip to content

Commit

Permalink
Fix CrDB auto-increment detection (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
licitdev authored Jan 30, 2023
1 parent ced5a9b commit 106415d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/dialects/cockroachdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ export default class CockroachDB implements SchemaInspector {
att.attname AS column,
frel.relnamespace::regnamespace::text AS foreign_key_schema,
frel.relname AS foreign_key_table,
fatt.attname AS foreign_key_column,
false AS has_auto_increment
fatt.attname AS foreign_key_column
FROM
pg_constraint con
LEFT JOIN pg_class rel ON con.conrelid = rel.oid
Expand Down Expand Up @@ -311,9 +310,9 @@ export default class CockroachDB implements SchemaInspector {
is_primary_key: constraintsForColumn.some(
(constraint) => constraint.type === 'p'
),
has_auto_increment: constraintsForColumn.some(
(constraint) => constraint.has_auto_increment
),
has_auto_increment:
['integer', 'bigint'].includes(col.data_type) &&
(col.default_value?.startsWith('nextval(') ?? false),
default_value: parseDefaultValue(col.default_value),
foreign_key_schema: foreignKeyConstraint?.foreign_key_schema ?? null,
foreign_key_table: foreignKeyConstraint?.foreign_key_table ?? null,
Expand Down

0 comments on commit 106415d

Please sign in to comment.