@c9up/atlas 0.3.5 → 0.3.6

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.
@@ -15,10 +15,12 @@ import { runSchemaCheck } from "../schema/SchemaCheck.js";
15
15
  import { getDb } from "../services/db.js";
16
16
  import { flag } from "./contract.js";
17
17
  /**
18
- * Build the `atlas:check` command for the given models. Register it in
19
- * `reamrc.commands` (atlas has no global entity registry — list your models,
20
- * as in Lucid). Run it as `ream atlas:check`; `--warn` reports drift without a
21
- * non-zero exit (useful for an advisory CI step).
18
+ * Build the `atlas:check` command for the given models.
19
+ *
20
+ * Most applications do not call this: `@c9up/atlas/commands` ships the command
21
+ * already, reading the models from `verifySchema.entities`. Call it directly to
22
+ * verify a different set — pass a function when the list is only known once the
23
+ * application has booted.
22
24
  *
23
25
  * @example
24
26
  * // commands/atlas-check.ts
@@ -45,7 +47,16 @@ export function schemaCheckCommand(entities) {
45
47
  process.exitCode = 1;
46
48
  return;
47
49
  }
48
- const code = await runSchemaCheck(entities, db, getAtlasDialect());
50
+ // Resolved here, not at registration: the shipped command reads the
51
+ // models from `verifySchema.entities`, which only exists once the
52
+ // application has booted its config.
53
+ const models = typeof entities === "function" ? entities() : entities;
54
+ if (models.length === 0) {
55
+ console.error("[atlas:check] no models to verify — list them under `verifySchema.entities` in config/database.ts.");
56
+ process.exitCode = 1;
57
+ return;
58
+ }
59
+ const code = await runSchemaCheck(models, db, getAtlasDialect());
49
60
  // `--warn` downgrades drift to advisory (exit 0); default fails CI.
50
61
  if (code !== 0 && !this.warn)
51
62
  process.exitCode = code;
@@ -1 +1 @@
1
- {"version":3,"file":"schemaCheckCommand.js","sourceRoot":"","sources":["../../src/console/schemaCheckCommand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OA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ks).
14
14
  */
15
- import type { ConnectionConfig } from "../AtlasProvider.js";
15
+ import type { AtlasDatabaseConfig, ConnectionConfig } from "../AtlasProvider.js";
16
16
  import type { AsyncDatabaseConnection } from "../adapters/NapiDbAdapter.js";
17
17
  import { ConnectionManager } from "../ConnectionManager.js";
18
18
  import { DatabaseQueryBuilder, type QueryExecutor } from "../query/DatabaseQueryBuilder.js";
@@ -146,6 +146,29 @@ export declare function setDb(connection: AsyncDatabaseConnection): void;
146
146
  export declare function clearDb(connection: AsyncDatabaseConnection): void;
147
147
  /** @internal Read the singleton (or `undefined` pre-boot). */
148
148
  export declare function getDb(): AsyncDatabaseConnection | undefined;
