@anarchitects/nx-typeorm 0.2.0 → 0.3.0

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 CHANGED
@@ -100,6 +100,38 @@ nx g @anarchitects/nx-typeorm:migration --project=api --name="add users"
100
100
  - app: `tools/typeorm/migrations`
101
101
  - lib: `src/infrastructure-persistence/migrations`
102
102
 
103
+ `migration-api` (alias: `migration-api-lib`)
104
+
105
+ ```bash
106
+ nx g @anarchitects/nx-typeorm:migration-api --project=data-access --name="init users"
107
+ nx g @anarchitects/nx-typeorm:migration-api-lib --project=data-access --name="init users"
108
+ ```
109
+
110
+ - library-only generator (fails for applications)
111
+ - generates migration files using TypeORM migration API (`QueryRunner`, `Table`,
112
+ `TableColumn`, etc.) without raw SQL strings
113
+ - maintains migration state in
114
+ `src/infrastructure-persistence/migrations/.nx-typeorm-migration-manifest.json`
115
+ - default behavior:
116
+ - no file when entity snapshot is unchanged
117
+ - new consolidated delta migration when entities changed
118
+ - options:
119
+ - required: `--project`
120
+ - required in `fileMode=new` (default): `--name`
121
+ - optional: `--fileMode=new|patch-init` (default `new`)
122
+ - optional: `--entityGlob=<glob-relative-to-project-root>`
123
+ (default `src/infrastructure-persistence/entities/**/*.ts`)
124
+ - optional: `--allowMixedMigrations` to opt into mixed manual/tool migration
125
+ directories
126
+ - optional: `--timestamp=<number>`
127
+ - safety behavior:
128
+ - fails on unsupported/unresolvable decorators/options
129
+ - fails when implicit naming cannot be resolved safely
130
+ - fails on rename-like table/column diffs (manual migration required)
131
+ - `patch-init` only patches bootstrap init migration
132
+ `1700000000000_init_schema.ts` and is only allowed before any generated
133
+ delta migration exists
134
+
103
135
  `entity-create` (alias: `entity`)
104
136
 
105
137
  ```bash
@@ -1,12 +1,16 @@
1
- import { MigrationInterface, QueryRunner } from 'typeorm';
1
+ import { MigrationInterface, QueryRunner, Table, TableCheck, TableColumn, TableExclusion, TableForeignKey, TableIndex, TableUnique } from 'typeorm';
2
2
  import { <%= className %>_SCHEMA as SCHEMA } from '../schema';
3
3
 
4
4
  export class Init<%= className %>Schema1700000000000 implements MigrationInterface {
5
- async up(q: QueryRunner): Promise<void> {
6
- await q.query(`CREATE SCHEMA IF NOT EXISTS "${SCHEMA}"`);
5
+ async up(queryRunner: QueryRunner): Promise<void> {
6
+ await queryRunner.createSchema(SCHEMA, true);
7
+ // nx-typeorm:migration-api:up:start
8
+ // nx-typeorm:migration-api:up:end
7
9
  }
8
10
 
9
11
  async down(): Promise<void> {
12
+ // nx-typeorm:migration-api:down:start
13
+ // nx-typeorm:migration-api:down:end
10
14
  // Schema intentionally kept
11
15
  }
12
16
  }
@@ -0,0 +1,4 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import type { MigrationApiGeneratorSchema } from './schema.js';
3
+ export default function migrationApiGenerator(tree: Tree, options: MigrationApiGeneratorSchema): Promise<void>;
4
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/migration-api/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAkBpB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAwM/D,wBAA8B,qBAAqB,CACjD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,2BAA2B,iBA2IrC"}