Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/PostgresMetaColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ COMMIT;`
default_value,
default_value_format = 'literal',
is_identity,
identity_generation = 'BY DEFAULT',
identity_generation,
is_nullable,
is_unique,
comment,
Expand Down Expand Up @@ -265,7 +265,7 @@ COMMIT;`
} else if (is_identity === undefined) {
identitySql = ''
} else {
identitySql += ` ADD GENERATED ${identity_generation} AS IDENTITY;`
identitySql += ` ADD GENERATED ${identity_generation ?? 'BY DEFAULT'} AS IDENTITY;`
}
let isNullableSql: string
if (is_nullable === undefined) {
Expand Down
26 changes: 26 additions & 0 deletions test/lib/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,3 +1017,29 @@ test('column with fully-qualified type', async () => {

await pgMeta.query(`drop table public.t; drop schema s cascade;`)
})

test('updating a comment does not rewrite ALWAYS identity to BY DEFAULT', async () => {
const { data: table, error: tableError } = await pgMeta.tables.create({
name: 't_identity_comment_update',
})
expect(tableError).toBeNull()

try {
const created = await pgMeta.columns.create({
table_id: table!.id,
name: 'id',
type: 'int8',
is_identity: true,
identity_generation: 'ALWAYS',
})
expect(created.error).toBeNull()
expect(created.data!.identity_generation).toBe('ALWAYS')

const updated = await pgMeta.columns.update(created.data!.id, { comment: 'pk' })
expect(updated.error).toBeNull()
expect(updated.data!.identity_generation).toBe('ALWAYS')
expect(updated.data!.comment).toBe('pk')
} finally {
await pgMeta.tables.remove(table!.id, { cascade: true })
}
})