Skip to content

feat: introduce advisory lock mode#1648

Merged
Shinigami92 merged 2 commits into
salsita:mainfrom
nemisj:advisory-lock-mode
Jun 8, 2026
Merged

feat: introduce advisory lock mode#1648
Shinigami92 merged 2 commits into
salsita:mainfrom
nemisj:advisory-lock-mode

Conversation

@nemisj

@nemisj nemisj commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This PR introduces a new advisoryLockMode option for migration locking.

Current behavior uses pg_try_advisory_lock, which fails immediately when another migration process already holds the advisory lock. While this behavior is preserved as the default ('fail') for backward compatibility, users can now opt into 'wait' mode, which uses pg_advisory_lock and waits until the lock becomes available.

This is particularly useful in deployment environments where multiple application instances may attempt to run migrations concurrently and should be serialized rather than fail.

Available modes:

  • fail (default): Fail immediately if the advisory lock is already held.
  • wait: Wait until the advisory lock becomes available.

ref: #1647

@nemisj
nemisj force-pushed the advisory-lock-mode branch from 661d7a5 to f99ec39 Compare June 3, 2026 09:32
@Shinigami92 Shinigami92 changed the title chore: introduce advisory lock mode feat: introduce advisory lock mode Jun 3, 2026
@Shinigami92 Shinigami92 added the c: feature Request for new feature label Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 93.65% (🎯 90%)
⬆️ +0.01%
1551 / 1656
🔵 Statements 93.56% (🎯 90%)
⬆️ +0.01%
1571 / 1679
🔵 Functions 95.04% (🎯 90%)
🟰 ±0%
345 / 363
🔵 Branches 87.17% (🎯 85%)
⬆️ +0.03%
979 / 1123
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/runner.ts 78.86%
⬆️ +0.53%
63.88%
⬆️ +1.57%
82.6%
🟰 ±0%
78.15%
⬆️ +0.57%
217-219, 238-240, 292, 337, 347-350, 364, 376-378, 402, 443-454, 459-461, 482-483, 493, 495-503
Unchanged Files
src/db.ts 78.43% 75% 76.92% 78% 88-90, 123-135, 171, 175-176
src/index.ts 100% 100% 100% 100%
src/logger.ts 100% 100% 100% 100%
src/migration.ts 76.53% 69.11% 80% 76.28% 129-131, 153-168, 233-268, 334, 361-363, 371, 389-391, 421
src/migrationBuilder.ts 95.49% 62.5% 90% 95.49% 833-836, 973-977
src/migrationLoader.ts 90.81% 82.69% 90% 93.54% 225, 364, 368, 371, 374, 408, 427, 434-435
src/migrationOptions.ts 100% 100% 100% 100%
src/pgType.ts 100% 100% 100% 100%
src/sqlMigration.ts 100% 100% 100% 100%
src/operations/sql.ts 100% 50% 100% 100%
src/operations/casts/createCast.ts 100% 100% 100% 100%
src/operations/casts/dropCast.ts 100% 100% 100% 100%
src/operations/casts/index.ts 100% 100% 100% 100%
src/operations/domains/alterDomain.ts 100% 100% 100% 100%
src/operations/domains/createDomain.ts 100% 95.45% 100% 100%
src/operations/domains/dropDomain.ts 100% 100% 100% 100%
src/operations/domains/index.ts 100% 100% 100% 100%
src/operations/domains/renameDomain.ts 100% 100% 100% 100%
src/operations/domains/shared.ts 100% 100% 100% 100%
src/operations/extensions/createExtension.ts 100% 100% 100% 100%
src/operations/extensions/dropExtension.ts 100% 100% 100% 100%
src/operations/extensions/index.ts 100% 100% 100% 100%
src/operations/extensions/shared.ts 100% 100% 100% 100%
src/operations/functions/createFunction.ts 96.29% 92% 100% 96.29% 71-73
src/operations/functions/dropFunction.ts 100% 100% 100% 100%
src/operations/functions/index.ts 100% 100% 100% 100%
src/operations/functions/renameFunction.ts 100% 100% 100% 100%
src/operations/functions/shared.ts 100% 100% 100% 100%
src/operations/grants/grantOnSchemas.ts 100% 100% 100% 100%
src/operations/grants/grantOnTables.ts 100% 100% 100% 100%
src/operations/grants/grantRoles.ts 100% 100% 100% 100%
src/operations/grants/index.ts 100% 100% 100% 100%
src/operations/grants/revokeOnSchemas.ts 100% 100% 100% 100%
src/operations/grants/revokeOnTables.ts 100% 100% 100% 100%
src/operations/grants/revokeRoles.ts 100% 100% 100% 100%
src/operations/grants/shared.ts 100% 75% 100% 100%
src/operations/indexes/createIndex.ts 100% 100% 100% 100%
src/operations/indexes/dropIndex.ts 100% 100% 100% 100%
src/operations/indexes/index.ts 100% 100% 100% 100%
src/operations/indexes/shared.ts 100% 88.23% 100% 100%
src/operations/materializedViews/alterMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/createMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/dropMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/index.ts 100% 100% 100% 100%
src/operations/materializedViews/refreshMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/renameMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/renameMaterializedViewColumn.ts 100% 100% 100% 100%
src/operations/materializedViews/shared.ts 100% 83.33% 100% 100%
src/operations/operators/addToOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/createOperator.ts 100% 88.88% 100% 100%
src/operations/operators/createOperatorClass.ts 100% 75% 100% 100%
src/operations/operators/createOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/dropOperator.ts 100% 100% 100% 100%
src/operations/operators/dropOperatorClass.ts 100% 100% 100% 100%
src/operations/operators/dropOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/index.ts 100% 100% 100% 100%
src/operations/operators/removeFromOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/renameOperatorClass.ts 100% 100% 100% 100%
src/operations/operators/renameOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/shared.ts 81.81% 77.77% 100% 81.81% 24, 38
src/operations/policies/alterPolicy.ts 100% 100% 100% 100%
src/operations/policies/createPolicy.ts 100% 100% 100% 100%
src/operations/policies/dropPolicy.ts 100% 100% 100% 100%
src/operations/policies/index.ts 100% 100% 100% 100%
src/operations/policies/renamePolicy.ts 100% 100% 100% 100%
src/operations/policies/shared.ts 100% 100% 100% 100%
src/operations/roles/alterRole.ts 100% 100% 100% 100%
src/operations/roles/createRole.ts 100% 92.3% 100% 100%
src/operations/roles/dropRole.ts 100% 100% 100% 100%
src/operations/roles/index.ts 100% 100% 100% 100%
src/operations/roles/renameRole.ts 100% 100% 100% 100%
src/operations/roles/shared.ts 100% 86.66% 100% 100%
src/operations/schemas/createSchema.ts 100% 100% 100% 100%
src/operations/schemas/dropSchema.ts 100% 100% 100% 100%
src/operations/schemas/index.ts 100% 100% 100% 100%
src/operations/schemas/renameSchema.ts 100% 100% 100% 100%
src/operations/sequences/alterSequence.ts 90% 83.33% 100% 90% 23
src/operations/sequences/createSequence.ts 100% 100% 100% 100%
src/operations/sequences/dropSequence.ts 100% 100% 100% 100%
src/operations/sequences/index.ts 100% 100% 100% 100%
src/operations/sequences/renameSequence.ts 100% 100% 100% 100%
src/operations/sequences/shared.ts 81.48% 83.33% 100% 81.48% 41, 43, 49, 63, 69
src/operations/tables/addColumns.ts 100% 85.71% 100% 100%
src/operations/tables/addConstraint.ts 100% 100% 100% 100%
src/operations/tables/alterColumn.ts 91.17% 81.25% 100% 91.17% 69, 76-83
src/operations/tables/alterTable.ts 100% 100% 100% 100%
src/operations/tables/createTable.ts 88% 82.14% 100% 88% 51-54, 92
src/operations/tables/dropColumns.ts 100% 100% 100% 100%
src/operations/tables/dropConstraint.ts 100% 100% 100% 100%
src/operations/tables/dropTable.ts 100% 100% 100% 100%
src/operations/tables/index.ts 100% 100% 100% 100%
src/operations/tables/renameColumn.ts 100% 100% 100% 100%
src/operations/tables/renameConstraint.ts 100% 100% 100% 100%
src/operations/tables/renameTable.ts 100% 100% 100% 100%
src/operations/tables/shared.ts 86.79% 76.76% 76.47% 86.79% 157, 239, 259, 285, 289-295, 299, 440-461
src/operations/triggers/createTrigger.ts 88.23% 71.79% 100% 88.23% 53, 66, 70, 74-76
src/operations/triggers/dropTrigger.ts 100% 100% 100% 100%
src/operations/triggers/index.ts 100% 100% 100% 100%
src/operations/triggers/renameTrigger.ts 100% 100% 100% 100%
src/operations/triggers/shared.ts 100% 100% 100% 100%
src/operations/types/addTypeAttribute.ts 100% 100% 100% 100%
src/operations/types/addTypeValue.ts 100% 100% 100% 100%
src/operations/types/createType.ts 100% 100% 100% 100%
src/operations/types/dropType.ts 100% 100% 100% 100%
src/operations/types/dropTypeAttribute.ts 100% 100% 100% 100%
src/operations/types/index.ts 100% 100% 100% 100%
src/operations/types/renameType.ts 100% 100% 100% 100%
src/operations/types/renameTypeAttribute.ts 100% 100% 100% 100%
src/operations/types/renameTypeValue.ts 100% 100% 100% 100%
src/operations/types/setTypeAttribute.ts 100% 100% 100% 100%
src/operations/views/alterView.ts 100% 100% 100% 100%
src/operations/views/alterViewColumn.ts 100% 100% 100% 100%
src/operations/views/createView.ts 100% 100% 100% 100%
src/operations/views/dropView.ts 100% 100% 100% 100%
src/operations/views/index.ts 100% 100% 100% 100%
src/operations/views/renameView.ts 100% 100% 100% 100%
src/operations/views/shared.ts 100% 50% 100% 100%
src/utils/PgLiteral.ts 100% 100% 100% 100%
src/utils/comparators.ts 100% 100% 100% 100%
src/utils/createSchemalize.ts 96.42% 93.54% 100% 96.29% 84
src/utils/createTransformer.ts 100% 100% 100% 100%
src/utils/decamelize.ts 100% 100% 100% 100%
src/utils/escapeValue.ts 100% 100% 100% 100%
src/utils/fileNameUtils.ts 100% 100% 100% 100%
src/utils/formatLines.ts 100% 100% 100% 100%
src/utils/formatParams.ts 100% 87.5% 100% 100%
src/utils/formatPartitionColumns.ts 100% 100% 100% 100%
src/utils/getMigrationTableSchema.ts 100% 100% 100% 100%
src/utils/getSchemas.ts 100% 100% 100% 100%
src/utils/identity.ts 100% 100% 100% 100%
src/utils/index.ts 100% 100% 100% 100%
src/utils/intersection.ts 100% 100% 100% 100%
src/utils/makeComment.ts 100% 100% 100% 100%
src/utils/quote.ts 100% 100% 100% 100%
src/utils/stringIdGenerator.ts 100% 100% 100% 100%
src/utils/toArray.ts 100% 100% 100% 100%
src/utils/types.ts 100% 100% 100% 100%
Generated in workflow #3383 for commit 50c557e by the Vitest Coverage Report Action

