arkormx 0.2.5 → 0.2.7

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/dist/index.cjs CHANGED
@@ -26,15 +26,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  }) : target, mod));
27
27
 
28
28
  //#endregion
29
- let fs = require("fs");
30
- let path = require("path");
31
- path = __toESM(path);
32
- let module$1 = require("module");
33
29
  let node_fs = require("node:fs");
34
30
  let node_path = require("node:path");
35
31
  let node_child_process = require("node:child_process");
36
32
  let _h3ravel_support = require("@h3ravel/support");
33
+ let path = require("path");
34
+ path = __toESM(path);
35
+ let fs = require("fs");
37
36
  let url = require("url");
37
+ let module$1 = require("module");
38
38
  let _h3ravel_shared = require("@h3ravel/shared");
39
39
  let _h3ravel_musket = require("@h3ravel/musket");
40
40
  let node_crypto = require("node:crypto");
@@ -1152,6 +1152,26 @@ const applyMigrationToPrismaSchema = async (migration, options = {}) => {
1152
1152
  };
1153
1153
  };
1154
1154
  /**
1155
+ * Apply the rollback (down) operations defined in a migration to a Prisma schema file.
1156
+ *
1157
+ * @param migration The migration class or instance to rollback.
1158
+ * @param options Options for applying the rollback, including schema path and write flag.
1159
+ * @returns A promise that resolves to an object containing the updated schema, schema path, and rollback operations applied.
1160
+ */
1161
+ const applyMigrationRollbackToPrismaSchema = async (migration, options = {}) => {
1162
+ const schemaPath = options.schemaPath ?? (0, node_path.join)(process.cwd(), "prisma", "schema.prisma");
1163
+ if (!(0, node_fs.existsSync)(schemaPath)) throw new ArkormException(`Prisma schema file not found: ${schemaPath}`);
1164
+ const source = (0, node_fs.readFileSync)(schemaPath, "utf-8");
1165
+ const operations = await getMigrationPlan(migration, "down");
1166
+ const schema = applyOperationsToPrismaSchema(source, operations);
1167
+ if (options.write ?? true) (0, node_fs.writeFileSync)(schemaPath, schema);
1168
+ return {
1169
+ schema,
1170
+ schemaPath,
1171
+ operations
1172
+ };
1173
+ };
1174
+ /**
1155
1175
  * Run a migration by applying its schema operations to a Prisma schema
1156
1176
  * file, optionally generating Prisma client code and running migrations after
1157
1177
  * applying the schema changes.
@@ -1702,7 +1722,9 @@ var CliApp = class {
1702
1722
  name: "id",
1703
1723
  type: "id",
1704
1724
  primary: true
1705
- }]
1725
+ }],
1726
+ indexes: [],
1727
+ foreignKeys: []
1706
1728
  }));
1707
1729
  return {
1708
1730
  path: schemaPath,
@@ -1754,14 +1776,14 @@ var CliApp = class {
1754
1776
  body.split("\n").forEach((rawLine) => {
1755
1777
  const line = rawLine.trim();
1756
1778
  if (!line || line.startsWith("@@") || line.startsWith("//")) return;
1757
- const fieldMatch = line.match(/^(\w+)\s+([A-Za-z]+)(\?)?\b/);
1779
+ const fieldMatch = line.match(/^(\w+)\s+([A-Za-z]+)(\?)?(?:\s|$)/);
1758
1780
  if (!fieldMatch) return;
1759
1781
  const fieldType = fieldMatch[2];
1760
1782
  if (!scalarTypes.has(fieldType)) return;
1761
1783
  fields.push({
1762
1784
  name: fieldMatch[1],
1763
1785
  type: this.prismaTypeToTs(fieldType),
1764
- optional: Boolean(fieldMatch[3])
1786
+ nullable: Boolean(fieldMatch[3])
1765
1787
  });
1766
1788
  });
1767
1789
  models.push({
@@ -1852,7 +1874,7 @@ var CliApp = class {
1852
1874
  skipped.push(filePath);
1853
1875
  return;
1854
1876
  }
1855
- const declarations = prismaModel.fields.map((field) => `declare ${field.name}${field.optional ? "?" : ""}: ${field.type}`);
1877
+ const declarations = prismaModel.fields.map((field) => `declare ${field.name}: ${field.type}${field.nullable ? " | null" : ""}`);
1856
1878
  const synced = this.syncModelDeclarations(source, declarations);
1857
1879
  if (!synced.updated) {
1858
1880
  skipped.push(filePath);
@@ -2036,7 +2058,8 @@ var MakeSeederCommand = class extends _h3ravel_musket.Command {
2036
2058
  //#region src/helpers/migration-history.ts
2037
2059
  const DEFAULT_STATE = {
2038
2060
  version: 1,
2039
- migrations: []
2061
+ migrations: [],
2062
+ runs: []
2040
2063
  };
2041
2064
  const resolveMigrationStateFilePath = (cwd, configuredPath) => {
2042
2065
  if (configuredPath && configuredPath.trim().length > 0) return (0, node_path.resolve)(configuredPath);
@@ -2059,7 +2082,10 @@ const readAppliedMigrationsState = (stateFilePath) => {
2059
2082
  version: 1,
2060
2083
  migrations: parsed.migrations.filter((migration) => {
2061
2084
  return typeof migration?.id === "string" && typeof migration?.file === "string" && typeof migration?.className === "string" && typeof migration?.appliedAt === "string" && (migration?.checksum === void 0 || typeof migration?.checksum === "string");
2062
- })
2085
+ }),
2086
+ runs: Array.isArray(parsed.runs) ? parsed.runs.filter((run) => {
2087
+ return typeof run?.id === "string" && typeof run?.appliedAt === "string" && Array.isArray(run?.migrationIds) && run.migrationIds.every((item) => typeof item === "string");
2088
+ }) : []
2063
2089
  };
2064
2090
  } catch {
2065
2091
  return { ...DEFAULT_STATE };
@@ -2085,9 +2111,40 @@ const markMigrationApplied = (state, entry) => {
2085
2111
  next.push(entry);
2086
2112
  return {
2087
2113
  version: 1,
2088
- migrations: next
2114
+ migrations: next,
2115
+ runs: state.runs ?? []
2089
2116
  };
2090
2117
  };
2118
+ const removeAppliedMigration = (state, identity) => {
2119
+ return {
2120
+ version: 1,
2121
+ migrations: state.migrations.filter((migration) => migration.id !== identity),
2122
+ runs: (state.runs ?? []).map((run) => ({
2123
+ ...run,
2124
+ migrationIds: run.migrationIds.filter((id) => id !== identity)
2125
+ })).filter((run) => run.migrationIds.length > 0)
2126
+ };
2127
+ };
2128
+ const buildMigrationRunId = () => {
2129
+ return `run_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
2130
+ };
2131
+ const markMigrationRun = (state, run) => {
2132
+ const nextRuns = (state.runs ?? []).filter((existing) => existing.id !== run.id);
2133
+ nextRuns.push(run);
2134
+ return {
2135
+ version: 1,
2136
+ migrations: state.migrations,
2137
+ runs: nextRuns
2138
+ };
2139
+ };
2140
+ const getLastMigrationRun = (state) => {
2141
+ const runs = state.runs ?? [];
2142
+ if (runs.length === 0) return void 0;
2143
+ return [...runs].sort((left, right) => right.appliedAt.localeCompare(left.appliedAt))[0];
2144
+ };
2145
+ const getLatestAppliedMigrations = (state, steps) => {
2146
+ return [...state.migrations].sort((left, right) => right.appliedAt.localeCompare(left.appliedAt)).slice(0, Math.max(0, steps));
2147
+ };
2091
2148
 
2092
2149
  //#endregion
2093
2150
  //#region src/database/Migration.ts
@@ -2142,9 +2199,8 @@ var MigrateCommand = class extends _h3ravel_musket.Command {
2142
2199
  const schemaPath = this.option("schema") ? (0, node_path.resolve)(String(this.option("schema"))) : (0, node_path.join)(process.cwd(), "prisma", "schema.prisma");
2143
2200
  const classes = this.option("all") || !this.argument("name") ? await this.loadAllMigrations(migrationsDir) : (await this.loadNamedMigration(migrationsDir, this.argument("name"))).filter(([cls]) => cls !== void 0);
2144
2201
  if (classes.length === 0) return void this.error("Error: No migration classes found to run.");
2145
- const shouldTrackApplied = Boolean(this.option("all") || !this.argument("name") || this.option("state-file"));
2146
2202
  const stateFilePath = resolveMigrationStateFilePath(process.cwd(), this.option("state-file") ? String(this.option("state-file")) : void 0);
2147
- let appliedState = shouldTrackApplied ? readAppliedMigrationsState(stateFilePath) : void 0;
2203
+ let appliedState = readAppliedMigrationsState(stateFilePath);
2148
2204
  const skipped = [];
2149
2205
  const changed = [];
2150
2206
  const pending = classes.filter(([migrationClass, file]) => {
@@ -2171,6 +2227,7 @@ var MigrateCommand = class extends _h3ravel_musket.Command {
2171
2227
  write: true
2172
2228
  });
2173
2229
  if (appliedState) {
2230
+ const runAppliedIds = [];
2174
2231
  for (const [migrationClass, file] of pending) {
2175
2232
  const identity = buildMigrationIdentity(file, migrationClass.name);
2176
2233
  appliedState = markMigrationApplied(appliedState, {
@@ -2180,7 +2237,13 @@ var MigrateCommand = class extends _h3ravel_musket.Command {
2180
2237
  appliedAt: (/* @__PURE__ */ new Date()).toISOString(),
