@xixixao/convex-migrations 0.3.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +523 -0
- package/dist/client/index.d.ts +390 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +528 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/log.d.ts +8 -0
- package/dist/client/log.d.ts.map +1 -0
- package/dist/client/log.js +74 -0
- package/dist/client/log.js.map +1 -0
- package/dist/component/_generated/api.d.ts +34 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +95 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +74 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +290 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +28 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +20 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/shared.d.ts +40 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +22 -0
- package/dist/shared.js.map +1 -0
- package/package.json +95 -0
- package/src/client/index.test.ts +16 -0
- package/src/client/index.ts +765 -0
- package/src/client/log.ts +76 -0
- package/src/component/_generated/api.ts +50 -0
- package/src/component/_generated/component.ts +116 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +161 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/lib.test.ts +110 -0
- package/src/component/lib.ts +356 -0
- package/src/component/schema.ts +20 -0
- package/src/component/setup.test.ts +5 -0
- package/src/shared.ts +37 -0
- package/src/test.ts +18 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { type DocumentByName, type FunctionReference, type GenericActionCtx, type GenericDataModel, type GenericMutationCtx, type GenericQueryCtx, type MutationBuilder, type NamedTableInfo, type OrderedQuery, type QueryInitializer, type RegisteredMutation, type TableNamesInDataModel } from "convex/server";
|
|
2
|
+
import { type MigrationArgs, type MigrationResult, type MigrationStatus } from "../shared.js";
|
|
3
|
+
export type { MigrationArgs, MigrationResult, MigrationStatus };
|
|
4
|
+
import { type GenericId, type GenericValidator, type Infer, type ObjectType, type PropertyValidators, type Validator } from "convex/values";
|
|
5
|
+
import type { ComponentApi } from "../component/_generated/component.js";
|
|
6
|
+
import type { MigrationFunctionHandle } from "../component/lib.js";
|
|
7
|
+
export declare const DEFAULT_BATCH_SIZE = 100;
|
|
8
|
+
/**
|
|
9
|
+
* Infer the TypeScript type from an args validator definition.
|
|
10
|
+
* - If a single Validator (e.g. `v.object({...})`), use `Infer<T>`.
|
|
11
|
+
* - If PropertyValidators (e.g. `{ tag: v.string() }`), use `ObjectType<T>`.
|
|
12
|
+
* - If void/undefined (no args defined), the args type is `undefined`.
|
|
13
|
+
*/
|
|
14
|
+
type InferMigrationArgs<T> = T extends Validator<any, any, any> ? Infer<T> : T extends PropertyValidators ? ObjectType<T> : undefined;
|
|
15
|
+
export declare class Migrations<DataModel extends GenericDataModel> {
|
|
16
|
+
component: ComponentApi;
|
|
17
|
+
options?: {
|
|
18
|
+
/**
|
|
19
|
+
* Uses the internal mutation to run the migration.
|
|
20
|
+
* This also provides the types for your tables.
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { internalMutation } from "./_generated/server.js";
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
internalMutation?: MutationBuilder<DataModel, "internal">;
|
|
26
|
+
/**
|
|
27
|
+
* How many documents to process in a batch.
|
|
28
|
+
* Your migrateOne function will be called for each document in a batch in
|
|
29
|
+
* a single transaction.
|
|
30
|
+
*/
|
|
31
|
+
defaultBatchSize?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Prefix to add to the function name when running migrations.
|
|
34
|
+
* For example, if you have a function named "foo" in a file
|
|
35
|
+
* "convex/bar/baz.ts", you can set {migrationsLocationPrefix: "bar/baz:"}
|
|
36
|
+
* and then run:
|
|
37
|
+
* ```sh
|
|
38
|
+
* npx convex run migrations:run '{"fn": "foo"}'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
migrationsLocationPrefix?: string;
|
|
42
|
+
} | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Makes the migration wrapper, with types for your own tables.
|
|
45
|
+
*
|
|
46
|
+
* It will keep track of migration state.
|
|
47
|
+
* Add in convex/migrations.ts for example:
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { Migrations } from "@convex-dev/migrations";
|
|
50
|
+
* import { components } from "./_generated/api.js";
|
|
51
|
+
* import { internalMutation } from "./_generated/server";
|
|
52
|
+
*
|
|
53
|
+
* export const migrations = new Migrations(components.migrations, { internalMutation });
|
|
54
|
+
* // the private mutation to run migrations.
|
|
55
|
+
* export const run = migrations.runner();
|
|
56
|
+
*
|
|
57
|
+
* export const myMigration = migrations.define({
|
|
58
|
+
* table: "users",
|
|
59
|
+
* migrateOne: async (ctx, doc) => {
|
|
60
|
+
* await ctx.db.patch(doc._id, { someField: "value" });
|
|
61
|
+
* }
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
* You can then run it from the CLI or dashboard:
|
|
65
|
+
* ```sh
|
|
66
|
+
* npx convex run migrations:run '{"fn": "migrations:myMigration"}'
|
|
67
|
+
* ```
|
|
68
|
+
* For starting a migration from code, see {@link runOne}/{@link runSerially}.
|
|
69
|
+
* @param component - The migrations component. It will be on components.migrations
|
|
70
|
+
* after being configured in in convex.config.js.
|
|
71
|
+
* @param options - Configure options and set the internalMutation to use.
|
|
72
|
+
*/
|
|
73
|
+
constructor(component: ComponentApi, options?: {
|
|
74
|
+
/**
|
|
75
|
+
* Uses the internal mutation to run the migration.
|
|
76
|
+
* This also provides the types for your tables.
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { internalMutation } from "./_generated/server.js";
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
internalMutation?: MutationBuilder<DataModel, "internal">;
|
|
82
|
+
/**
|
|
83
|
+
* How many documents to process in a batch.
|
|
84
|
+
* Your migrateOne function will be called for each document in a batch in
|
|
85
|
+
* a single transaction.
|
|
86
|
+
*/
|
|
87
|
+
defaultBatchSize?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Prefix to add to the function name when running migrations.
|
|
90
|
+
* For example, if you have a function named "foo" in a file
|
|
91
|
+
* "convex/bar/baz.ts", you can set {migrationsLocationPrefix: "bar/baz:"}
|
|
92
|
+
* and then run:
|
|
93
|
+
* ```sh
|
|
94
|
+
* npx convex run migrations:run '{"fn": "foo"}'
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
migrationsLocationPrefix?: string;
|
|
98
|
+
} | undefined);
|
|
99
|
+
/**
|
|
100
|
+
* Creates a migration runner that can be called from the CLI or dashboard.
|
|
101
|
+
*
|
|
102
|
+
* For starting a migration from code, see {@link runOne}/{@link runSerially}.
|
|
103
|
+
*
|
|
104
|
+
* It can be created for a specific migration:
|
|
105
|
+
* ```ts
|
|
106
|
+
* export const runMyMigration = runner(internal.migrations.myMigration);
|
|
107
|
+
* ```
|
|
108
|
+
* CLI: `npx convex run migrations:runMyMigration`
|
|
109
|
+
*
|
|
110
|
+
* Or for any migration:
|
|
111
|
+
* ```ts
|
|
112
|
+
* export const run = runner();
|
|
113
|
+
* ```
|
|
114
|
+
* CLI: `npx convex run migrations:run '{"fn": "migrations:myMigration"}'`
|
|
115
|
+
*
|
|
116
|
+
* Where `myMigration` is the name of the migration function, defined in
|
|
117
|
+
* "convex/migrations.ts" along with the run function.
|
|
118
|
+
*
|
|
119
|
+
* @param specificMigration If you want a migration runner for one migration,
|
|
120
|
+
* pass in the migration function reference like `internal.migrations.foo`.
|
|
121
|
+
* Otherwise it will be a generic runner that requires the migration name.
|
|
122
|
+
* @returns An internal mutation,
|
|
123
|
+
*/
|
|
124
|
+
runner(specificMigrationOrSeries?: MigrationFunctionReference | MigrationFunctionReference[]): RegisteredMutation<"internal", {
|
|
125
|
+
args?: any;
|
|
126
|
+
fn?: string | undefined;
|
|
127
|
+
cursor?: string | null | undefined;
|
|
128
|
+
batchSize?: number | undefined;
|
|
129
|
+
dryRun?: boolean | undefined;
|
|
130
|
+
next?: string[] | undefined;
|
|
131
|
+
}, Promise<Record<string, unknown>>>;
|
|
132
|
+
private _runInteractive;
|
|
133
|
+
/**
|
|
134
|
+
* Use this to wrap a mutation that will be run over all documents in a table.
|
|
135
|
+
* Your mutation only needs to handle changing one document at a time,
|
|
136
|
+
* passed into migrateOne.
|
|
137
|
+
* Optionally specify a custom batch size to override the default (100).
|
|
138
|
+
*
|
|
139
|
+
* In convex/migrations.ts for example:
|
|
140
|
+
* ```ts
|
|
141
|
+
* export const foo = migrations.define({
|
|
142
|
+
* table: "users",
|
|
143
|
+
* migrateOne: async (ctx, doc) => {
|
|
144
|
+
* await ctx.db.patch(doc._id, { someField: "value" });
|
|
145
|
+
* },
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* You can run this manually from the CLI or dashboard:
|
|
150
|
+
* ```sh
|
|
151
|
+
* # Start or resume a migration. No-ops if it's already done:
|
|
152
|
+
* npx convex run migrations:run '{"fn": "migrations:foo"}'
|
|
153
|
+
*
|
|
154
|
+
* # Restart a migration from a cursor (null is from the beginning):
|
|
155
|
+
* npx convex run migrations:run '{"fn": "migrations:foo", "cursor": null }'
|
|
156
|
+
*
|
|
157
|
+
* # Dry run - runs one batch but doesn't schedule or commit changes.
|
|
158
|
+
* # so you can see what it would do without committing the transaction.
|
|
159
|
+
* npx convex run migrations:run '{"fn": "migrations:foo", "dryRun": true}'
|
|
160
|
+
* # or
|
|
161
|
+
* npx convex run migrations:myMigration '{"dryRun": true}'
|
|
162
|
+
*
|
|
163
|
+
* # Run many migrations serially:
|
|
164
|
+
* npx convex run migrations:run '{"fn": "migrations:foo", "next": ["migrations:bar", "migrations:baz"] }'
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* The fn is the string form of the function reference. See:
|
|
168
|
+
* https://docs.convex.dev/functions/query-functions#query-names
|
|
169
|
+
*
|
|
170
|
+
* See {@link runOne} and {@link runSerially} for programmatic use.
|
|
171
|
+
*
|
|
172
|
+
* @param table - The table to run the migration over.
|
|
173
|
+
* @param migrateOne - The function to run on each document.
|
|
174
|
+
* @param batchSize - The number of documents to process in a batch.
|
|
175
|
+
* If not set, defaults to the value passed to makeMigration,
|
|
176
|
+
* or {@link DEFAULT_BATCH_SIZE}. Overriden by arg at runtime if supplied.
|
|
177
|
+
* @param parallelize - If true, each migration batch will be run in parallel.
|
|
178
|
+
* @returns An internal mutation that runs the migration.
|
|
179
|
+
*/
|
|
180
|
+
define<TableName extends TableNamesInDataModel<DataModel>, ArgsValidator extends GenericValidator | PropertyValidators | void = void>({ table, migrateOne, customRange, batchSize: functionDefaultBatchSize, parallelize, args: defineArgs, }: {
|
|
181
|
+
table: TableName;
|
|
182
|
+
migrateOne: (ctx: GenericMutationCtx<DataModel>, doc: DocumentByName<DataModel, TableName> & {
|
|
183
|
+
_id: GenericId<TableName>;
|
|
184
|
+
}, args: InferMigrationArgs<ArgsValidator>) => void | Partial<DocumentByName<DataModel, TableName>> | Promise<Partial<DocumentByName<DataModel, TableName>> | void>;
|
|
185
|
+
customRange?: (q: QueryInitializer<NamedTableInfo<DataModel, TableName>>, args: InferMigrationArgs<ArgsValidator>) => OrderedQuery<NamedTableInfo<DataModel, TableName>>;
|
|
186
|
+
batchSize?: number;
|
|
187
|
+
parallelize?: boolean;
|
|
188
|
+
args?: ArgsValidator;
|
|
189
|
+
}): RegisteredMutation<"internal", {
|
|
190
|
+
args?: any;
|
|
191
|
+
fn?: string | undefined;
|
|
192
|
+
cursor?: string | null | undefined;
|
|
193
|
+
batchSize?: number | undefined;
|
|
194
|
+
dryRun?: boolean | undefined;
|
|
195
|
+
next?: string[] | undefined;
|
|
196
|
+
}, Promise<any>>;
|
|
197
|
+
/**
|
|
198
|
+
* Start a migration from a server function via a function reference.
|
|
199
|
+
*
|
|
200
|
+
* ```ts
|
|
201
|
+
* const migrations = new Migrations(components.migrations, { internalMutation });
|
|
202
|
+
*
|
|
203
|
+
* // in a mutation or action:
|
|
204
|
+
* await migrations.runOne(ctx, internal.migrations.myMigration, {
|
|
205
|
+
* cursor: null, // optional override
|
|
206
|
+
* batchSize: 10, // optional override
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* Overrides any options you passed in, such as resetting the cursor.
|
|
211
|
+
* If it's already in progress, it will no-op.
|
|
212
|
+
* If you run a migration that had previously failed which was part of a series,
|
|
213
|
+
* it will not resume the series.
|
|
214
|
+
* To resume a series, call the series again: {@link Migrations.runSerially}.
|
|
215
|
+
*
|
|
216
|
+
* Note: It's up to you to determine if it's safe to run a migration while
|
|
217
|
+
* others are in progress. It won't run multiple instance of the same migration
|
|
218
|
+
* but it currently allows running multiple migrations on the same table.
|
|
219
|
+
*
|
|
220
|
+
* @param ctx Context from a mutation or action. Needs `runMutation`.
|
|
221
|
+
* @param fnRef The migration function to run. Like `internal.migrations.foo`.
|
|
222
|
+
* @param opts Options to start the migration.
|
|
223
|
+
* @param opts.cursor The cursor to start from.
|
|
224
|
+
* null: start from the beginning.
|
|
225
|
+
* undefined: start or resume from where it failed. If done, it won't restart.
|
|
226
|
+
* @param opts.batchSize The number of documents to process in a batch.
|
|
227
|
+
* @param opts.dryRun If true, it will run a batch and then throw an error.
|
|
228
|
+
* It's helpful to see what it would do without committing the transaction.
|
|
229
|
+
*/
|
|
230
|
+
runOne(ctx: MutationCtx | ActionCtx, fnRef: MigrationFunctionReference, opts?: {
|
|
231
|
+
cursor?: string | null;
|
|
232
|
+
batchSize?: number;
|
|
233
|
+
dryRun?: boolean;
|
|
234
|
+
args?: any;
|
|
235
|
+
}): Promise<{
|
|
236
|
+
batchSize?: number;
|
|
237
|
+
cursor?: string | null;
|
|
238
|
+
error?: string;
|
|
239
|
+
isDone: boolean;
|
|
240
|
+
latestEnd?: number;
|
|
241
|
+
latestStart: number;
|
|
242
|
+
name: string;
|
|
243
|
+
next?: Array<string>;
|
|
244
|
+
processed: number;
|
|
245
|
+
state: "inProgress" | "success" | "failed" | "canceled" | "unknown";
|
|
246
|
+
}>;
|
|
247
|
+
/**
|
|
248
|
+
* Start a series of migrations, running one a time. Each call starts a series.
|
|
249
|
+
*
|
|
250
|
+
* ```ts
|
|
251
|
+
* const migrations = new Migrations(components.migrations, { internalMutation });
|
|
252
|
+
*
|
|
253
|
+
* // in a mutation or action:
|
|
254
|
+
* await migrations.runSerially(ctx, [
|
|
255
|
+
* internal.migrations.myMigration,
|
|
256
|
+
* internal.migrations.myOtherMigration,
|
|
257
|
+
* ]);
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* It runs one batch at a time currently.
|
|
261
|
+
* If a migration has previously completed it will skip it.
|
|
262
|
+
* If a migration had partial progress, it will resume from where it left off.
|
|
263
|
+
* If a migration is already in progress when attempted, it will no-op.
|
|
264
|
+
* If a migration fails or is canceled, it will stop executing and NOT execute
|
|
265
|
+
* any subsequent migrations in the series. Call the series again to retry.
|
|
266
|
+
*
|
|
267
|
+
* This is useful to run as an post-deploy script where you specify all the
|
|
268
|
+
* live migrations that should be run.
|
|
269
|
+
*
|
|
270
|
+
* Note: if you start multiple serial migrations, the behavior is:
|
|
271
|
+
* - If they don't overlap on functions, they will happily run in parallel.
|
|
272
|
+
* - If they have a function in common and one completes before the other
|
|
273
|
+
* attempts it, the second will just skip it.
|
|
274
|
+
* - If they have a function in common and one is in progress, the second will
|
|
275
|
+
* no-op and not run any further migrations in its series.
|
|
276
|
+
*
|
|
277
|
+
* To stop a migration in progress, see {@link cancelMigration}.
|
|
278
|
+
*
|
|
279
|
+
* @param ctx Context from a mutation or action. Needs `runMutation`.
|
|
280
|
+
* @param fnRefs The migrations to run in order. Like [internal.migrations.foo].
|
|
281
|
+
*/
|
|
282
|
+
runSerially(ctx: MutationCtx | ActionCtx, fnRefs: MigrationFunctionReference[]): Promise<{
|
|
283
|
+
batchSize?: number;
|
|
284
|
+
cursor?: string | null;
|
|
285
|
+
error?: string;
|
|
286
|
+
isDone: boolean;
|
|
287
|
+
latestEnd?: number;
|
|
288
|
+
latestStart: number;
|
|
289
|
+
name: string;
|
|
290
|
+
next?: Array<string>;
|
|
291
|
+
processed: number;
|
|
292
|
+
state: "inProgress" | "success" | "failed" | "canceled" | "unknown";
|
|
293
|
+
} | undefined>;
|
|
294
|
+
/**
|
|
295
|
+
* Get the status of a migration or all migrations.
|
|
296
|
+
* @param ctx Context from a query, mutation or action. Needs `runQuery`.
|
|
297
|
+
* @param migrations The migrations to get the status of. Defaults to all.
|
|
298
|
+
* @param limit How many migrations to fetch, if not specified by name.
|
|
299
|
+
* @returns The status of the migrations, in the order of the input.
|
|
300
|
+
*/
|
|
301
|
+
getStatus(ctx: QueryCtx | MutationCtx | ActionCtx, { migrations, limit, }: {
|
|
302
|
+
migrations?: (string | MigrationFunctionReference)[];
|
|
303
|
+
limit?: number;
|
|
304
|
+
}): Promise<MigrationStatus[]>;
|
|
305
|
+
/**
|
|
306
|
+
* Cancels a migration if it's in progress.
|
|
307
|
+
* You can resume it later by calling the migration without an explicit cursor.
|
|
308
|
+
* If the migration had "next" migrations, e.g. from {@link runSerially},
|
|
309
|
+
* they will not run. To resume, call the series again or manually pass "next".
|
|
310
|
+
* @param ctx Context from a mutation or action. Needs `runMutation`.
|
|
311
|
+
* @param migration Migration to cancel. Either the name like "migrations:foo"
|
|
312
|
+
* or the function reference like `internal.migrations.foo`.
|
|
313
|
+
* @returns The status of the migration after attempting to cancel it.
|
|
314
|
+
*/
|
|
315
|
+
cancel(ctx: MutationCtx | ActionCtx, migration: MigrationFunctionReference | string): Promise<MigrationStatus>;
|
|
316
|
+
/**
|
|
317
|
+
* Cancels all migrations that are in progress.
|
|
318
|
+
* You can resume it later by calling the migration without an explicit cursor.
|
|
319
|
+
* If the migration had "next" migrations, e.g. from {@link runSerially},
|
|
320
|
+
* they will not run. To resume, call the series again or manually pass "next".
|
|
321
|
+
* @param ctx Context from a mutation or action. Needs `runMutation`.
|
|
322
|
+
* @returns The status of up to 100 of the canceled migrations.
|
|
323
|
+
*/
|
|
324
|
+
cancelAll(ctx: MutationCtx | ActionCtx): Promise<{
|
|
325
|
+
batchSize?: number;
|
|
326
|
+
cursor?: string | null;
|
|
327
|
+
error?: string;
|
|
328
|
+
isDone: boolean;
|
|
329
|
+
latestEnd?: number;
|
|
330
|
+
latestStart: number;
|
|
331
|
+
name: string;
|
|
332
|
+
next?: Array<string>;
|
|
333
|
+
processed: number;
|
|
334
|
+
state: "inProgress" | "success" | "failed" | "canceled" | "unknown";
|
|
335
|
+
}[]>;
|
|
336
|
+
private prefixedName;
|
|
337
|
+
}
|
|
338
|
+
export type MigrationFunctionReference = FunctionReference<"mutation", "internal", MigrationArgs>;
|
|
339
|
+
/**
|
|
340
|
+
* Start a migration and run it synchronously until it's done.
|
|
341
|
+
* If this function crashes, the migration will not continue.
|
|
342
|
+
*
|
|
343
|
+
* ```ts
|
|
344
|
+
* // In an action
|
|
345
|
+
* const toRun = internal.migrations.myMigration;
|
|
346
|
+
* await runToCompletion(ctx, components.migrations, toRun);
|
|
347
|
+
* ```
|
|
348
|
+
*
|
|
349
|
+
* If it's already in progress, it will no-op.
|
|
350
|
+
* If you run a migration that had previously failed which was part of a series,
|
|
351
|
+
* it will not resume the series.
|
|
352
|
+
* To resume a series, call the series again: {@link Migrations.runSerially}.
|
|
353
|
+
*
|
|
354
|
+
* Note: It's up to you to determine if it's safe to run a migration while
|
|
355
|
+
* others are in progress. It won't run multiple instances of the same migration
|
|
356
|
+
* but it currently allows running multiple migrations on the same table.
|
|
357
|
+
*
|
|
358
|
+
* @param ctx Context from an action.
|
|
359
|
+
* @param component The migrations component, usually `components.migrations`.
|
|
360
|
+
* @param fnRef The migration function to run. Like `internal.migrations.foo`.
|
|
361
|
+
* @param opts Options to start the migration.
|
|
362
|
+
* It's helpful to see what it would do without committing the transaction.
|
|
363
|
+
*/
|
|
364
|
+
export declare function runToCompletion(ctx: ActionCtx, component: ComponentApi, fnRef: MigrationFunctionReference | MigrationFunctionHandle, opts?: {
|
|
365
|
+
/**
|
|
366
|
+
* The name of the migration function, generated with getFunctionName.
|
|
367
|
+
*/
|
|
368
|
+
name?: string;
|
|
369
|
+
/**
|
|
370
|
+
* The cursor to start from.
|
|
371
|
+
* null: start from the beginning.
|
|
372
|
+
* undefined: start, or resume from where it failed. No-ops if already done.
|
|
373
|
+
*/
|
|
374
|
+
cursor?: string | null;
|
|
375
|
+
/**
|
|
376
|
+
* The number of documents to process in a batch.
|
|
377
|
+
* Overrides the migrations's configured batch size.
|
|
378
|
+
*/
|
|
379
|
+
batchSize?: number;
|
|
380
|
+
/**
|
|
381
|
+
* If true, it will run a batch and then throw an error.
|
|
382
|
+
* It's helpful to see what it would do without committing the transaction.
|
|
383
|
+
*/
|
|
384
|
+
dryRun?: boolean;
|
|
385
|
+
args?: any;
|
|
386
|
+
}): Promise<MigrationStatus>;
|
|
387
|
+
type QueryCtx = Pick<GenericQueryCtx<GenericDataModel>, "runQuery">;
|
|
388
|
+
type MutationCtx = Pick<GenericMutationCtx<GenericDataModel>, "runQuery" | "runMutation">;
|
|
389
|
+
type ActionCtx = Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation" | "storage">;
|
|
390
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EAKpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,eAAe,EACpB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC;AAEhE,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,SAAS,EAEf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAGnE,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC;;;;;GAKG;AACH,KAAK,kBAAkB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAC3D,KAAK,CAAC,CAAC,CAAC,GACR,CAAC,SAAS,kBAAkB,GAC1B,UAAU,CAAC,CAAC,CAAC,GACb,SAAS,CAAC;AAYhB,qBAAa,UAAU,CAAC,SAAS,SAAS,gBAAgB;IAgC/C,SAAS,EAAE,YAAY;IACvB,OAAO,CAAC,EAAE;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