MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / migrateTo

Function migrateTo

packages/core/fumadb/src/migration-engine/create.ts:217–305  ·  view source on GitHub ↗
(version, options = {})

Source from the content-addressed store, hash-verified

215 return this.migrateTo(prev.version, options);
216 },
217 async migrateTo(version, options = {}) {
218 const {
219 updateSettings: updateVersion = true,
220 unsafe = false,
221 mode = "from-schema",
222 } = options;
223 const targetSchema = getSchemaByVersion(version);
224 const currentSchema = await getCurrentSchema();
225
226 let run:
227 | ((context: MigrationContext) => Awaitable<MigrationOperation[]>)
228 | undefined;
229
230 // same variant
231 const prevVariant = parse(targetSchema.version)!.prerelease;
232 const variant = parse(currentSchema.version)!.prerelease;
233
234 if (deepEqual(prevVariant, variant)) {
235 const list = getSchemasOfVariant(variant);
236 const targetIdx = list.indexOf(targetSchema);
237
238 switch (currentSchema.version) {
239 case list[targetIdx - 1]?.version:
240 run = targetSchema.up;
241 break;
242 case list[targetIdx + 1]?.version:
243 run = targetSchema.down;
244 break;
245 }
246 }
247
248 run ??= (context) => context.auto();
249
250 const context: MigrationContext = {
251 async auto() {
252 let generated: MigrationOperation[];
253
254 if (mode === "from-schema") {
255 generated = generateMigrationFromSchema(
256 currentSchema,
257 targetSchema,
258 userConfig
259 );
260 } else {
261 if (!generateMigrationFromDatabase)
262 throw new Error(`${mode} is not supported for this adapter.`);
263
264 generated = await generateMigrationFromDatabase({
265 target: targetSchema,
266 dropUnusedColumns: unsafe,
267 });
268 }
269
270 for (const transformer of transformers) {
271 if (!transformer.afterAuto) continue;
272
273 generated = transformer.afterAuto(generated, {
274 prev: currentSchema,

Callers

nothing calls this directly

Calls 7

deepEqualFunction · 0.90
getSchemaByVersionFunction · 0.85
getCurrentSchemaFunction · 0.85
getSchemasOfVariantFunction · 0.85
pushMethod · 0.80
runFunction · 0.50
executorFunction · 0.50

Tested by

no test coverage detected