2181
2238
  checksum: computeMigrationChecksum(file)
2182
2239
  });
2240
+ runAppliedIds.push(identity);
2183
2241
  }
2242
+ appliedState = markMigrationRun(appliedState, {
2243
+ id: buildMigrationRunId(),
2244
+ appliedAt: (/* @__PURE__ */ new Date()).toISOString(),
2245
+ migrationIds: runAppliedIds
2246
+ });
2184
2247
  writeAppliedMigrationsState(stateFilePath, appliedState);
2185
2248
  }
2186
2249
  if (!this.option("skip-generate")) runPrismaCommand(["generate"], process.cwd());
@@ -2244,6 +2307,91 @@ var MigrateCommand = class extends _h3ravel_musket.Command {
2244
2307
  }
2245
2308
  };
2246
2309
 
2310
+ //#endregion
2311
+ //#region src/cli/commands/MigrateRollbackCommand.ts
2312
+ /**
2313
+ * Rollback migration classes from the Prisma schema and run Prisma workflow.
2314
+ * By default, rolls back classes applied in the last migrate run.
2315
+ *
2316
+ * @author Legacy (3m1n3nc3)
2317
+ * @since 0.2.4
2318
+ */
2319
+ var MigrateRollbackCommand = class extends _h3ravel_musket.Command {
2320
+ signature = `migrate:rollback
2321
+ {--step= : Number of latest applied migration classes to rollback}
2322
+ {--dry-run : Preview rollback targets without applying changes}
2323
+ {--deploy : Use prisma migrate deploy instead of migrate dev}
2324
+ {--skip-generate : Skip prisma generate}
2325
+ {--skip-migrate : Skip prisma migrate command}
2326
+ {--state-file= : Path to applied migration state file}
2327
+ {--schema= : Explicit prisma schema path}
2328
+ {--migration-name= : Name for prisma migrate dev}
2329
+ `;
2330
+ description = "Rollback migration classes from schema.prisma and run Prisma workflow";
2331
+ async handle() {
2332
+ this.app.command = this;
2333
+ const configuredMigrationsDir = this.app.getConfig("paths")?.migrations ?? (0, node_path.join)(process.cwd(), "database", "migrations");
2334
+ const migrationsDir = this.app.resolveRuntimeDirectoryPath(configuredMigrationsDir);
2335
+ if (!(0, node_fs.existsSync)(migrationsDir)) return void this.error(`Error: Migrations directory not found: ${this.app.formatPathForLog(configuredMigrationsDir)}`);
2336
+ const schemaPath = this.option("schema") ? (0, node_path.resolve)(String(this.option("schema"))) : (0, node_path.join)(process.cwd(), "prisma", "schema.prisma");
2337
+ const stateFilePath = resolveMigrationStateFilePath(process.cwd(), this.option("state-file") ? String(this.option("state-file")) : void 0);
2338
+ let appliedState = readAppliedMigrationsState(stateFilePath);
2339
+ const stepOption = this.option("step");
2340
+ const stepCount = stepOption == null ? void 0 : Number(stepOption);
2341
+ if (stepCount != null && (!Number.isFinite(stepCount) || stepCount <= 0 || !Number.isInteger(stepCount))) return void this.error("Error: --step must be a positive integer.");
2342
+ const targets = stepCount ? getLatestAppliedMigrations(appliedState, stepCount) : (() => {
2343
+ const lastRun = getLastMigrationRun(appliedState);
2344
+ if (!lastRun) return [];
2345
+ return lastRun.migrationIds.map((id) => appliedState.migrations.find((migration) => migration.id === id)).filter((migration) => Boolean(migration));
2346
+ })();
2347
+ if (targets.length === 0) return void this.error("Error: No tracked migrations available to rollback.");
2348
+ const available = await this.loadAllMigrations(migrationsDir);
2349
+ const rollbackClasses = targets.map((target) => {
2350
+ return available.find(([migrationClass, file]) => {
2351
+ return buildMigrationIdentity(file, migrationClass.name) === target.id || migrationClass.name === target.className;
2352
+ });
2353
+ }).filter((entry) => Boolean(entry));
2354
+ if (rollbackClasses.length === 0) return void this.error("Error: Unable to resolve rollback migration classes from tracked history.");
2355
+ if (this.option("dry-run")) {
2356
+ this.success(`Dry run: ${rollbackClasses.length} migration(s) would be rolled back.`);
2357
+ rollbackClasses.forEach(([_, file]) => this.success(this.app.splitLogger("WouldRollback", file)));
2358
+ return;
2359
+ }
2360
+ for (const [MigrationClassItem] of rollbackClasses) await applyMigrationRollbackToPrismaSchema(MigrationClassItem, {
2361
+ schemaPath,
2362
+ write: true
2363
+ });
2364
+ for (const [migrationClass, file] of rollbackClasses) {
2365
+ const identity = buildMigrationIdentity(file, migrationClass.name);
2366
+ appliedState = removeAppliedMigration(appliedState, identity);
2367
+ }
2368
+ writeAppliedMigrationsState(stateFilePath, appliedState);
2369
+ if (!this.option("skip-generate")) runPrismaCommand(["generate"], process.cwd());
2370
+ if (!this.option("skip-migrate")) if (this.option("deploy")) runPrismaCommand(["migrate", "deploy"], process.cwd());
2371
+ else runPrismaCommand([
2372
+ "migrate",
2373
+ "dev",
2374
+ "--name",
2375
+ this.option("migration-name") ? String(this.option("migration-name")) : `arkorm_cli_rollback_${Date.now()}`
2376
+ ], process.cwd());
2377
+ this.success(`Rolled back ${rollbackClasses.length} migration(s).`);
2378
+ rollbackClasses.forEach(([_, file]) => this.success(this.app.splitLogger("RolledBack", file)));
2379
+ }
2380
+ async loadAllMigrations(migrationsDir) {
2381
+ const files = (0, node_fs.readdirSync)(migrationsDir).filter((file) => /\.(ts|js|mjs|cjs)$/i.test(file)).sort((left, right) => left.localeCompare(right)).map((file) => this.app.resolveRuntimeScriptPath((0, node_path.join)(migrationsDir, file)));
2382
+ return (await Promise.all(files.map(async (file) => (await this.loadMigrationClassesFromFile(file)).map((cls) => [cls, file])))).flat();
2383
+ }
2384
+ async loadMigrationClassesFromFile(filePath) {
2385
+ const imported = await import(`${(0, node_url.pathToFileURL)((0, node_path.resolve)(filePath)).href}?arkorm_rollback=${Date.now()}`);
2386
+ return Object.values(imported).filter((value) => {
2387
+ if (typeof value !== "function") return false;
2388
+ const candidate = value;
2389
+ const prototype = candidate.prototype;
2390
+ return candidate[MIGRATION_BRAND] === true || typeof prototype?.up === "function" && typeof prototype?.down === "function";
2391
+ });
2392
+ }
2393
+ };
2394
+
2247
2395
  //#endregion