149
+ /** @internal Record the booted config (called by AtlasProvider). */
150
+ export declare function setDatabaseConfig(config: AtlasDatabaseConfig, defaultName: string): void;
151
+ /**
152
+ * @internal Forget the config IF it is still the one `config` describes.
153
+ * Ownership-guarded for the same reason {@link clearDb} is: a second provider
154
+ * may have rebound it, and the older provider's shutdown must not clear the
155
+ * newer binding.
156
+ */
157
+ export declare function clearDatabaseConfig(config: AtlasDatabaseConfig): void;
158
+ /** The config the application booted with, or `undefined` before boot. */
159
+ export declare function getDatabaseConfig(): AtlasDatabaseConfig | undefined;
160
+ /** The default connection's name — Lucid `db.primaryConnectionName`. */
161
+ export declare function primaryConnectionName(): string;
162
+ /**
163
+ * One connection's config, by name (default connection when unnamed).
164
+ *
165
+ * Read from the manager's node first — that is where Lucid keeps `migrations`,
166
+ * `seeders` and `schemaGeneration`, and the shape we mirror. The top level is
167
+ * the fallback, because the single-connection form IS the connection config,
168
+ * and because an app that set `migrations` there before these keys were
169
+ * per-connection must keep working.
170
+ */
171
+ export declare function connectionConfigFor(name?: string): ConnectionConfig;
149
172
  /**
150
173
  * @internal Register an already-open named connection (called by AtlasProvider,
151
174
  * which opens connections itself). Records the config on the node too.
@@ -1 +1 @@
1
- {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/services/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;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IAAI,EAAE,MAAM,GACV,uBAAuB,GAAG,SAAS,CAErC;AAED,8FAA8F;AAC9F,wBAAgB,iBAAiB,IAAI,iBAAiB,CAErD;AAmCD,iFAAiF;AACjF,wBAAgB,eAAe,CAC9B,OAAO,EAAE,MAAM,uBAAuB,EACtC,QAAQ,UAAQ,GACd,SAAS,CA4JX;AAED,QAAA,MAAM,EAAE,EAAE,SAUR,CAAC;AAEH,eAAe,EAAE,CAAC"}
@@ -36,6 +36,72 @@ export function clearDb(connection) {
36
36
  export function getDb() {
37
37
  return instance;
38
38
  }
39
+ // The config the provider booted with. Commands need it: `migration:run` has to
40
+ // know where the migration files are, and Lucid answers that from the config
41
+ // too (`connection.config.migrations.paths`, read through `lucid.db`). Atlas has
42
+ // no framework container to read, so the provider records it here.
43
+ let databaseConfig;
44
+ /** @internal Record the booted config (called by AtlasProvider). */
45
+ export function setDatabaseConfig(config, defaultName) {
46
+ databaseConfig = { config, defaultName };
47
+ }
48
+ /**
49
+ * @internal Forget the config IF it is still the one `config` describes.
50
+ * Ownership-guarded for the same reason {@link clearDb} is: a second provider
51
+ * may have rebound it, and the older provider's shutdown must not clear the
52
+ * newer binding.
53
+ */
54
+ export function clearDatabaseConfig(config) {
55
+ if (databaseConfig?.config === config)
56
+ databaseConfig = undefined;
57
+ }
58
+ /** The config the application booted with, or `undefined` before boot. */
59
+ export function getDatabaseConfig() {
60
+ return databaseConfig?.config;
61
+ }
62
+ /** The default connection's name — Lucid `db.primaryConnectionName`. */
63
+ export function primaryConnectionName() {
64
+ return databaseConfig?.defaultName ?? "primary";
65
+ }
66
+ /**
67
+ * One connection's config, by name (default connection when unnamed).
68
+ *
69
+ * Read from the manager's node first — that is where Lucid keeps `migrations`,
70
+ * `seeders` and `schemaGeneration`, and the shape we mirror. The top level is
71
+ * the fallback, because the single-connection form IS the connection config,
72
+ * and because an app that set `migrations` there before these keys were
73
+ * per-connection must keep working.
74
+ */
75
+ export function connectionConfigFor(name) {
76
+ const resolved = name ?? primaryConnectionName();
77
+ const top = databaseConfig?.config;
78
+ // The manager knows a connection once the provider has registered it; before
79
+ // that — a command running against a config nobody opened yet — the declared
80
+ // `connections` entry is the same information.
81
+ const declared = manager.get(resolved)?.config ?? top?.connections?.[resolved];
82
+ if (top === undefined)
83
+ return declared ?? {};
84
+ if (declared === undefined)
85
+ return top;
86
+ return {
87
+ ...top,
88
+ ...declared,
89
+ // These three are merged a level down rather than replaced: the top level
90
+ // is the single-connection form of the same config, so a connection that
91
+ // names only its paths must not drop a `tableName` set beside it.
92
+ migrations: mergeOrUndefined(top.migrations, declared.migrations),
93
+ seeders: mergeOrUndefined(top.seeders, declared.seeders),
94
+ schemaGeneration: mergeOrUndefined(top.schemaGeneration, declared.schemaGeneration),
95
+ };
96
+ }
97
+ /** `{...a, ...b}`, or `undefined` when neither side has anything to merge. */
98
+ function mergeOrUndefined(base, override) {
99
+ if (base === undefined)
100
+ return override;
101
+ if (override === undefined)
102
+ return base;
103
+ return { ...base, ...override };
104
+ }
39
105
  // The shared connection manager (Lucid `db.manager`) — the single owner of named