@Shinigami92

Copy link
Copy Markdown
Collaborator

basic shape of the PR looks already mergable 👍

however I would like to make an in-depth review with claude from home this evening

my current gut feeling: are fail and wait the best terms here? 🤔

@nemisj

nemisj commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

basic shape of the PR looks already mergable 👍

however I would like to make an in-depth review with claude from home this evening

my current gut feeling: are fail and wait the best terms here? 🤔

take your time :)

@nemisj
nemisj force-pushed the advisory-lock-mode branch from f99ec39 to 669c99b Compare June 3, 2026 11:13
@nemisj

nemisj commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@Shinigami92 i have also added Troubleshooting explanation

@Shinigami92 Shinigami92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Opus 4.8 is fine with wait/fail 🙁

Comment thread docs/src/api.md Outdated
Comment thread src/runner.ts
Comment thread test/runner.spec.ts Outdated
Comment thread test/runner.spec.ts Outdated
Comment thread src/runner.ts
Comment thread src/runner.ts Outdated
Comment thread src/runner.ts
@nemisj
nemisj force-pushed the advisory-lock-mode branch from 669c99b to 3cf2cc7 Compare June 3, 2026 15:58
@nemisj

nemisj commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@Shinigami92 how can i fix the lint issue? in the bin/node-pg-migrate.ts you use type from the node-pg-migrate package, and this augmented type is not published yet