2248
2396
  //#region src/cli/commands/MigrationHistoryCommand.ts
2249
2397
  /**
@@ -2295,7 +2443,7 @@ var MigrationHistoryCommand = class extends _h3ravel_musket.Command {
2295
2443
  return;
2296
2444
  }
2297
2445
  state.migrations.sort((left, right) => left.appliedAt.localeCompare(right.appliedAt)).forEach((migration) => {
2298
- this.success(this.app.splitLogger("Applied", `${migration.id} @ ${migration.appliedAt}`));
2446
+ this.success(this.app.splitLogger("Applied:", `${migration.id} @ ${migration.appliedAt}`));
2299
2447
  });
2300
2448
  }
2301
2449
  };
@@ -5281,6 +5429,7 @@ exports.MakeMigrationCommand = MakeMigrationCommand;
5281
5429
  exports.MakeModelCommand = MakeModelCommand;
5282
5430
  exports.MakeSeederCommand = MakeSeederCommand;
5283
5431
  exports.MigrateCommand = MigrateCommand;
5432
+ exports.MigrateRollbackCommand = MigrateRollbackCommand;
5284
5433
  exports.Migration = Migration;
5285
5434
  exports.MigrationHistoryCommand = MigrationHistoryCommand;
5286
5435
  exports.Model = Model;
@@ -5299,12 +5448,14 @@ exports.URLDriver = URLDriver;
5299
5448
  exports.applyAlterTableOperation = applyAlterTableOperation;
5300
5449
  exports.applyCreateTableOperation = applyCreateTableOperation;
5301
5450
  exports.applyDropTableOperation = applyDropTableOperation;
5451
+ exports.applyMigrationRollbackToPrismaSchema = applyMigrationRollbackToPrismaSchema;
5302
5452
  exports.applyMigrationToPrismaSchema = applyMigrationToPrismaSchema;
5303
5453
  exports.applyOperationsToPrismaSchema = applyOperationsToPrismaSchema;
5304
5454
  exports.buildFieldLine = buildFieldLine;
5305
5455
  exports.buildIndexLine = buildIndexLine;
5306
5456
  exports.buildInverseRelationLine = buildInverseRelationLine;
5307
5457
  exports.buildMigrationIdentity = buildMigrationIdentity;
5458
+ exports.buildMigrationRunId = buildMigrationRunId;
5308
5459
  exports.buildMigrationSource = buildMigrationSource;
5309
5460
  exports.buildModelBlock = buildModelBlock;
5310
5461
  exports.buildRelationLine = buildRelationLine;
@@ -5326,6 +5477,8 @@ exports.formatDefaultValue = formatDefaultValue;
5326
5477
  exports.formatRelationAction = formatRelationAction;
5327
5478
  exports.generateMigrationFile = generateMigrationFile;
5328
5479
  exports.getDefaultStubsPath = getDefaultStubsPath;
5480
+ exports.getLastMigrationRun = getLastMigrationRun;
5481
+ exports.getLatestAppliedMigrations = getLatestAppliedMigrations;
5329
5482
  exports.getMigrationPlan = getMigrationPlan;
5330
5483
  exports.getRuntimePaginationURLDriverFactory = getRuntimePaginationURLDriverFactory;
5331
5484
  exports.getRuntimePrismaClient = getRuntimePrismaClient;
@@ -5335,8 +5488,10 @@ exports.isDelegateLike = isDelegateLike;
5335
5488
  exports.isMigrationApplied = isMigrationApplied;
5336
5489
  exports.loadArkormConfig = loadArkormConfig;
5337
5490
  exports.markMigrationApplied = markMigrationApplied;
5491
+ exports.markMigrationRun = markMigrationRun;
5338
5492
  exports.pad = pad;
5339
5493
  exports.readAppliedMigrationsState = readAppliedMigrationsState;
5494
+ exports.removeAppliedMigration = removeAppliedMigration;
5340
5495
  exports.resetArkormRuntimeForTests = resetArkormRuntimeForTests;
5341
5496
  exports.resolveCast = resolveCast;
5342
5497
  exports.resolveMigrationClassName = resolveMigrationClassName;
package/dist/index.d.cts CHANGED
@@ -86,9 +86,15 @@ interface AppliedMigrationEntry {
86
86
  appliedAt: string;
87
87
  checksum?: string;
88
88
  }
89
+ interface AppliedMigrationRun {
90
+ id: string;
91
+ appliedAt: string;
92
+ migrationIds: string[];
93
+ }
89
94
  interface AppliedMigrationsState {
90
95
  version: 1;
91
96
  migrations: AppliedMigrationEntry[];
97
+ runs?: AppliedMigrationRun[];
92
98
  }
93
99
  //#endregion
94
100
  //#region src/Collection.d.ts
@@ -2262,6 +2268,22 @@ declare class MigrateCommand extends Command<CliApp> {
2262
2268
  private loadMigrationClassesFromFile;
2263
2269
  }
2264
2270
  //#endregion
2271
+ //#region src/cli/commands/MigrateRollbackCommand.d.ts
2272
+ /**
2273
+ * Rollback migration classes from the Prisma schema and run Prisma workflow.
2274
+ * By default, rolls back classes applied in the last migrate run.
2275
+ *
2276
+ * @author Legacy (3m1n3nc3)
2277
+ * @since 0.2.4
2278
+ */
2279
+ declare class MigrateRollbackCommand extends Command<CliApp> {
2280
+ protected signature: string;
2281
+ protected description: string;
2282
+ handle(): Promise<undefined>;
2283
+ private loadAllMigrations;
2284
+ private loadMigrationClassesFromFile;
2285
+ }
2286
+ //#endregion
2265
2287
  //#region src/cli/commands/MigrationHistoryCommand.d.ts
