fix(database): audit_logs.timeline_sequence idempotent on re-run - #357
Merged
telivity-otaip merged 1 commit intoAug 30, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADD COLUMN IF NOT EXISTS timeline_sequence bigserialthrowsrelation "audit_logs_timeline_sequence_seq" already existsif push-schema.js runs a second time against a database that already has the column.Postgres expands
bigserialinto its implicitCREATE SEQUENCEduring statement transformation, before theIF NOT EXISTSexistence 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 plainbigintcolumn with an explicitnextval()default, which is safe to run any number of times.