1- import { ErrCode , makeScopeChecker , RecaseError , Scopes } from "@autumn/shared" ;
1+ import { ErrCode , RecaseError , Scopes } from "@autumn/shared" ;
22import { auth } from "@trigger.dev/sdk/v3" ;
33import { z } from "zod/v4" ;
44import { createRoute } from "@/honoMiddlewares/routeHandler" ;
@@ -7,49 +7,39 @@ import { prepare } from "@/internal/migrations/v2/prepare/index.js";
77import { migrationRepo } from "@/internal/migrations/v2/repos/index.js" ;
88import { RETRYABLE_MIGRATION_ITEM_RUN_STATUSES } from "@/internal/migrations/v2/run/utils/retryItemStatuses.js" ;
99import { shouldRunMigrationInline } from "@/internal/migrations/v2/utils/shouldRunMigrationInline.js" ;
10+ import {
11+ getMigrationTriggerOptions ,
12+ MIGRATION_RUN_CUSTOMER_CONCURRENCY ,
13+ } from "@/trigger/migrations/migrationTaskQueue.js" ;
1014import {
1115 executeRunMigration ,
1216 type RunMigrationPayload ,
1317 runMigrationTask ,
1418} from "@/trigger/migrations/runMigrationTask.js" ;
1519
16- const MAX_CONCURRENCY = 5 ;
17- const SUPERUSER_MAX_CONCURRENCY = 100 ;
20+ const LEGACY_MAX_REQUESTED_CONCURRENCY = 100 ;
1821
1922const RunMigrationBody = z . object ( {
2023 id : z . string ( ) ,
2124 dry_run : z . boolean ( ) . default ( false ) ,
2225 limit : z . number ( ) . int ( ) . min ( 1 ) . optional ( ) ,
2326 only : z . array ( z . string ( ) ) . optional ( ) ,
27+ /** Accepted for backward compatibility; migration concurrency is fleet-managed. */
2428 concurrency : z
2529 . number ( )
2630 . int ( )
2731 . min ( 1 )
28- . max ( SUPERUSER_MAX_CONCURRENCY )
29- . optional ( ) ,
32+ . max ( LEGACY_MAX_REQUESTED_CONCURRENCY )
33+ . optional ( )
34+ . describe ( "Deprecated: migration concurrency is fleet-managed" ) ,
3035 retry_item_statuses : z
3136 . array ( z . enum ( RETRYABLE_MIGRATION_ITEM_RUN_STATUSES ) )
3237 . optional ( ) ,
33- /** When true, claim a lazy run alongside the background sweeper. Customers
34- * hit on the request path get migrated lazily via `runMigrationCustomerTask`
35- * before the sweeper reaches them. Background and lazy run on the same
36- * migration_run row — the claim is shared. */
38+ /** Lazy runs share one run row with the sweeper and enqueue request-path customer work.
39+ * Targeted `only` is incompatible because lazy matching happens on customer reads. */
3740 lazy_run : z . boolean ( ) . default ( false ) ,
3841} ) ;
3942
40- const getRunMigrationTriggerOptions = ( {
41- orgId,
42- migrationId,
43- isDev,
44- } : {
45- orgId : string ;
46- migrationId : string ;
47- isDev : boolean ;
48- } ) => ( {
49- ...( isDev ? { region : "eu-central-1" } : { } ) ,
50- concurrencyKey : `${ orgId } :${ migrationId } ` ,
51- } ) ;
52-
5343export const handleRunMigration = createRoute ( {
5444 scopes : [ Scopes . Migrations . Write ] ,
5545 body : RunMigrationBody ,
@@ -60,23 +50,10 @@ export const handleRunMigration = createRoute({
6050 dry_run : dryRun ,
6151 limit,
6252 only,
63- concurrency,
6453 retry_item_statuses : retryItemStatuses ,
6554 lazy_run : lazyRun ,
6655 } = c . req . valid ( "json" ) ;
6756
68- const { isSuperuser } = makeScopeChecker ( ctx . scopes ) ;
69- const maxConcurrency = isSuperuser
70- ? SUPERUSER_MAX_CONCURRENCY
71- : MAX_CONCURRENCY ;
72- if ( concurrency !== undefined && concurrency > maxConcurrency ) {
73- throw new RecaseError ( {
74- message : `Migration concurrency cannot exceed ${ maxConcurrency } ` ,
75- code : ErrCode . InvalidRequest ,
76- statusCode : 400 ,
77- } ) ;
78- }
79-
8057 const migration = await migrationRepo . find ( { ctx, id } ) ;
8158
8259 if ( ! migration . operations )
@@ -119,7 +96,6 @@ export const handleRunMigration = createRoute({
11996 controls : {
12097 limit,
12198 only,
122- concurrency,
12399 retryItemStatuses,
124100 } ,
125101 } ;
@@ -129,11 +105,7 @@ export const handleRunMigration = createRoute({
129105 }
130106 const handle = await runMigrationTask . trigger (
131107 payload ,
132- getRunMigrationTriggerOptions ( {
133- orgId : ctx . org . id ,
134- migrationId : id ,
135- isDev,
136- } ) ,
108+ getMigrationTriggerOptions ( { isDev } ) ,
137109 ) ;
138110 return { triggerRunId : handle . id } ;
139111 } ,
@@ -176,7 +148,7 @@ export const handleRunMigration = createRoute({
176148 migration_id : id ,
177149 dry_run : dryRun ,
178150 lazy_run : lazyRun ,
179- concurrency,
151+ concurrency : MIGRATION_RUN_CUSTOMER_CONCURRENCY ,
180152 run_id : migrationRunId ,
181153 trigger_run_id : triggerRunId ,
182154 public_access_token : publicAccessToken ,
0 commit comments