2266
2288
  /**
2267
2289
  * The MigrationHistoryCommand class manages tracked migration run history.
@@ -2764,6 +2786,11 @@ declare const writeAppliedMigrationsState: (stateFilePath: string, state: Applie
2764
2786
  declare const isMigrationApplied: (state: AppliedMigrationsState, identity: string, checksum?: string) => boolean;
2765
2787
  declare const findAppliedMigration: (state: AppliedMigrationsState, identity: string) => AppliedMigrationEntry | undefined;
2766
2788
  declare const markMigrationApplied: (state: AppliedMigrationsState, entry: AppliedMigrationEntry) => AppliedMigrationsState;
2789
+ declare const removeAppliedMigration: (state: AppliedMigrationsState, identity: string) => AppliedMigrationsState;
2790
+ declare const buildMigrationRunId: () => string;
2791
+ declare const markMigrationRun: (state: AppliedMigrationsState, run: AppliedMigrationRun) => AppliedMigrationsState;
2792
+ declare const getLastMigrationRun: (state: AppliedMigrationsState) => AppliedMigrationRun | undefined;
2793
+ declare const getLatestAppliedMigrations: (state: AppliedMigrationsState, steps: number) => AppliedMigrationEntry[];
2767
2794
  //#endregion
2768
2795
  //#region src/helpers/migrations.d.ts
2769
2796
  declare const PRISMA_MODEL_REGEX: RegExp;
@@ -2990,6 +3017,18 @@ declare const applyMigrationToPrismaSchema: (migration: Migration | (new () => M
2990
3017
  schemaPath: string;
2991
3018
  operations: SchemaOperation[];
2992
3019
  }>;
3020
+ /**
3021
+ * Apply the rollback (down) operations defined in a migration to a Prisma schema file.
3022
+ *
3023
+ * @param migration The migration class or instance to rollback.
3024
+ * @param options Options for applying the rollback, including schema path and write flag.
3025
+ * @returns A promise that resolves to an object containing the updated schema, schema path, and rollback operations applied.
3026
+ */
3027
+ declare const applyMigrationRollbackToPrismaSchema: (migration: Migration | (new () => Migration), options?: PrismaSchemaSyncOptions) => Promise<{
3028
+ schema: string;
3029
+ schemaPath: string;
3030
+ operations: SchemaOperation[];
3031
+ }>;
2993
3032
  /**
2994
3033
  * Run a migration by applying its schema operations to a Prisma schema
2995
3034
  * file, optionally generating Prisma client code and running migrations after
@@ -3114,4 +3153,4 @@ declare class URLDriver {
3114
3153
  url(page: number): string;
3115
3154
  }
3116
3155
  //#endregion
3117
- export { ArkormCollection, ArkormException, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, PrismaDelegateMap, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getMigrationPlan, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, pad, readAppliedMigrationsState, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };
3156
+ export { ArkormCollection, ArkormException, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, PrismaDelegateMap, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToPrismaSchema, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, removeAppliedMigration, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };
package/dist/index.d.mts CHANGED
@@ -86,9 +86,15 @@ interface AppliedMigrationEntry {
86
86
  appliedAt: string;
87
87
  checksum?: string;
88
88
  }
89
+ interface AppliedMigrationRun {
90
+ id: string;
91
+ appliedAt: string;
92
+ migrationIds: string[];
93
+ }
89
94
  interface AppliedMigrationsState {
90
95
  version: 1;
91
96
  migrations: AppliedMigrationEntry[];
97
+ runs?: AppliedMigrationRun[];
92
98
  }
93
99
  //#endregion
94
100
  //#region src/Collection.d.ts
@@ -2262,6 +2268,22 @@ declare class MigrateCommand extends Command<CliApp> {
2262
2268
  private loadMigrationClassesFromFile;
2263
2269
  }
2264
2270
  //#endregion
2271
+ //#region src/cli/commands/MigrateRollbackCommand.d.ts
2272
+ /**
2273
+ * Rollback migration classes from the Prisma schema and run Prisma workflow.
2274
+ * By default, rolls back classes applied in the last migrate run.
2275
+ *
2276
+ * @author Legacy (3m1n3nc3)
2277
+ * @since 0.2.4
2278
+ */
2279
+ declare class MigrateRollbackCommand extends Command<CliApp> {
2280
+ protected signature: string;
2281
+ protected description: string;
2282
+ handle(): Promise<undefined>;
2283
+ private loadAllMigrations;
2284
+ private loadMigrationClassesFromFile;
2285
+ }
2286
+ //#endregion
2265
2287
  //#region src/cli/commands/MigrationHistoryCommand.d.ts
