@warlock.js/cascade 5.7.0 → 5.9.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/CHANGELOG.md +14 -0
- package/cjs/index.cjs +59 -15
- package/cjs/index.cjs.map +1 -1
- package/esm/drivers/postgres/index.d.mts +1 -1
- package/esm/drivers/postgres/index.mjs +1 -1
- package/esm/drivers/postgres/postgres-driver.d.mts +18 -1
- package/esm/drivers/postgres/postgres-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-driver.mjs +35 -16
- package/esm/drivers/postgres/postgres-driver.mjs.map +1 -1
- package/esm/index.d.mts +2 -2
- package/esm/index.mjs +2 -2
- package/esm/migration/migration.d.mts +27 -0
- package/esm/migration/migration.d.mts.map +1 -1
- package/esm/migration/migration.mjs +24 -0
- package/esm/migration/migration.mjs.map +1 -1
- package/llms-full.txt +29 -0
- package/package.json +4 -4
- package/skills/write-migration/SKILL.md +29 -0
package/llms-full.txt
CHANGED
|
@@ -2771,6 +2771,35 @@ export default class BackfillStatuses extends Migration {
|
|
|
2771
2771
|
|
|
2772
2772
|
Class-form builders include `createTable()` / `createTableIfNotExists()`, `dropTable()` / `dropTableIfExists()`, `dropColumn(name)`, `renameTableTo(name)`, `timestamps()`, `index(...)`, `primaryUuid()`, and `raw(sql)` for a raw statement.
|
|
2773
2773
|
|
|
2774
|
+
### Foreign-key columns that match the app's PK type — `this.foreignId`
|
|
2775
|
+
|
|
2776
|
+
`this.foreignId(name)` (5.8+) derives the column's type from `migrationDefaults.primaryKey` so a foreign-key column always matches the type of the `id` it points at, instead of hardcoding one:
|
|
2777
|
+
|
|
2778
|
+
| `migrationDefaults.primaryKey` | `foreignId` produces |
|
|
2779
|
+
| --- | --- |
|
|
2780
|
+
| `uuid` | `uuid` column |
|
|
2781
|
+
| `bigInt` | `bigInteger` column |
|
|
2782
|
+
| anything else (default) | `integer` column |
|
|
2783
|
+
|
|
2784
|
+
```ts
|
|
2785
|
+
import { Migration } from "@warlock.js/cascade";
|
|
2786
|
+
|
|
2787
|
+
export default class AddUserToPosts extends Migration {
|
|
2788
|
+
public readonly table = "posts";
|
|
2789
|
+
|
|
2790
|
+
public async up(): Promise<void> {
|
|
2791
|
+
// uuid / bigInteger / integer, matching the app's chosen PK type
|
|
2792
|
+
this.foreignId("user_id").index();
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
public down(): void {
|
|
2796
|
+
this.dropColumn("user_id");
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
```
|
|
2800
|
+
|
|
2801
|
+
Reach for it on plain (non-`.references()`) FK id columns — e.g. a polymorphic `user_id` paired with a `user_type` — so a reference to a default-PK model is always type-compatible with that model's `id`.
|
|
2802
|
+
|
|
2774
2803
|
## Raw SQL migrations
|
|
2775
2804
|
|
|
2776
2805
|
For SQL-only changes (Postgres), `Migration.rawSql` builds a migration class for you:
|
package/package.json
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"@mongez/events": "^2.2.7",
|
|
14
14
|
"@mongez/reinforcements": "^4.0.1",
|
|
15
15
|
"@mongez/supportive-is": "^2.1.4",
|
|
16
|
-
"@warlock.js/context": "5.
|
|
17
|
-
"@warlock.js/logger": "5.
|
|
18
|
-
"@warlock.js/seal": "5.
|
|
16
|
+
"@warlock.js/context": "5.9.0",
|
|
17
|
+
"@warlock.js/logger": "5.9.0",
|
|
18
|
+
"@warlock.js/seal": "5.9.0",
|
|
19
19
|
"citty": "^0.2.2",
|
|
20
20
|
"fast-glob": "^3.3.3"
|
|
21
21
|
},
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"author": "hassanzohdy",
|
|
45
45
|
"license": "MIT",
|
|
46
|
-
"version": "5.
|
|
46
|
+
"version": "5.9.0",
|
|
47
47
|
"main": "./cjs/index.cjs",
|
|
48
48
|
"module": "./esm/index.mjs",
|
|
49
49
|
"types": "./esm/index.d.mts",
|
|
@@ -124,6 +124,35 @@ export default class BackfillStatuses extends Migration {
|
|
|
124
124
|
|
|
125
125
|
Class-form builders include `createTable()` / `createTableIfNotExists()`, `dropTable()` / `dropTableIfExists()`, `dropColumn(name)`, `renameTableTo(name)`, `timestamps()`, `index(...)`, `primaryUuid()`, and `raw(sql)` for a raw statement.
|
|
126
126
|
|
|
127
|
+
### Foreign-key columns that match the app's PK type — `this.foreignId`
|
|
128
|
+
|
|
129
|
+
`this.foreignId(name)` (5.8+) derives the column's type from `migrationDefaults.primaryKey` so a foreign-key column always matches the type of the `id` it points at, instead of hardcoding one:
|
|
130
|
+
|
|
131
|
+
| `migrationDefaults.primaryKey` | `foreignId` produces |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| `uuid` | `uuid` column |
|
|
134
|
+
| `bigInt` | `bigInteger` column |
|
|
135
|
+
| anything else (default) | `integer` column |
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { Migration } from "@warlock.js/cascade";
|
|
139
|
+
|
|
140
|
+
export default class AddUserToPosts extends Migration {
|
|
141
|
+
public readonly table = "posts";
|
|
142
|
+
|
|
143
|
+
public async up(): Promise<void> {
|
|
144
|
+
// uuid / bigInteger / integer, matching the app's chosen PK type
|
|
145
|
+
this.foreignId("user_id").index();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public down(): void {
|
|
149
|
+
this.dropColumn("user_id");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Reach for it on plain (non-`.references()`) FK id columns — e.g. a polymorphic `user_id` paired with a `user_type` — so a reference to a default-PK model is always type-compatible with that model's `id`.
|
|
155
|
+
|
|
127
156
|
## Raw SQL migrations
|
|
128
157
|
|
|
129
158
|
For SQL-only changes (Postgres), `Migration.rawSql` builds a migration class for you:
|