Comment thread bin/node-pg-migrate.ts
@Shinigami92

Copy link
Copy Markdown
Collaborator

@Shinigami92 how can i fix the lint issue? in the bin/node-pg-migrate.ts you use type from the node-pg-migrate package, and this augmented type is not published yet

this is something we will fix in v10
until then, build once, then it works

@nemisj
nemisj force-pushed the advisory-lock-mode branch from 2035ee6 to 711d1e9 Compare June 3, 2026 16:17
@Shinigami92

Copy link
Copy Markdown
Collaborator

@nemisj You can see the errors also in the job runs
I think best what you can do is run pnpm run preflight twice at the first time, the install or build command will then set it up
after the first time further runs should work

Comment thread bin/node-pg-migrate.ts
@nemisj
nemisj force-pushed the advisory-lock-mode branch 3 times, most recently from af55716 to f095aed Compare June 4, 2026 10:39

@Shinigami92 Shinigami92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it gets too much for you, say a word and I can take over when I find the time

Comment thread bin/node-pg-migrate.ts Outdated
@nemisj
nemisj force-pushed the advisory-lock-mode branch from f095aed to 50c557e Compare June 4, 2026 19:48
@nemisj

nemisj commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@Shinigami92 do you think it takes long for others to review? i would love to use this feature as soon as possible 😇, since currently i'm patching the node-pg-migrate on our end

@Shinigami92

Copy link
Copy Markdown
Collaborator

@Shinigami92 do you think it takes long for others to review? i would love to use this feature as soon as possible 😇, since currently i'm patching the node-pg-migrate on our end

You can expect to work with it in upcoming week
But please respect timezones
The other two (new) maintainers are in 🇧🇷 and 🇯🇵

@nemisj

nemisj commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@Shinigami92 do you think it takes long for others to review? i would love to use this feature as soon as possible 😇, since currently i'm patching the node-pg-migrate on our end

You can expect to work with it in upcoming week But please respect timezones The other two (new) maintainers are in 🇧🇷 and 🇯🇵

Great. thanks :)

@Shinigami92
Shinigami92 added this pull request to the merge queue Jun 8, 2026
Merged via the queue into salsita:main with commit bca90c5 Jun 8, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: feature Request for new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants