Skip to content

fix(database): audit_logs.timeline_sequence idempotent on re-run - #357

Merged
telivity-otaip merged 1 commit into
TelivityAI:mainfrom
modernit-com-au:fix-audit-log-timeline-sequence
Aug 30, 2026
Merged

fix(database): audit_logs.timeline_sequence idempotent on re-run#357
telivity-otaip merged 1 commit into
TelivityAI:mainfrom
modernit-com-au:fix-audit-log-timeline-sequence

Conversation

@modernitconsultants

Copy link
Copy Markdown
Collaborator

ADD COLUMN IF NOT EXISTS timeline_sequence bigserial throws relation "audit_logs_timeline_sequence_seq" already exists if push-schema.js runs a second time against a database that already has the column.

Postgres expands bigserial into its implicit CREATE SEQUENCE during statement transformation, before the IF NOT EXISTS existence check runs -- so the sequence creation is attempted regardless of whether the column already exists.

Found running push-schema.js twice against the same database in one session (once via run-migrations.js, which imports and calls pushSchema() directly, once standalone) -- the second run threw and the whole script exited nonzero.

Replaced with an explicit CREATE SEQUENCE IF NOT EXISTS + a plain bigint column with an explicit nextval() default, which is safe to run any number of times.

ADD COLUMN IF NOT EXISTS timeline_sequence bigserial throws 'relation
audit_logs_timeline_sequence_seq already exists' if push-schema.js runs
a second time against a database that already has the column -- the
IF NOT EXISTS existence check runs after Postgres has already expanded
bigserial into its implicit CREATE SEQUENCE during statement
transformation, so the sequence creation is attempted regardless.

Replaced with an explicit CREATE SEQUENCE IF NOT EXISTS + a plain
bigint column with an explicit nextval() default, which is safe to
run any number of times.
@telivity-otaip
telivity-otaip merged commit 4a05538 into TelivityAI:main Aug 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants