@c9up/atlas 0.1.19 → 0.2.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/README.md +63 -14
- package/db.darwin-arm64.node +0 -0
- package/db.darwin-x64.node +0 -0
- package/db.linux-arm64-gnu.node +0 -0
- package/db.linux-x64-gnu.node +0 -0
- package/db.win32-x64-msvc.node +0 -0
- package/dist/AtlasProvider.d.ts +66 -7
- package/dist/AtlasProvider.d.ts.map +1 -1
- package/dist/AtlasProvider.js +205 -39
- package/dist/AtlasProvider.js.map +1 -1
- package/dist/BaseEntity.d.ts +181 -5
- package/dist/BaseEntity.d.ts.map +1 -1
- package/dist/BaseEntity.js +339 -33
- package/dist/BaseEntity.js.map +1 -1
- package/dist/BaseModel.d.ts +127 -0
- package/dist/BaseModel.d.ts.map +1 -0
- package/dist/BaseModel.js +250 -0
- package/dist/BaseModel.js.map +1 -0
- package/dist/BaseRepository.d.ts +81 -15
- package/dist/BaseRepository.d.ts.map +1 -1
- package/dist/BaseRepository.js +1433 -387
- package/dist/BaseRepository.js.map +1 -1
- package/dist/ConnectionManager.d.ts +106 -0
- package/dist/ConnectionManager.d.ts.map +1 -0
- package/dist/ConnectionManager.js +228 -0
- package/dist/ConnectionManager.js.map +1 -0
- package/dist/ModelQuery.d.ts +577 -41
- package/dist/ModelQuery.d.ts.map +1 -1
- package/dist/ModelQuery.js +2188 -291
- package/dist/ModelQuery.js.map +1 -1
- package/dist/Transaction.d.ts +71 -1
- package/dist/Transaction.d.ts.map +1 -1
- package/dist/Transaction.js +138 -24
- package/dist/Transaction.js.map +1 -1
- package/dist/adapters/NapiDbAdapter.d.ts +44 -4
- package/dist/adapters/NapiDbAdapter.d.ts.map +1 -1
- package/dist/adapters/NapiDbAdapter.js +131 -13
- package/dist/adapters/NapiDbAdapter.js.map +1 -1
- package/dist/console/contract.d.ts +62 -0
- package/dist/console/contract.d.ts.map +1 -0
- package/dist/console/contract.js +38 -0
- package/dist/console/contract.js.map +1 -0
- package/dist/console/factoryCommands.d.ts +23 -0
- package/dist/console/factoryCommands.d.ts.map +1 -0
- package/dist/console/factoryCommands.js +62 -0
- package/dist/console/factoryCommands.js.map +1 -0
- package/dist/console/migrationCommands.d.ts +78 -0
- package/dist/console/migrationCommands.d.ts.map +1 -0
- package/dist/console/migrationCommands.js +327 -0
- package/dist/console/migrationCommands.js.map +1 -0
- package/dist/console/schemaCheckCommand.d.ts +11 -17
- package/dist/console/schemaCheckCommand.d.ts.map +1 -1
- package/dist/console/schemaCheckCommand.js +21 -15
- package/dist/console/schemaCheckCommand.js.map +1 -1
- package/dist/console/schemaDumpCommand.d.ts +30 -0
- package/dist/console/schemaDumpCommand.d.ts.map +1 -0
- package/dist/console/schemaDumpCommand.js +69 -0
- package/dist/console/schemaDumpCommand.js.map +1 -0
- package/dist/console/schemaGenerateCommand.d.ts +100 -0
- package/dist/console/schemaGenerateCommand.d.ts.map +1 -0
- package/dist/console/schemaGenerateCommand.js +246 -0
- package/dist/console/schemaGenerateCommand.js.map +1 -0
- package/dist/console/seederCommands.d.ts +46 -0
- package/dist/console/seederCommands.d.ts.map +1 -0
- package/dist/console/seederCommands.js +136 -0
- package/dist/console/seederCommands.js.map +1 -0
- package/dist/decorators/entity.d.ts +50 -8
- package/dist/decorators/entity.d.ts.map +1 -1
- package/dist/decorators/entity.js +42 -2
- package/dist/decorators/entity.js.map +1 -1
- package/dist/decorators/hooks.d.ts +3 -3
- package/dist/decorators/hooks.d.ts.map +1 -1
- package/dist/decorators/hooks.js.map +1 -1
- package/dist/events.d.ts +69 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +82 -0
- package/dist/events.js.map +1 -0
- package/dist/factories.d.ts +8 -0
- package/dist/factories.d.ts.map +1 -0
- package/dist/factories.js +8 -0
- package/dist/factories.js.map +1 -0
- package/dist/index.d.ts +15 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/lucid-schema.d.ts +15 -0
- package/dist/lucid-schema.d.ts.map +1 -0
- package/dist/lucid-schema.js +16 -0
- package/dist/lucid-schema.js.map +1 -0
- package/dist/metadata-keys.d.ts +3 -2
- package/dist/metadata-keys.d.ts.map +1 -1
- package/dist/naming/NamingStrategy.d.ts +7 -0
- package/dist/naming/NamingStrategy.d.ts.map +1 -1
- package/dist/naming/NamingStrategy.js +16 -0
- package/dist/naming/NamingStrategy.js.map +1 -1
- package/dist/orm.d.ts +14 -0
- package/dist/orm.d.ts.map +1 -0
- package/dist/orm.js +14 -0
- package/dist/orm.js.map +1 -0
- package/dist/query/DatabaseQueryBuilder.d.ts +557 -0
- package/dist/query/DatabaseQueryBuilder.d.ts.map +1 -0
- package/dist/query/DatabaseQueryBuilder.js +1798 -0
- package/dist/query/DatabaseQueryBuilder.js.map +1 -0
- package/dist/query/DmlBuilder.d.ts +62 -0
- package/dist/query/DmlBuilder.d.ts.map +1 -0
- package/dist/query/DmlBuilder.js +84 -0
- package/dist/query/DmlBuilder.js.map +1 -0
- package/dist/query/QueryBuilder.d.ts +5 -0
- package/dist/query/QueryBuilder.d.ts.map +1 -1
- package/dist/query/QueryBuilder.js +7 -0
- package/dist/query/QueryBuilder.js.map +1 -1
- package/dist/query/RawQueryBuilder.d.ts +47 -0
- package/dist/query/RawQueryBuilder.d.ts.map +1 -0
- package/dist/query/RawQueryBuilder.js +138 -0
- package/dist/query/RawQueryBuilder.js.map +1 -0
- package/dist/query/interpolate.d.ts +45 -0
- package/dist/query/interpolate.d.ts.map +1 -0
- package/dist/query/interpolate.js +51 -0
- package/dist/query/interpolate.js.map +1 -0
- package/dist/query/native.d.ts +8 -0
- package/dist/query/native.d.ts.map +1 -1
- package/dist/query/native.js +14 -0
- package/dist/query/native.js.map +1 -1
- package/dist/query/operators.d.ts +4 -0
- package/dist/query/operators.d.ts.map +1 -0
- package/dist/query/operators.js +27 -0
- package/dist/query/operators.js.map +1 -0
- package/dist/schema/Migration.d.ts +50 -3
- package/dist/schema/Migration.d.ts.map +1 -1
- package/dist/schema/Migration.js +60 -24
- package/dist/schema/Migration.js.map +1 -1
- package/dist/schema/MigrationRunner.d.ts +95 -34
- package/dist/schema/MigrationRunner.d.ts.map +1 -1
- package/dist/schema/MigrationRunner.js +523 -68
- package/dist/schema/MigrationRunner.js.map +1 -1
- package/dist/schema/Schema.d.ts +114 -0
- package/dist/schema/Schema.d.ts.map +1 -1
- package/dist/schema/Schema.js +272 -3
- package/dist/schema/Schema.js.map +1 -1
- package/dist/schema/SchemaDumper.d.ts +121 -0
- package/dist/schema/SchemaDumper.d.ts.map +1 -0
- package/dist/schema/SchemaDumper.js +365 -0
- package/dist/schema/SchemaDumper.js.map +1 -0
- package/dist/schema/Seeder.d.ts +13 -0
- package/dist/schema/Seeder.d.ts.map +1 -1
- package/dist/schema/Seeder.js +28 -5
- package/dist/schema/Seeder.js.map +1 -1
- package/dist/schema/TableBuilder.d.ts +274 -16
- package/dist/schema/TableBuilder.d.ts.map +1 -1
- package/dist/schema/TableBuilder.js +656 -52
- package/dist/schema/TableBuilder.js.map +1 -1
- package/dist/schema/catalog.d.ts +71 -0
- package/dist/schema/catalog.d.ts.map +1 -0
- package/dist/schema/catalog.js +158 -0
- package/dist/schema/catalog.js.map +1 -0
- package/dist/schema/introspect.d.ts +1 -1
- package/dist/schema/introspect.d.ts.map +1 -1
- package/dist/schema/introspect.js +26 -11
- package/dist/schema/introspect.js.map +1 -1
- package/dist/schema/types.d.ts +150 -1
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +11 -0
- package/dist/schema/types.js.map +1 -1
- package/dist/seeders.d.ts +7 -0
- package/dist/seeders.d.ts.map +1 -0
- package/dist/seeders.js +7 -0
- package/dist/seeders.js.map +1 -0
- package/dist/services/db.d.ts +122 -5
- package/dist/services/db.d.ts.map +1 -1
- package/dist/services/db.js +187 -14
- package/dist/services/db.js.map +1 -1
- package/dist/testing/DatabaseCleanup.d.ts +33 -7
- package/dist/testing/DatabaseCleanup.d.ts.map +1 -1
- package/dist/testing/DatabaseCleanup.js +54 -24
- package/dist/testing/DatabaseCleanup.js.map +1 -1
- package/dist/testing/DbAssertions.d.ts +48 -0
- package/dist/testing/DbAssertions.d.ts.map +1 -0
- package/dist/testing/DbAssertions.js +80 -0
- package/dist/testing/DbAssertions.js.map +1 -0
- package/dist/testing/Factory.d.ts +166 -15
- package/dist/testing/Factory.d.ts.map +1 -1
- package/dist/testing/Factory.js +497 -23
- package/dist/testing/Factory.js.map +1 -1
- package/dist/testing/TestUtils.d.ts +49 -0
- package/dist/testing/TestUtils.d.ts.map +1 -0
- package/dist/testing/TestUtils.js +79 -0
- package/dist/testing/TestUtils.js.map +1 -0
- package/dist/testing/index.d.ts +3 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +3 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/types/relations.d.ts +31 -0
- package/dist/types/relations.d.ts.map +1 -0
- package/dist/types/relations.js +20 -0
- package/dist/types/relations.js.map +1 -0
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +32 -2
- package/scripts/guard-publish.mjs +15 -0
- package/src/AtlasProvider.ts +305 -52
- package/src/BaseEntity.ts +460 -41
- package/src/BaseModel.ts +461 -0
- package/src/BaseRepository.ts +1710 -421
- package/src/ConnectionManager.ts +298 -0
- package/src/ModelQuery.ts +2998 -335
- package/src/Transaction.ts +227 -30
- package/src/adapters/NapiDbAdapter.ts +224 -17
- package/src/console/contract.ts +96 -0
- package/src/console/factoryCommands.ts +73 -0
- package/src/console/migrationCommands.ts +448 -0
- package/src/console/schemaCheckCommand.ts +26 -22
- package/src/console/schemaDumpCommand.ts +96 -0
- package/src/console/schemaGenerateCommand.ts +380 -0
- package/src/console/seederCommands.ts +174 -0
- package/src/decorators/entity.ts +71 -8
- package/src/decorators/hooks.ts +5 -3
- package/src/events.ts +117 -0
- package/src/factories.ts +10 -0
- package/src/index.ts +69 -3
- package/src/lucid-schema.ts +22 -0
- package/src/metadata-keys.ts +3 -2
- package/src/naming/NamingStrategy.ts +23 -0
- package/src/orm.ts +13 -0
- package/src/query/DatabaseQueryBuilder.ts +2724 -0
- package/src/query/DmlBuilder.ts +131 -0
- package/src/query/QueryBuilder.ts +8 -0
- package/src/query/RawQueryBuilder.ts +173 -0
- package/src/query/interpolate.ts +73 -0
- package/src/query/native.ts +29 -0
- package/src/query/operators.ts +27 -0
- package/src/schema/Migration.ts +71 -3
- package/src/schema/MigrationRunner.ts +676 -69
- package/src/schema/Schema.ts +359 -3
- package/src/schema/SchemaDumper.ts +518 -0
- package/src/schema/Seeder.ts +47 -10
- package/src/schema/TableBuilder.ts +783 -52
- package/src/schema/catalog.ts +236 -0
- package/src/schema/introspect.ts +26 -9
- package/src/schema/types.ts +137 -2
- package/src/seeders.ts +16 -0
- package/src/services/db.ts +361 -21
- package/src/testing/DatabaseCleanup.ts +78 -25
- package/src/testing/DbAssertions.ts +127 -0
- package/src/testing/Factory.ts +837 -40
- package/src/testing/TestUtils.ts +123 -0
- package/src/testing/index.ts +12 -1
- package/src/types/relations.ts +43 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory console command — `make:factory` (Adonis Lucid). Scaffolds a model
|
|
3
|
+
* factory file. Same shape as the migration/seeder commands: a plain
|
|
4
|
+
* `{ name, description, run }` object registered in `reamrc.commands`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // commands/make-factory.ts
|
|
8
|
+
* import { makeFactoryCommand } from '@c9up/atlas'
|
|
9
|
+
* export default makeFactoryCommand({ factoriesDir: 'database/factories' })
|
|
10
|
+
* // run: <console-entry> make:factory User
|
|
11
|
+
*/
|
|
12
|
+
import { type AtlasCommandClass } from "./contract.js";
|
|
13
|
+
export interface FactoryCommandOptions {
|
|
14
|
+
/** Directory the factory files are scaffolded into. */
|
|
15
|
+
factoriesDir: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `make:factory <Model>` — scaffold `<Model>Factory.ts` in `factoriesDir`. The
|
|
19
|
+
* name is validated (no path separators / traversal) and written with `wx` so an
|
|
20
|
+
* existing factory is never clobbered.
|
|
21
|
+
*/
|
|
22
|
+
export declare function makeFactoryCommand(options: FactoryCommandOptions): AtlasCommandClass;
|
|
23
|
+
//# sourceMappingURL=factoryCommands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factoryCommands.d.ts","sourceRoot":"","sources":["../../src/console/factoryCommands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EAAE,KAAK,iBAAiB,EAAY,MAAM,eAAe,CAAC;AAEjE,MAAM,WAAW,qBAAqB;IACrC,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;CACrB;AAaD;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,qBAAqB,GAC5B,iBAAiB,CA+BnB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory console command — `make:factory` (Adonis Lucid). Scaffolds a model
|
|
3
|
+
* factory file. Same shape as the migration/seeder commands: a plain
|
|
4
|
+
* `{ name, description, run }` object registered in `reamrc.commands`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // commands/make-factory.ts
|
|
8
|
+
* import { makeFactoryCommand } from '@c9up/atlas'
|
|
9
|
+
* export default makeFactoryCommand({ factoriesDir: 'database/factories' })
|
|
10
|
+
* // run: <console-entry> make:factory User
|
|
11
|
+
*/
|
|
12
|
+
import * as fsp from "node:fs/promises";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
import { camelToSnake } from "../utils/casing.js";
|
|
15
|
+
import { assertSafeName } from "../utils/safePath.js";
|
|
16
|
+
import { argument } from "./contract.js";
|
|
17
|
+
/** Scaffold body for a fresh factory (`make:factory <Model>`). */
|
|
18
|
+
function factoryStub(model) {
|
|
19
|
+
return `import { factory } from '@c9up/atlas'
|
|
20
|
+
import ${model} from '#models/${model.toLowerCase()}'
|
|
21
|
+
|
|
22
|
+
export const ${model}Factory = factory(${model}, ({ faker }) => ({
|
|
23
|
+
// email: faker.internet.email(),
|
|
24
|
+
}))
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* `make:factory <Model>` — scaffold `<Model>Factory.ts` in `factoriesDir`. The
|
|
29
|
+
* name is validated (no path separators / traversal) and written with `wx` so an
|
|
30
|
+
* existing factory is never clobbered.
|
|
31
|
+
*/
|
|
32
|
+
export function makeFactoryCommand(options) {
|
|
33
|
+
return class MakeFactory {
|
|
34
|
+
static commandName = "make:factory";
|
|
35
|
+
static description = "Scaffold a new model factory file";
|
|
36
|
+
// Pure filesystem work: no reason to boot the app and open a connection.
|
|
37
|
+
static options = { startApp: false };
|
|
38
|
+
static args = [
|
|
39
|
+
argument("model", { description: "Model the factory is built for" }),
|
|
40
|
+
];
|
|
41
|
+
async run() {
|
|
42
|
+
// A missing model is caught by the kernel before `run()` — it reports
|
|
43
|
+
// the required argument by name, so there is no usage check here.
|
|
44
|
+
// Lucid convention: `make:factory User` → `user_factory.ts`
|
|
45
|
+
// (`BlogPost` → `blog_post_factory.ts`).
|
|
46
|
+
const fileName = `${camelToSnake(this.model)}_factory.ts`;
|
|
47
|
+
try {
|
|
48
|
+
assertSafeName(fileName, "FACTORY_INVALID", "factory");
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
console.error(`[atlas] invalid factory name: ${this.model}`);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const filePath = path.join(options.factoriesDir, fileName);
|
|
56
|
+
await fsp.mkdir(options.factoriesDir, { recursive: true });
|
|
57
|
+
await fsp.writeFile(filePath, factoryStub(this.model), { flag: "wx" });
|
|
58
|
+
console.log(`Created ${filePath}`);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=factoryCommands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factoryCommands.js","sourceRoot":"","sources":["../../src/console/factoryCommands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAA0B,QAAQ,EAAE,MAAM,eAAe,CAAC;AAOjE,kEAAkE;AAClE,SAAS,WAAW,CAAC,KAAa;IACjC,OAAO;SACC,KAAK,kBAAkB,KAAK,CAAC,WAAW,EAAE;;eAEpC,KAAK,qBAAqB,KAAK;;;CAG7C,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CACjC,OAA8B;IAE9B,OAAO,MAAM,WAAW;QACvB,MAAM,CAAC,WAAW,GAAG,cAAc,CAAC;QACpC,MAAM,CAAC,WAAW,GAAG,mCAAmC,CAAC;QACzD,yEAAyE;QACzE,MAAM,CAAC,OAAO,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACrC,MAAM,CAAC,IAAI,GAAG;YACb,QAAQ,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;SACpE,CAAC;QAIF,KAAK,CAAC,GAAG;YACR,sEAAsE;YACtE,kEAAkE;YAClE,4DAA4D;YAC5D,yCAAyC;YACzC,MAAM,QAAQ,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;YAC1D,IAAI,CAAC;gBACJ,cAAc,CAAC,QAAQ,EAAE,iBAAiB,EAAE,SAAS,CAAC,CAAC;YACxD,CAAC;YAAC,MAAM,CAAC;gBACR,OAAO,CAAC,KAAK,CAAC,iCAAiC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;gBAC7D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;gBACrB,OAAO;YACR,CAAC;YACD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;YAC3D,MAAM,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3D,MAAM,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YACvE,OAAO,CAAC,GAAG,CAAC,WAAW,QAAQ,EAAE,CAAC,CAAC;QACpC,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration console commands — the Ream-idiomatic CLI for running, rolling back,
|
|
3
|
+
* inspecting, and wiping migrations. Same shape and contract as
|
|
4
|
+
* {@link schemaCheckCommand}: plain `{ name, description, run }` objects
|
|
5
|
+
* registered in `reamrc.commands` and dispatched by the console kernel.
|
|
6
|
+
*
|
|
7
|
+
* Each command resolves the live connection from atlas's OWN service locator
|
|
8
|
+
* (`getDb`), never importing `@c9up/ream`, and drives the already-tested
|
|
9
|
+
* {@link MigrationRunner}. Atlas has no global config registry (Lucid parity —
|
|
10
|
+
* you pass your own paths), so every factory takes the `migrationsDir`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // commands/migrate.ts
|
|
14
|
+
* import { migrationRunCommand } from '@c9up/atlas'
|
|
15
|
+
* export default migrationRunCommand({ migrationsDir: 'database/migrations' })
|
|
16
|
+
*
|
|
17
|
+
* // reamrc.ts → commands: [() => import('./commands/migrate.js')]
|
|
18
|
+
* // run: <console-entry> migration:run
|
|
19
|
+
*/
|
|
20
|
+
import { type AtlasCommandClass } from "./contract.js";
|
|
21
|
+
import { type SchemaGenerateOptions } from "./schemaGenerateCommand.js";
|
|
22
|
+
export interface MigrationCommandOptions {
|
|
23
|
+
/** Directory holding the numbered migration files. */
|
|
24
|
+
migrationsDir: string;
|
|
25
|
+
/**
|
|
26
|
+
* Sort migration files numerically (`2_x` before `10_x`). Adonis Lucid
|
|
27
|
+
* `migrations.naturalSort`. Defaults to `false`.
|
|
28
|
+
*/
|
|
29
|
+
naturalSort?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Run every migration outside a transaction. Adonis Lucid
|
|
32
|
+
* `migrations.disableTransactions`. A migration can also opt out with
|
|
33
|
+
* `static disableTransactions = true`. Defaults to `false`.
|
|
34
|
+
*/
|
|
35
|
+
disableTransactions?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Regenerate the schema file after a mutating migration command
|
|
38
|
+
* (run/rollback/reset/refresh/fresh) — Adonis Lucid's post-migration
|
|
39
|
+
* `schema:generate`. Off unless an `outputPath` is given; on by default once
|
|
40
|
+
* it is, unless `enabled: false`; suppress per-run with `--no-schema-generate`.
|
|
41
|
+
*/
|
|
42
|
+
schemaGeneration?: SchemaGenerateOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Default schema-dump path auto-loaded by `migration:run` / `migration:fresh`
|
|
45
|
+
* when the target DB has no applied migrations (Adonis Lucid bootstraps from
|
|
46
|
+
* the dump by default). Overridden per-run by `--schema-path`; a run never
|
|
47
|
+
* loads it once migrations exist.
|
|
48
|
+
*/
|
|
49
|
+
schemaPath?: string;
|
|
50
|
+
}
|
|
51
|
+
/** `migration:run` — apply every pending migration. */
|
|
52
|
+
export declare function migrationRunCommand(options: MigrationCommandOptions): AtlasCommandClass;
|
|
53
|
+
/**
|
|
54
|
+
* `migration:rollback` — undo the latest batch, or with `--batch=N` roll back
|
|
55
|
+
* everything applied after batch N (`--batch=0` rolls back all).
|
|
56
|
+
*/
|
|
57
|
+
export declare function migrationRollbackCommand(options: MigrationCommandOptions): AtlasCommandClass;
|
|
58
|
+
/** `migration:status` — list every migration and whether it is applied. */
|
|
59
|
+
export declare function migrationStatusCommand(options: MigrationCommandOptions): AtlasCommandClass;
|
|
60
|
+
/** `migration:reset` — roll back every applied migration. */
|
|
61
|
+
export declare function migrationResetCommand(options: MigrationCommandOptions): AtlasCommandClass;
|
|
62
|
+
/** `migration:unlock` — force-clear a stuck migration lock (Lucid `migration:unlock`). */
|
|
63
|
+
export declare function migrationUnlockCommand(options: MigrationCommandOptions): AtlasCommandClass;
|
|
64
|
+
/** `migration:fresh` — drop every table, then re-run all migrations (Lucid `migration:fresh`). */
|
|
65
|
+
export declare function migrationFreshCommand(options: MigrationCommandOptions): AtlasCommandClass;
|
|
66
|
+
/** `migration:refresh` — roll everything back, then re-run all migrations. */
|
|
67
|
+
export declare function migrationRefreshCommand(options: MigrationCommandOptions): AtlasCommandClass;
|
|
68
|
+
/** `db:wipe` — drop every table, including the migrations bookkeeping table. */
|
|
69
|
+
export declare function dbWipeCommand(options: MigrationCommandOptions): AtlasCommandClass;
|
|
70
|
+
/**
|
|
71
|
+
* `make:migration <name>` — scaffold a timestamped migration file in
|
|
72
|
+
* `migrationsDir`. The `Date.now()` prefix keeps files in creation order under
|
|
73
|
+
* the runner's lexicographic sort (same convention as AdonisJS/Lucid). The name
|
|
74
|
+
* is validated (no path separators / traversal) and the file is written with
|
|
75
|
+
* `wx` so an existing migration is never clobbered.
|
|
76
|
+
*/
|
|
77
|
+
export declare function makeMigrationCommand(options: MigrationCommandOptions): AtlasCommandClass;
|
|
78
|
+
//# sourceMappingURL=migrationCommands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrationCommands.d.ts","sourceRoot":"","sources":["../../src/console/migrationCommands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAWH,OAAO,EAAE,KAAK,iBAAiB,EAAk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omatic CLI for running, rolling back,
|
|
3
|
+
* inspecting, and wiping migrations. Same shape and contract as
|
|
4
|
+
* {@link schemaCheckCommand}: plain `{ name, description, run }` objects
|
|
5
|
+
* registered in `reamrc.commands` and dispatched by the console kernel.
|
|
6
|
+
*
|
|
7
|
+
* Each command resolves the live connection from atlas's OWN service locator
|
|
8
|
+
* (`getDb`), never importing `@c9up/ream`, and drives the already-tested
|
|
9
|
+
* {@link MigrationRunner}. Atlas has no global config registry (Lucid parity —
|
|
10
|
+
* you pass your own paths), so every factory takes the `migrationsDir`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // commands/migrate.ts
|
|
14
|
+
* import { migrationRunCommand } from '@c9up/atlas'
|
|
15
|
+
* export default migrationRunCommand({ migrationsDir: 'database/migrations' })
|
|
16
|
+
*
|
|
17
|
+
* // reamrc.ts → commands: [() => import('./commands/migrate.js')]
|
|
18
|
+
* // run: <console-entry> migration:run
|
|
19
|
+
*/
|
|
20
|
+
import * as fsp from "node:fs/promises";
|
|
21
|
+
import * as path from "node:path";
|
|
22
|
+
import { MigrationRunner, } from "../schema/MigrationRunner.js";
|
|
23
|
+
import { getDb } from "../services/db.js";
|
|
24
|
+
import { assertSafeName } from "../utils/safePath.js";
|
|
25
|
+
import { argument, flag } from "./contract.js";
|
|
26
|
+
import { generateSchemaFile, } from "./schemaGenerateCommand.js";
|
|
27
|
+
/**
|
|
28
|
+
* Adapt the shared singleton connection to the runner's {@link DatabaseAdapter}.
|
|
29
|
+
* `close()` is intentionally a no-op — the console kernel owns the connection's
|
|
30
|
+
* lifecycle, so a command must not tear down a connection other commands share.
|
|
31
|
+
*/
|
|
32
|
+
function toAdapter(conn) {
|
|
33
|
+
return {
|
|
34
|
+
execute: async (sql, params) => {
|
|
35
|
+
await conn.execute(sql, params);
|
|
36
|
+
},
|
|
37
|
+
query: (sql, params) => conn.query(sql, params),
|
|
38
|
+
runInTransaction: (batch) => conn.runInTransaction(batch),
|
|
39
|
+
// Thread the connection's managed interactive transaction through so the
|
|
40
|
+
// runner can make this.defer() atomic and restore MySQL FK checks.
|
|
41
|
+
transaction: conn.transaction?.bind(conn),
|
|
42
|
+
close: async () => { },
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolve a runner from the live connection, or report and set a failing exit
|
|
47
|
+
* code when no connection is registered (mirrors `schemaCheckCommand`).
|
|
48
|
+
*/
|
|
49
|
+
function resolveRunner(options) {
|
|
50
|
+
const db = getDb();
|
|
51
|
+
if (!db) {
|
|
52
|
+
console.error("[atlas] no database connection — is AtlasProvider registered?");
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
// Pass the connection's ACTUAL dialect — without it the runner defaults to
|
|
57
|
+
// sqlite and emits SQLite SQL (lock table, FK handling, DDL) against a
|
|
58
|
+
// Postgres/MySQL database.
|
|
59
|
+
return new MigrationRunner(toAdapter(db), {
|
|
60
|
+
migrationsDir: options.migrationsDir,
|
|
61
|
+
dialect: db.dialect,
|
|
62
|
+
naturalSort: options.naturalSort,
|
|
63
|
+
disableTransactions: options.disableTransactions,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** `migration:run` — apply every pending migration. */
|
|
67
|
+
export function migrationRunCommand(options) {
|
|
68
|
+
return class MigrationRun {
|
|
69
|
+
static commandName = "migration:run";
|
|
70
|
+
static description = "Run all pending migrations (--schema-path to bootstrap from a dump)";
|
|
71
|
+
static options = { startApp: true };
|
|
72
|
+
static flags = [schemaPathOption(), noSchemaGenerateFlag()];
|
|
73
|
+
async run() {
|
|
74
|
+
const runner = resolveRunner(options);
|
|
75
|
+
if (!runner)
|
|
76
|
+
return;
|
|
77
|
+
const ran = await runner.migrate({
|
|
78
|
+
schemaPath: this.schemaPath ?? options.schemaPath,
|
|
79
|
+
});
|
|
80
|
+
console.log(ran.length ? `Migrated: ${ran.join(", ")}` : "Already up to date");
|
|
81
|
+
await maybeRegenSchema(options, this);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `migration:rollback` — undo the latest batch, or with `--batch=N` roll back
|
|
87
|
+
* everything applied after batch N (`--batch=0` rolls back all).
|
|
88
|
+
*/
|
|
89
|
+
export function migrationRollbackCommand(options) {
|
|
90
|
+
return class MigrationRollback {
|
|
91
|
+
static commandName = "migration:rollback";
|
|
92
|
+
static description = "Roll back the latest batch (or --batch=N; --force in prod)";
|
|
93
|
+
static options = { startApp: true };
|
|
94
|
+
static flags = [
|
|
95
|
+
flag("batch", "number", {
|
|
96
|
+
description: "Roll back everything applied after batch N (0 = all)",
|
|
97
|
+
}),
|
|
98
|
+
forceFlag(),
|
|
99
|
+
noSchemaGenerateFlag(),
|
|
100
|
+
];
|
|
101
|
+
async run() {
|
|
102
|
+
const runner = resolveRunner(options);
|
|
103
|
+
if (!runner)
|
|
104
|
+
return;
|
|
105
|
+
const batch = parseBatchFlag(this.batch);
|
|
106
|
+
if (batch === "invalid") {
|
|
107
|
+
console.error("[atlas] --batch must be a non-negative integer");
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const force = this.force === true;
|
|
112
|
+
const rolled = await runner.rollback(batch === undefined ? { force } : { batch, force });
|
|
113
|
+
console.log(rolled.length
|
|
114
|
+
? `Rolled back: ${rolled.join(", ")}`
|
|
115
|
+
: "Nothing to roll back");
|
|
116
|
+
await maybeRegenSchema(options, this);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** `migration:status` — list every migration and whether it is applied. */
|
|
121
|
+
export function migrationStatusCommand(options) {
|
|
122
|
+
return class MigrationStatus {
|
|
123
|
+
static commandName = "migration:status";
|
|
124
|
+
static description = "Show applied and pending migrations";
|
|
125
|
+
static options = { startApp: true };
|
|
126
|
+
async run() {
|
|
127
|
+
const runner = resolveRunner(options);
|
|
128
|
+
if (!runner)
|
|
129
|
+
return;
|
|
130
|
+
const rows = await runner.status();
|
|
131
|
+
if (rows.length === 0) {
|
|
132
|
+
console.log("No migrations found");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
for (const row of rows) {
|
|
136
|
+
const batch = row.batch === undefined ? "" : ` (batch ${row.batch})`;
|
|
137
|
+
console.log(`${row.status.padEnd(8)} ${row.name}${batch}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** `migration:reset` — roll back every applied migration. */
|
|
143
|
+
export function migrationResetCommand(options) {
|
|
144
|
+
return class MigrationReset {
|
|
145
|
+
static commandName = "migration:reset";
|
|
146
|
+
static description = "Roll back all migrations (--force to override prod guard)";
|
|
147
|
+
static options = { startApp: true };
|
|
148
|
+
static flags = [forceFlag(), noSchemaGenerateFlag()];
|
|
149
|
+
async run() {
|
|
150
|
+
const runner = resolveRunner(options);
|
|
151
|
+
if (!runner)
|
|
152
|
+
return;
|
|
153
|
+
const rolled = await runner.reset({ force: this.force === true });
|
|
154
|
+
console.log(rolled.length
|
|
155
|
+
? `Rolled back: ${rolled.join(", ")}`
|
|
156
|
+
: "Nothing to reset");
|
|
157
|
+
await maybeRegenSchema(options, this);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** `migration:unlock` — force-clear a stuck migration lock (Lucid `migration:unlock`). */
|
|
162
|
+
export function migrationUnlockCommand(options) {
|
|
163
|
+
return class MigrationUnlock {
|
|
164
|
+
static commandName = "migration:unlock";
|
|
165
|
+
static description = "Force-clear a stuck migration lock";
|
|
166
|
+
static options = { startApp: true };
|
|
167
|
+
async run() {
|
|
168
|
+
const runner = resolveRunner(options);
|
|
169
|
+
if (!runner)
|
|
170
|
+
return;
|
|
171
|
+
const cleared = await runner.forceUnlock();
|
|
172
|
+
console.log(cleared ? "Migration lock cleared" : "No migration lock was held");
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/** `migration:fresh` — drop every table, then re-run all migrations (Lucid `migration:fresh`). */
|
|
177
|
+
export function migrationFreshCommand(options) {
|
|
178
|
+
return class MigrationFresh {
|
|
179
|
+
static commandName = "migration:fresh";
|
|
180
|
+
static description = "Drop all tables, then re-run every migration (--force to override prod guard)";
|
|
181
|
+
static options = { startApp: true };
|
|
182
|
+
static flags = [forceFlag(), schemaPathOption(), noSchemaGenerateFlag()];
|
|
183
|
+
async run() {
|
|
184
|
+
const runner = resolveRunner(options);
|
|
185
|
+
if (!runner)
|
|
186
|
+
return;
|
|
187
|
+
const { executed } = await runner.fresh({
|
|
188
|
+
force: this.force === true,
|
|
189
|
+
schemaPath: this.schemaPath ?? options.schemaPath,
|
|
190
|
+
});
|
|
191
|
+
console.log(executed.length
|
|
192
|
+
? `Dropped all tables, re-ran: ${executed.join(", ")}`
|
|
193
|
+
: "Dropped all tables (no migrations to run)");
|
|
194
|
+
await maybeRegenSchema(options, this);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/** `migration:refresh` — roll everything back, then re-run all migrations. */
|
|
199
|
+
export function migrationRefreshCommand(options) {
|
|
200
|
+
return class MigrationRefresh {
|
|
201
|
+
static commandName = "migration:refresh";
|
|
202
|
+
static description = "Roll back all migrations, then re-run them (--force to override prod guard)";
|
|
203
|
+
static options = { startApp: true };
|
|
204
|
+
static flags = [forceFlag(), noSchemaGenerateFlag()];
|
|
205
|
+
async run() {
|
|
206
|
+
const runner = resolveRunner(options);
|
|
207
|
+
if (!runner)
|
|
208
|
+
return;
|
|
209
|
+
const { rolled, executed } = await runner.refresh({
|
|
210
|
+
force: this.force === true,
|
|
211
|
+
});
|
|
212
|
+
console.log(`Rolled back: ${rolled.length}, re-ran: ${executed.length}`);
|
|
213
|
+
await maybeRegenSchema(options, this);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** `db:wipe` — drop every table, including the migrations bookkeeping table. */
|
|
218
|
+
export function dbWipeCommand(options) {
|
|
219
|
+
return class DbWipe {
|
|
220
|
+
static commandName = "db:wipe";
|
|
221
|
+
static description = "Drop all tables including the migrations table (--force to override prod guard)";
|
|
222
|
+
static options = { startApp: true };
|
|
223
|
+
static flags = [forceFlag()];
|
|
224
|
+
async run() {
|
|
225
|
+
const runner = resolveRunner(options);
|
|
226
|
+
if (!runner)
|
|
227
|
+
return;
|
|
228
|
+
await runner.wipe({ force: this.force === true });
|
|
229
|
+
console.log("Dropped all tables");
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/** Scaffold body for a fresh migration (`make:migration`). */
|
|
234
|
+
const MIGRATION_STUB = `import { Migration } from '@c9up/atlas'
|
|
235
|
+
|
|
236
|
+
export default class extends Migration {
|
|
237
|
+
async up() {
|
|
238
|
+
// this.schema.createTable('table_name', (table) => {
|
|
239
|
+
// table.increments('id')
|
|
240
|
+
// })
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async down() {
|
|
244
|
+
// this.schema.dropTable('table_name')
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
`;
|
|
248
|
+
/**
|
|
249
|
+
* `make:migration <name>` — scaffold a timestamped migration file in
|
|
250
|
+
* `migrationsDir`. The `Date.now()` prefix keeps files in creation order under
|
|
251
|
+
* the runner's lexicographic sort (same convention as AdonisJS/Lucid). The name
|
|
252
|
+
* is validated (no path separators / traversal) and the file is written with
|
|
253
|
+
* `wx` so an existing migration is never clobbered.
|
|
254
|
+
*/
|
|
255
|
+
export function makeMigrationCommand(options) {
|
|
256
|
+
return class MakeMigration {
|
|
257
|
+
static commandName = "make:migration";
|
|
258
|
+
static description = "Scaffold a new timestamped migration file";
|
|
259
|
+
// Filesystem only — no connection needed.
|
|
260
|
+
static options = { startApp: false };
|
|
261
|
+
static args = [argument("name", { description: "Migration file name" })];
|
|
262
|
+
async run() {
|
|
263
|
+
// A missing name never reaches here: the kernel reports the required
|
|
264
|
+
// argument by name before `run()`.
|
|
265
|
+
try {
|
|
266
|
+
assertSafeName(this.name, "MIGRATION_INVALID", "migration");
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
console.error(`[atlas] invalid migration name: ${this.name}`);
|
|
270
|
+
process.exitCode = 1;
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const fileName = `${Date.now()}_${this.name}.ts`;
|
|
274
|
+
const filePath = path.join(options.migrationsDir, fileName);
|
|
275
|
+
await fsp.mkdir(options.migrationsDir, { recursive: true });
|
|
276
|
+
await fsp.writeFile(filePath, MIGRATION_STUB, { flag: "wx" });
|
|
277
|
+
console.log(`Created ${filePath}`);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Flags shared by several migration commands.
|
|
283
|
+
*
|
|
284
|
+
* Declared per command rather than inherited: `migration:status` takes neither
|
|
285
|
+
* `--force` nor `--schema-path`, and listing them anyway would put flags in its
|
|
286
|
+
* help that it ignores.
|
|
287
|
+
*/
|
|
288
|
+
const forceFlag = () => flag("force", "boolean", {
|
|
289
|
+
description: "Override the production guard",
|
|
290
|
+
});
|
|
291
|
+
const schemaPathOption = () => flag("schemaPath", "string", {
|
|
292
|
+
description: "Bootstrap from a schema dump before migrating",
|
|
293
|
+
});
|
|
294
|
+
const noSchemaGenerateFlag = () => flag("noSchemaGenerate", "boolean", {
|
|
295
|
+
description: "Skip regenerating the schema file afterwards",
|
|
296
|
+
});
|
|
297
|
+
/**
|
|
298
|
+
* Regenerate the schema file after a mutating migration command (Adonis Lucid's
|
|
299
|
+
* post-migration `schema:generate`) — unless it's disabled, has no `outputPath`,
|
|
300
|
+
* or the run passed `--no-schema-generate`.
|
|
301
|
+
*/
|
|
302
|
+
async function maybeRegenSchema(options, command) {
|
|
303
|
+
const cfg = options.schemaGeneration;
|
|
304
|
+
// Opt-in by configuring an outputPath; then ON unless explicitly disabled —
|
|
305
|
+
// Adonis Lucid presents `enabled: false` as the OFF switch (default on).
|
|
306
|
+
if (!cfg?.outputPath || cfg.enabled === false)
|
|
307
|
+
return;
|
|
308
|
+
if (command.noSchemaGenerate === true)
|
|
309
|
+
return;
|
|
310
|
+
const db = getDb();
|
|
311
|
+
if (!db)
|
|
312
|
+
return;
|
|
313
|
+
const n = await generateSchemaFile(db, cfg);
|
|
314
|
+
console.log(`Regenerated ${cfg.outputPath} (${n} table${n === 1 ? "" : "s"})`);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Parse the `--batch` flag: absent → undefined (default rollback), a
|
|
318
|
+
* non-negative integer string → that number, anything else → `"invalid"`.
|
|
319
|
+
*/
|
|
320
|
+
function parseBatchFlag(value) {
|
|
321
|
+
// The kernel already rejected a non-numeric `--batch`; what is left to check
|
|
322
|
+
// is that the number is a non-negative integer.
|
|
323
|
+
if (value === undefined)
|
|
324
|
+
return undefined;
|
|
325
|
+
return Number.isInteger(value) && value >= 0 ? value : "invalid";
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=migrationCommands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrationCommands.js","sourceRoot":"","sources":["../../src/console/migrationCommands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAEN,eAAe,GACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAA0B,QAAQ,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EACN,kBAAkB,GAElB,MAAM,4BAA4B,CAAC;AAgCpC;;;;GAIG;AACH,SAAS,SAAS,CAAC,IAA6B;IAC/C,OAAO;QACN,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,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,gDAAgD;IAChD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAClE,CAAC"}
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `atlas:check` console command — the Ream-idiomatic CLI for schema
|
|
3
|
-
* verification. Ream commands are
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* verification. Ream commands are classes carrying their name, description and
|
|
4
|
+
* inputs as statics; the console kernel discovers them in `commands/` or reads
|
|
5
|
+
* them from `reamrc.commands`.
|
|
6
6
|
*
|
|
7
7
|
* Stays framework-agnostic: resolves the live connection + dialect from atlas's
|
|
8
8
|
* OWN service locators (`getDb` / `getAtlasDialect`), never importing
|
|
9
|
-
* `@c9up/ream`. The {@link
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* `@c9up/ream`. The {@link AtlasCommandClass} shape structurally matches Ream's
|
|
10
|
+
* command contract, so the console kernel accepts it without a type dependency
|
|
11
|
+
* in either direction.
|
|
12
12
|
*/
|
|
13
|
+
import { type AtlasCommandClass } from "./contract.js";
|
|
13
14
|
type Constructor = new (...args: unknown[]) => unknown;
|
|
14
|
-
|
|
15
|
-
export interface AtlasCommand {
|
|
16
|
-
name: string;
|
|
17
|
-
description: string;
|
|
18
|
-
run(args: string[], flags: Record<string, string | boolean>): Promise<void>;
|
|
19
|
-
}
|
|
15
|
+
export type { AtlasCommandClass } from "./contract.js";
|
|
20
16
|
/**
|
|
21
17
|
* Build the `atlas:check` command for the given models. Register it in
|
|
22
18
|
* `reamrc.commands` (atlas has no global entity registry — list your models,
|
|
23
|
-
* as in Lucid). Run it
|
|
19
|
+
* as in Lucid). Run it as `ream atlas:check`; `--warn` reports drift without a
|
|
24
20
|
* non-zero exit (useful for an advisory CI step).
|
|
25
21
|
*
|
|
26
22
|
* @example
|
|
@@ -29,9 +25,7 @@ export interface AtlasCommand {
|
|
|
29
25
|
* import { User } from '#models/user'
|
|
30
26
|
* export default schemaCheckCommand([User])
|
|
31
27
|
*
|
|
32
|
-
* //
|
|
33
|
-
* // run: <console-entry> atlas:check
|
|
28
|
+
* // run: ream atlas:check --warn
|
|
34
29
|
*/
|
|
35
|
-
export declare function schemaCheckCommand(entities: readonly Constructor[]):
|
|
36
|
-
export {};
|
|
30
|
+
export declare function schemaCheckCommand(entities: readonly Constructor[]): AtlasCommandClass;
|
|
37
31
|
//# sourceMappingURL=schemaCheckCommand.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaCheckCommand.d.ts","sourceRoot":"","sources":["../../src/console/schemaCheckCommand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"schemaCheckCommand.d.ts","sourceRoot":"","sources":["../../src/console/schemaCheckCommand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,EAAE,KAAK,iBAAiB,EAAQ,MAAM,eAAe,CAAC;AAE7D,KAAK,WAAW,GAAG,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAEvD,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC9B,iBAAiB,CA2BnB"}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `atlas:check` console command — the Ream-idiomatic CLI for schema
|
|
3
|
-
* verification. Ream commands are
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* verification. Ream commands are classes carrying their name, description and
|
|
4
|
+
* inputs as statics; the console kernel discovers them in `commands/` or reads
|
|
5
|
+
* them from `reamrc.commands`.
|
|
6
6
|
*
|
|
7
7
|
* Stays framework-agnostic: resolves the live connection + dialect from atlas's
|
|
8
8
|
* OWN service locators (`getDb` / `getAtlasDialect`), never importing
|
|
9
|
-
* `@c9up/ream`. The {@link
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* `@c9up/ream`. The {@link AtlasCommandClass} shape structurally matches Ream's
|
|
10
|
+
* command contract, so the console kernel accepts it without a type dependency
|
|
11
|
+
* in either direction.
|
|
12
12
|
*/
|
|
13
13
|
import { getAtlasDialect } from "../query/native.js";
|
|
14
14
|
import { runSchemaCheck } from "../schema/SchemaCheck.js";
|
|
15
15
|
import { getDb } from "../services/db.js";
|
|
16
|
+
import { flag } from "./contract.js";
|
|
16
17
|
/**
|
|
17
18
|
* Build the `atlas:check` command for the given models. Register it in
|
|
18
19
|
* `reamrc.commands` (atlas has no global entity registry — list your models,
|
|
19
|
-
* as in Lucid). Run it
|
|
20
|
+
* as in Lucid). Run it as `ream atlas:check`; `--warn` reports drift without a
|
|
20
21
|
* non-zero exit (useful for an advisory CI step).
|
|
21
22
|
*
|
|
22
23
|
* @example
|
|
@@ -25,14 +26,19 @@ import { getDb } from "../services/db.js";
|
|
|
25
26
|
* import { User } from '#models/user'
|
|
26
27
|
* export default schemaCheckCommand([User])
|
|
27
28
|
*
|
|
28
|
-
* //
|
|
29
|
-
* // run: <console-entry> atlas:check
|
|
29
|
+
* // run: ream atlas:check --warn
|
|
30
30
|
*/
|
|
31
31
|
export function schemaCheckCommand(entities) {
|
|
32
|
-
return {
|
|
33
|
-
|
|
34
|
-
description
|
|
35
|
-
|
|
32
|
+
return class SchemaCheck {
|
|
33
|
+
static commandName = "atlas:check";
|
|
34
|
+
static description = "Verify models match the live database schema";
|
|
35
|
+
static options = { startApp: true };
|
|
36
|
+
static flags = [
|
|
37
|
+
flag("warn", "boolean", {
|
|
38
|
+
description: "Report drift without failing (exit 0)",
|
|
39
|
+
}),
|
|
40
|
+
];
|
|
41
|
+
async run() {
|
|
36
42
|
const db = getDb();
|
|
37
43
|
if (!db) {
|
|
38
44
|
console.error("[atlas:check] no database connection — is AtlasProvider registered?");
|
|
@@ -41,9 +47,9 @@ export function schemaCheckCommand(entities) {
|
|
|
41
47
|
}
|
|
42
48
|
const code = await runSchemaCheck(entities, db, getAtlasDialect());
|
|
43
49
|
// `--warn` downgrades drift to advisory (exit 0); default fails CI.
|
|
44
|
-
if (code !== 0 && !
|
|
50
|
+
if (code !== 0 && !this.warn)
|
|
45
51
|
process.exitCode = code;
|
|
46
|
-
}
|
|
52
|
+
}
|
|
47
53
|
};
|
|
48
54
|
}
|
|
49
55
|
//# sourceMappingURL=schemaCheckCommand.js.map
|