40
106
  // connections. Backs `BaseModel.connection = 'analytics'` so a model resolves a
41
107
  // non-default connection from a plain import (AdonisJS `static connection`).
@@ -1 +1 @@
1
- {"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/services/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EACN,oBAAoB,GAEpB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EACN,eAAe,EACf,kBAAkB,GAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AA2H5D,IAAI,QAA6C,CAAC;AAElD,8DAA8D;AAC9D,MAAM,UAAU,KAAK,CAAC,UAAmC;IACxD,QAAQ,GAAG,UAAU,CAAC;AACv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AAa,CACd,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC,CAAC;AAEH,eAAe,EAAE,CAAC"}
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c9up/atlas",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Atlas — Data Mapper ORM for the Ream framework",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -48,6 +48,10 @@
48
48
  "types": "./dist/factories.d.ts",
49
49
  "import": "./dist/factories.js"
50
50
  },
51
+ "./commands": {
52
+ "types": "./dist/console/index.d.ts",
53
+ "import": "./dist/console/index.js"
54
+ },
51
55
  "./seeders": {
52
56
  "types": "./dist/seeders.d.ts",
53
57
  "import": "./dist/seeders.js"
@@ -25,6 +25,7 @@ import {
25
25
  type AsyncDatabaseConnection,
26
26
  createNapiConnection,
27
27
  } from "./adapters/NapiDbAdapter.js";
28
+ import type { SchemaGenerateOptions } from "./console/schemaGenerateCommand.js";
28
29
  import { clearCastRegistry, setAtlasDialect } from "./query/native.js";
29
30
  import {
30
31
  type DatabaseAdapter,
@@ -145,31 +146,27 @@ export interface ConnectionConfig {
145
146
  * make each `connectRetries` attempt give up faster (e.g. 5 × 2s).
146
147
  */
147
148
  connectTimeoutMs?: number;
148
- }
149
149
 
150
- /** Full database config — single-connection (legacy) OR multi-connection. */
151
- export interface AtlasDatabaseConfig extends ConnectionConfig {
152
- /**
153
- * Name of the default connection when `connections` is set (Lucid's top-level
154
- * `connection`). `default` is a deprecated alias — `connection` wins when both
155
- * are set. Defaults to `"primary"`.
156
- */
157
- connection?: string;
158
- /** @deprecated Use {@link connection} (the Lucid key). */
159
- default?: string;
160
- /** Named connections. When present, top-level `url` is treated as `connections[default].url`. */
161
- connections?: Record<string, ConnectionConfig>;
162
150
  migrations?: {
163
151
  /** @deprecated Use the Lucid-shaped {@link paths}. */
164
152
  path?: string;
165
153
  /** Migration directories, Lucid-shaped — `paths: ['database/migrations']`. */
166
154
  paths?: string[];
167
155
  /**
168
- * Custom name for the migrations tracking table. Defaults to `"ream_migrations"`.
169
- * Must match `/^[A-Za-z_][A-Za-z0-9_]*$/` the `MigrationRunner` constructor
170
- * throws `AtlasError("MIGRATION_INVALID_TABLE_NAME")` otherwise.
156
+ * Custom name for the migrations tracking table Adonis Lucid
157
+ * `migrations.tableName`. Defaults to `"ream_migrations"`. Must match
158
+ * `/^[A-Za-z_][A-Za-z0-9_]*$/` — the `MigrationRunner` constructor throws
159
+ * `AtlasError("MIGRATION_INVALID_TABLE_NAME")` otherwise.
171
160
  */
161
+ tableName?: string;
162
+ /** @deprecated Use the Lucid-shaped {@link tableName}, which wins when both are set. */
172
163
  table?: string;
164
+ /**
165
+ * Refuse rollback / reset / refresh / fresh / wipe when `NODE_ENV` is
166
+ * `production`, unless the command is given `--force` (Adonis Lucid
167
+ * `migrations.disableRollbacksInProduction`). On by default.
168
+ */
169
+ disableRollbacksInProduction?: boolean;
173
170
  /**
174
171
  * Allow the boot-time auto-migrate in production. OFF by default:
175
172
  * starting the app should NOT silently mutate the schema in prod (Adonis
@@ -192,6 +189,47 @@ export interface AtlasDatabaseConfig extends ConnectionConfig {
192
189
  */
193
190
  disableTransactions?: boolean;
194
191
  };
192
+ /**
193
+ * Where the seeder files live, and how they are ordered. Lucid keeps this on
194
+ * the connection too (`seeders: { paths: ['database/seeders'] }`); the
195
+ * commands default to `database/seeders` when it is absent.
196
+ */
197
+ seeders?: {
198
+ /** Seeder directories. Only the first is used — one connection, one source. */
199
+ paths?: string[];
200
+ /** Sort files numerically (`2_x` before `10_x`) — Lucid `naturalSort`. */
201
+ naturalSort?: boolean;
202
+ };
203
+ /**
204
+ * Where `make:factory` scaffolds. Not a Lucid key — Lucid resolves it from
205
+ * the application's `database/factories` directory, which atlas cannot read
206
+ * without depending on the framework, so it is configured here and defaults
207
+ * to the same path.
208
+ */
209
+ factories?: {
210
+ /** Directory the factory files are scaffolded into. */
211
+ path?: string;
212
+ };
213
+ /**
214
+ * Schema-file generation — Lucid `schemaGeneration`, on the connection.
215
+ * `schema:generate` needs `outputPath`; without it the command says so
216
+ * rather than guessing a path to write into.
217
+ */
218
+ schemaGeneration?: SchemaGenerateOptions;
219
+ }
220
+
221
+ /** Full database config — single-connection (legacy) OR multi-connection. */
222
+ export interface AtlasDatabaseConfig extends ConnectionConfig {
223
+ /**
224
+ * Name of the default connection when `connections` is set (Lucid's top-level
225
+ * `connection`). `default` is a deprecated alias — `connection` wins when both
226
+ * are set. Defaults to `"primary"`.
227
+ */
228
+ connection?: string;
229
+ /** @deprecated Use {@link connection} (the Lucid key). */
230
+ default?: string;
231
+ /** Named connections. When present, top-level `url` is treated as `connections[default].url`. */
232
+ connections?: Record<string, ConnectionConfig>;
195
233
  /**
196
234
  * Boot-time schema verification. When set, atlas reconciles each listed
197
235
  * model's `@Column` metadata against the LIVE database schema after boot and
@@ -411,6 +449,10 @@ export default class AtlasProvider {
411
449
  // `import db from '@c9up/atlas/services/db'` from anywhere.
412
450
  dbServices.setDb(defaultConn);
413
451
 
452
+ // Record the config too: the commands atlas ships read their paths from
453
+ // it, the way Lucid's read `connection.config.migrations.paths`.
454
+ dbServices.setDatabaseConfig(config, defaultName);
455
+
414
456
  // The dialect set module-wide is the DEFAULT connection's dialect.
415
457
  // Per-connection dialect (when a user hits a non-default) is read from
416
458
  // the connection URL at query time by each call site that cares.
@@ -445,7 +487,7 @@ export default class AtlasProvider {
445
487
  migrationsPath,
446
488
  connections[defaultName]?.url,
447
489
  defaultConn,
448
- config.migrations?.table,
490
+ config.migrations?.tableName ?? config.migrations?.table,
449
491
  {
450
492
  naturalSort: config.migrations?.naturalSort,
451
493
  disableTransactions: config.migrations?.disableTransactions,
@@ -457,7 +499,7 @@ export default class AtlasProvider {
457
499
  migrationsPath,
458
500
  connections[defaultName]?.url,
459
501
  defaultConn,
460
- config.migrations?.table,
502
+ config.migrations?.tableName ?? config.migrations?.table,
461
503
  {
462
504
  naturalSort: config.migrations?.naturalSort,
463
505
  disableTransactions: config.migrations?.disableTransactions,
@@ -466,6 +508,7 @@ export default class AtlasProvider {
466
508
  }
467
509
  } catch (err) {
468
510
  await Promise.allSettled(successes.map((s) => s.conn.close()));
511
+ dbServices.clearDatabaseConfig(config);
469
512
  for (const { name, conn } of successes) {
470
513
  dbServices.clearDb(conn);
471
514
  dbServices.unregisterConnection(name, conn);
@@ -502,7 +545,11 @@ export default class AtlasProvider {
502
545
  // registry entries (boot registered them), so `getConnection(name)` /
503
546
  // `BaseModel.connection` / `Factory.connection()` can't hand out a CLOSED
504
547
  // handle after shutdown.
505
- const { clearDb, unregisterConnection } = await import("./services/db.js");
548
+ const { clearDatabaseConfig, clearDb, unregisterConnection } = await import(
549
+ "./services/db.js"
550
+ );
551
+ const booted = this.app.config.get<AtlasDatabaseConfig>("database");
552
+ if (booted) clearDatabaseConfig(booted);
506
553
  for (const [name, conn] of named) {
507
554
  clearDb(conn);
508
555
  unregisterConnection(name, conn);
package/src/configure.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  interface Codemods {
2
2
  addProvider(importPath: string): Promise<void>;
3
+ registerCommand(importPath: string): Promise<void>;
3
4
  addEnvVars(vars: Record<string, string>): Promise<void>;
4
5
  writeFile(
5
6
  filePath: string,
@@ -10,6 +11,11 @@ interface Codemods {
10
11
 
11
12
  export async function configure(codemods: Codemods): Promise<void> {
12
13
  await codemods.addProvider("@c9up/atlas/provider");
14
+ // `reamrc.commands` is how a package ships commands — the same channel Lucid
15
+ // uses (`@adonisjs/lucid/commands`). Every migration / seeder / schema
16
+ // command comes from here, configured by `config/database.ts`; none of them
17
+ // needs a line in the `ream` binary.
18
+ await codemods.registerCommand("@c9up/atlas/commands");
13
19
  await codemods.addEnvVars({
14
20
  DB_HOST: "localhost",
15
21
  DB_PORT: "5432",
@@ -22,12 +28,18 @@ export async function configure(codemods: Codemods): Promise<void> {
22
28
  `import { defineConfig } from '@c9up/atlas'
23
29
 
24
30
  export default defineConfig({
25
- default: 'postgres',
31
+ connection: 'postgres',
26
32
  connections: {
27
33
  postgres: {
28
34
  url:
29
35
  process.env.DATABASE_URL ??
30
36
  \`postgres://\${process.env.DB_USER ?? 'postgres'}:\${process.env.DB_PASSWORD ?? ''}@\${process.env.DB_HOST ?? 'localhost'}:\${process.env.DB_PORT ?? '5432'}/\${process.env.DB_DATABASE ?? 'ream'}\`,
37
+ migrations: {
38
+ paths: ['database/migrations'],
39
+ },
40
+ seeders: {
41
+ paths: ['database/seeders'],
42
+ },
31
43
  },
32
44
  },
33
45
  })
@@ -0,0 +1,202 @@
1
+ /**
2
+ * `@c9up/atlas/commands` — every command atlas ships, configured from
3
+ * `config/database.ts`.
4
+ *
5
+ * // reamrc.ts, written by `configure()`
6
+ * commands: [() => import('@c9up/atlas/commands')]
7
+ *
8
+ * This is the shape Adonis Lucid ships (`@adonisjs/lucid/commands`, a module
9
+ * exporting `getMetaData` / `getCommand`), and it is the whole point: a package
10
+ * adds commands by shipping them, never by a change to the `ream` binary.
11
+ *
12
+ * Where the paths come from is Lucid's answer too — the connection's config
13
+ * (`migrations.paths`, `seeders.paths`, `schemaGeneration.outputPath`). Lucid
14
+ * reads it through the container; atlas reads it from its own locator, which
15
+ * the provider fills at boot, so nothing here imports `@c9up/ream`.
16
+ *
17
+ * The option objects below use getters on purpose. A command class is built
18
+ * when this module is imported — before the application boots — while every
19
+ * `options.x` is read inside `run()`, after it. A plain object would capture
20
+ * the config that did not exist yet.
21
+ */
22
+
23
+ import {
24
+ connectionConfigFor,
25
+ getDatabaseConfig,
26
+ primaryConnectionName,
27
+ } from "../services/db.js";
28
+ import type { AtlasCommandClass } from "./contract.js";
29
+ import {
30
+ type FactoryCommandOptions,
31
+ makeFactoryCommand,
32
+ } from "./factoryCommands.js";
33
+ import {
34
+ dbWipeCommand,
35
+ type MigrationCommandOptions,
36
+ makeMigrationCommand,
37
+ migrationFreshCommand,
38
+ migrationRefreshCommand,
39
+ migrationResetCommand,
40
+ migrationRollbackCommand,
41
+ migrationRunCommand,
42
+ migrationStatusCommand,
43
+ migrationUnlockCommand,
44
+ } from "./migrationCommands.js";
45
+ import { schemaCheckCommand } from "./schemaCheckCommand.js";
46
+ import {
47
+ type SchemaDumpCommandOptions,
48
+ schemaDumpCommand,
49
+ } from "./schemaDumpCommand.js";
50
+ import {
51
+ type SchemaGenerateOptions,
52
+ schemaGenerateCommand,
53
+ } from "./schemaGenerateCommand.js";
54
+ import {
55
+ dbSeedCommand,
56
+ makeSeederCommand,
57
+ type SeederCommandOptions,
58
+ } from "./seederCommands.js";
59
+
60
+ /** Lucid's defaults, for a config that leaves the paths out. */
61
+ const DEFAULT_MIGRATIONS_DIR = "database/migrations";
62
+ const DEFAULT_SEEDERS_DIR = "database/seeders";
63
+ const DEFAULT_FACTORIES_DIR = "database/factories";
64
+
65
+ /** The default connection's config — per-connection first, then the top level. */
66
+ function connection() {
67
+ return connectionConfigFor();
68
+ }
69
+
70
+ function migrationsDir(): string {
71
+ const migrations = connection().migrations;
72
+ return migrations?.paths?.[0] ?? migrations?.path ?? DEFAULT_MIGRATIONS_DIR;
73
+ }
74
+
75
+ const migrationOptions: MigrationCommandOptions = {
76
+ get migrationsDir() {
77
+ return migrationsDir();
78
+ },
79
+ get naturalSort() {
80
+ return connection().migrations?.naturalSort;
81
+ },
82
+ get disableTransactions() {
83
+ return connection().migrations?.disableTransactions;
84
+ },
85
+ get tableName() {
86
+ return connection().migrations?.tableName ?? connection().migrations?.table;
87
+ },
88
+ get disableRollbacksInProduction() {
89
+ return connection().migrations?.disableRollbacksInProduction;
90
+ },
91
+ get schemaGeneration() {
92
+ return connection().schemaGeneration;
93
+ },
94
+ };
95
+
96
+ const seederOptions: SeederCommandOptions = {
97
+ get seedersDir() {
98
+ return connection().seeders?.paths?.[0] ?? DEFAULT_SEEDERS_DIR;
99
+ },
100
+ get naturalSort() {
101
+ return connection().seeders?.naturalSort;
102
+ },
103
+ };
104
+
105
+ const factoryOptions: FactoryCommandOptions = {
106
+ get factoriesDir() {
107
+ return connection().factories?.path ?? DEFAULT_FACTORIES_DIR;
108
+ },
109
+ };
110
+
111
+ const schemaDumpOptions: SchemaDumpCommandOptions = {
112
+ get migrationsDir() {
113
+ return migrationsDir();
114
+ },
115
+ get schemaTableName() {
116
+ return connection().migrations?.tableName ?? connection().migrations?.table;
117
+ },
118
+ };
119
+
120
+ // `outputPath` has no sensible default — a command that guessed one would write
121
+ // a generated file into a directory the project never chose. The command
122
+ // reports the missing key itself; an empty string is what it checks for.
123
+ const schemaGenerateOptions: SchemaGenerateOptions = {
124
+ get outputPath() {
125
+ return connection().schemaGeneration?.outputPath ?? "";
126
+ },
127
+ get excludeTables() {
128
+ return connection().schemaGeneration?.excludeTables;
129
+ },
130
+ get enabled() {
131
+ return connection().schemaGeneration?.enabled;
132
+ },
133
+ get rulesPaths() {
134
+ return connection().schemaGeneration?.rulesPaths;
135
+ },
136
+ get compact() {
137
+ return connection().schemaGeneration?.compact;
138
+ },
139
+ get schemas() {
140
+ return connection().schemaGeneration?.schemas;
141
+ },
142
+ };
143
+
144
+ const COMMANDS: readonly AtlasCommandClass[] = [
145
+ migrationRunCommand(migrationOptions),
146
+ migrationRollbackCommand(migrationOptions),
147
+ migrationStatusCommand(migrationOptions),
148
+ migrationResetCommand(migrationOptions),
149
+ migrationRefreshCommand(migrationOptions),
150
+ migrationFreshCommand(migrationOptions),
151
+ migrationUnlockCommand(migrationOptions),
152
+ makeMigrationCommand(migrationOptions),
153
+ dbWipeCommand(migrationOptions),
154
+ dbSeedCommand(seederOptions),
155
+ makeSeederCommand(seederOptions),
156
+ makeFactoryCommand(factoryOptions),
157
+ schemaDumpCommand(schemaDumpOptions),
158
+ schemaGenerateCommand(schemaGenerateOptions),
159
+ schemaCheckCommand(() => getDatabaseConfig()?.verifySchema?.entities ?? []),
160
+ ];
161
+
162
+ /** What the kernel reads to list a command without importing it. */
163
+ interface CommandMetaData {
164
+ commandName: string;
165
+ namespace: string | null;
166
+ description: string;
167
+ help?: string | string[];
168
+ aliases: string[];
169
+ options: Record<string, unknown>;
170
+ args: readonly unknown[];
171
+ flags: readonly unknown[];
172
+ }
173
+
174
+ function serialize(command: AtlasCommandClass): CommandMetaData {
175
+ const colon = command.commandName.indexOf(":");
176
+ return {
177
+ commandName: command.commandName,
178
+ namespace: colon === -1 ? null : command.commandName.slice(0, colon),
179
+ description: command.description,
180
+ help: command.help,
181
+ aliases: [],
182
+ options: { ...command.options },
183
+ args: command.args ?? [],
184
+ flags: command.flags ?? [],
185
+ };
186
+ }
187
+
188
+ export async function getMetaData(): Promise<CommandMetaData[]> {
189
+ return COMMANDS.map(serialize);
190
+ }
191
+
192
+ export async function getCommand(
193
+ metadata: CommandMetaData,
194
+ ): Promise<AtlasCommandClass | null> {
195
+ return (
196
+ COMMANDS.find((command) => command.commandName === metadata.commandName) ??
197
+ null
198
+ );
199
+ }
200
+
201
+ /** The connection these commands run against — Lucid `db.primaryConnectionName`. */
202
+ export { primaryConnectionName };
@@ -61,6 +61,18 @@ export interface MigrationCommandOptions {
61
61
  * loads it once migrations exist.
62
62
  */
63
63
  schemaPath?: string;
64
+ /**
65
+ * Migration bookkeeping table — Adonis Lucid `migrations.tableName`. Must
66
+ * match what the application boots with: a command tracking migrations in a
67
+ * different table than the app would re-apply every migration it cannot see.
68
+ * Defaults to the runner's `"ream_migrations"`.
69
+ */
70
+ tableName?: string;
71
+ /**
72
+ * Refuse rollback/reset/refresh/fresh/wipe in production unless `--force`
73
+ * (Adonis Lucid `migrations.disableRollbacksInProduction`). On by default.
74
+ */
75
+ disableRollbacksInProduction?: boolean;
64
76
  }
65
77
 
66
78
  /**
@@ -105,6 +117,11 @@ function resolveRunner(
105
117
  dialect: db.dialect,
106
118
  naturalSort: options.naturalSort,
107
119
  disableTransactions: options.disableTransactions,
120
+ // Without the table name the runner falls back to its default while the
121
+ // application tracks migrations in the configured one — the command would
122
+ // then see an empty history and re-apply everything.
123
+ tableName: options.tableName,
124
+ disableRollbacksInProduction: options.disableRollbacksInProduction,
108
125
  });
109
126
  }
110
127