Skip to content

feat: add customizable lock value#1403

Merged
Shinigami92 merged 6 commits into
salsita:mainfrom
CanalsAI:add-custom-lock-value
May 14, 2025
Merged

feat: add customizable lock value#1403
Shinigami92 merged 6 commits into
salsita:mainfrom
CanalsAI:add-custom-lock-value

Conversation

@zsalzbank
Copy link
Copy Markdown
Contributor

I have a couple of separate migration directories in the same repository and when I need to, I run the migrations from a specific directory. The migrations all run on the same database, but for different schemas.

If two migration directories run at the same time (but still in separate processes), there is a slight chance that the lock of one directory blocks the migration of the other directory.

To avoid this, I've introduced a lock-value argument to the runner options. This allows customizing the value that is used for the lock from the command line.

I didn't really see any tests for the locking mechanism anywhere, so I didn't add any to this PR, but I'm happy to if you let me know where you'd like them.

@zsalzbank zsalzbank requested a review from Shinigami92 as a code owner May 8, 2025 01:52
@zsalzbank zsalzbank changed the title add customizable lock value feat: add customizable lock value May 8, 2025
@Shinigami92 Shinigami92 added c: feature Request for new feature p: 1-normal Nothing urgent labels May 8, 2025
@Shinigami92 Shinigami92 added this to the vAnytime milestone May 8, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2025

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 92.66% (🎯 90%)
⬆️ +0.01%
3221 / 3476
🟢 Statements 92.66% (🎯 90%)
⬆️ +0.01%
3221 / 3476
🟢 Functions 96.69% (🎯 90%)
🟰 ±0%
263 / 272
🟢 Branches 91.19% (🎯 85%)
⬆️ +0.14%
849 / 931
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/index.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/runner.ts 82.13%
⬆️ +0.38%
67.79%
⬆️ +4.16%
100%
🟰 ±0%
82.13%
⬆️ +0.38%
186, 206-207, 219-220, 272-273, 315-318, 327-331, 344, 356-359, 382, 393, 423-436, 439-442, 462-464, 473, 475-484
Unchanged Files
src/db.ts 83.18% 88.88% 87.5% 83.18% 90-92, 122, 125-137, 177-179
src/logger.ts 100% 100% 100% 100%
src/migration.ts 73.38% 87.27% 66.66% 73.38% 147-150, 171-187, 226-232, 237-275, 332-333, 359-361, 369-370, 387-390, 419-420
src/migrationBuilder.ts 96.18% 93.33% 100% 96.18% 824-828, 967-972
src/migrationOptions.ts 100% 100% 100% 100%
src/pgType.ts 100% 100% 100% 100%
src/sqlMigration.ts 85.36% 100% 80% 85.36% 54-60
src/operations/sql.ts 100% 100% 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% 100% 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 95.52% 94.44% 100% 95.52% 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 95.45% 85.71% 100% 95.45% 71
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 88% 86.95% 100% 88% 23, 33-36, 48
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% 87.5% 100% 100%
src/operations/operators/addToOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/createOperator.ts 100% 100% 100% 100%
src/operations/operators/createOperatorClass.ts 100% 83.33% 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 85% 75% 100% 85% 24-25, 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% 75% 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 98.07% 76.92% 100% 98.07% 78
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 93.75% 75% 100% 93.75% 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 78.57% 68.75% 100% 78.57% 41, 43-44, 49-50, 63-64, 69-70
src/operations/tables/addColumns.ts 100% 80% 100% 100%
src/operations/tables/addConstraint.ts 100% 100% 100% 100%
src/operations/tables/alterColumn.ts 89.33% 76.47% 100% 89.33% 69, 76-83
src/operations/tables/alterTable.ts 100% 100% 100% 100%
src/operations/tables/createTable.ts 89.39% 77.27% 100% 89.39% 51-55, 92-93
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 83.15% 81.81% 80% 83.15% 157-158, 211-215, 241-242, 261-262, 287-288, 291-298, 301-302, 439-464
src/operations/triggers/createTrigger.ts 86.25% 68.18% 100% 86.25% 53-54, 66-67, 70-71, 74-77, 113
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% 66.66% 100% 100%
src/utils/PgLiteral.ts 90.47% 100% 80% 90.47% 44-45
src/utils/StringIdGenerator.ts 100% 100% 100% 100%
src/utils/createSchemalize.ts 100% 100% 100% 100%
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/formatLines.ts 100% 100% 100% 100%
src/utils/formatParams.ts 100% 100% 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/toArray.ts 100% 100% 100% 100%
src/utils/types.ts 100% 100% 100% 100%
Generated in workflow #1937 for commit e8dbc90 by the Vitest Coverage Report Action

@zsalzbank
Copy link
Copy Markdown
Contributor Author

Fixed the formatting issue. Is that why it was assigned back to me? Is there something else I should be doing? Thanks!

@Shinigami92
Copy link
Copy Markdown
Collaborator

Fixed the formatting issue. Is that why it was assigned back to me? Is there something else I should be doing? Thanks!

No, I usually assign the accounts to the PRs, so I can filter in the PR list overview.
I will review it a bit more deeply upcoming weekend.

@Shinigami92 Shinigami92 added the needs test More tests are needed label May 11, 2025
Copy link
Copy Markdown
Collaborator

@Shinigami92 Shinigami92 left a comment

Choose a reason for hiding this comment

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

we definitely need to add a test somehow 🤔
maybe in .github/workflows/postgres-test.yml and/or in test/runner.spec.ts

@zsalzbank zsalzbank requested a review from Shinigami92 May 14, 2025 14:35
Comment thread src/runner.ts Outdated
Comment thread src/runner.ts Outdated
Comment thread bin/node-pg-migrate.ts
Migration,
runner as migrationRunner,
PG_MIGRATE_LOCK_ID,
} from 'node-pg-migrate';
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.

thought: I'm not sure what's going on here, when I try to run everything locally and rebuild everything it works

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it seems rebasing got rid of the links to the old action runs

I think I had to do this because when I added an import to the file that contains the constant directly, the src was not converted to dist, so it failed to import

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.

trying something out with #1408

@Shinigami92 Shinigami92 removed the needs test More tests are needed label May 14, 2025
@Shinigami92
Copy link
Copy Markdown
Collaborator

Please also rebase the PR
For any reason I couldn't push commits into this PR. Maybe this is due to you made the PR from an organization account instead of a user

@zsalzbank zsalzbank force-pushed the add-custom-lock-value branch from 489465d to b26f1e6 Compare May 14, 2025 17:58
@Shinigami92 Shinigami92 self-requested a review May 14, 2025 19:18
@Shinigami92
Copy link
Copy Markdown
Collaborator

@zsalzbank please hit rebase/update branch
I cant do it 🤷

@Shinigami92 Shinigami92 merged commit 5b49dc8 into salsita:main May 14, 2025
41 checks passed
@zsalzbank
Copy link
Copy Markdown
Contributor Author

thanks!

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 p: 1-normal Nothing urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants