chore: configurable database migration in concurrency (#14004)

> [!NOTE]
> Adds a configurable concurrency for link migrations (CLI/commands), forces concurrency=1 when pgstream is detected, and ignores duplicate link-table inserts.
> 
> - **CLI**
>   - Add `--concurrency` option to `db:migrate` and `db:sync-links`.
> - **Medusa commands**
>   - `migrate` and `sync-links` accept `concurrency`; set `DB_MIGRATION_CONCURRENCY` and force `1` when `pgstream` schema exists via new `isPgstreamEnabled`.
> - **Link Modules (migrations)**
>   - Execute plan actions with `executeWithConcurrency` using `DB_MIGRATION_CONCURRENCY`.
>   - Make link-table tracking inserts idempotent with `ON CONFLICT DO NOTHING` (including bulk/upsert and per-create).
> 
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 07432293c8fe8de30b07920fa47823b9081edacc. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
This commit is contained in:
Carlos R. L. Rodrigues
2025-12-04 08:30:30 -03:00
committed by GitHub
parent a33ef1e4d9
commit 5b7e3c0e76
6 changed files with 104 additions and 28 deletions

View File

@@ -196,6 +196,10 @@ function buildLocalCommands(cli, isLocalProject) {
describe:
"Skip prompts and execute only safe actions from sync links",
})
builder.option("concurrency", {
type: "number",
describe: "Number of concurrent migrations to run",
})
},
handler: handlerP(
getCommandHandler("db/migrate", (args, cmd) => {
@@ -270,6 +274,10 @@ function buildLocalCommands(cli, isLocalProject) {
type: "boolean",
describe: "Skip prompts and execute only safe actions",
})
builder.option("concurrency", {
type: "number",
describe: "Number of concurrent migrations to run",
})
},
handler: handlerP(
getCommandHandler("db/sync-links", (args, cmd) => {