2266
2288
  /**
2267
2289
  * The MigrationHistoryCommand class manages tracked migration run history.
@@ -2764,6 +2786,11 @@ declare const writeAppliedMigrationsState: (stateFilePath: string, state: Applie
2764
2786
  declare const isMigrationApplied: (state: AppliedMigrationsState, identity: string, checksum?: string) => boolean;
2765
2787
  declare const findAppliedMigration: (state: AppliedMigrationsState, identity: string) => AppliedMigrationEntry | undefined;
2766
2788
  declare const markMigrationApplied: (state: AppliedMigrationsState, entry: AppliedMigrationEntry) => AppliedMigrationsState;
2789
+ declare const removeAppliedMigration: (state: AppliedMigrationsState, identity: string) => AppliedMigrationsState;
2790
+ declare const buildMigrationRunId: () => string;
2791
+ declare const markMigrationRun: (state: AppliedMigrationsState, run: AppliedMigrationRun) => AppliedMigrationsState;
2792
+ declare const getLastMigrationRun: (state: AppliedMigrationsState) => AppliedMigrationRun | undefined;
2793
+ declare const getLatestAppliedMigrations: (state: AppliedMigrationsState, steps: number) => AppliedMigrationEntry[];
2767
2794
  //#endregion
2768
2795
  //#region src/helpers/migrations.d.ts
2769
2796
  declare const PRISMA_MODEL_REGEX: RegExp;
@@ -2990,6 +3017,18 @@ declare const applyMigrationToPrismaSchema: (migration: Migration | (new () => M
2990
3017
  schemaPath: string;
2991
3018
  operations: SchemaOperation[];
2992
3019
  }>;
3020
+ /**
3021
+ * Apply the rollback (down) operations defined in a migration to a Prisma schema file.
3022
+ *
3023
+ * @param migration The migration class or instance to rollback.
3024
+ * @param options Options for applying the rollback, including schema path and write flag.
3025
+ * @returns A promise that resolves to an object containing the updated schema, schema path, and rollback operations applied.
3026
+ */
3027
+ declare const applyMigrationRollbackToPrismaSchema: (migration: Migration | (new () => Migration), options?: PrismaSchemaSyncOptions) => Promise<{
3028
+ schema: string;
3029
+ schemaPath: string;
3030
+ operations: SchemaOperation[];
3031
+ }>;
2993
3032
  /**
2994
3033
  * Run a migration by applying its schema operations to a Prisma schema
2995
3034
  * file, optionally generating Prisma client code and running migrations after
@@ -3114,4 +3153,4 @@ declare class URLDriver {
3114
3153
  url(page: number): string;
3115
3154
  }
3116
3155
  //#endregion
3117
- export { ArkormCollection, ArkormException, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, PrismaDelegateMap, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getMigrationPlan, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, pad, readAppliedMigrationsState, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };
3156
+ export { ArkormCollection, ArkormException, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, PrismaDelegateMap, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToPrismaSchema, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, removeAppliedMigration, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };