@warlock.js/cascade 4.0.60 → 4.0.88
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/cjs/contracts/driver-blueprint.contract.d.ts +4 -0
- package/cjs/contracts/driver-blueprint.contract.d.ts.map +1 -1
- package/cjs/drivers/mongo/mongodb-driver.d.ts.map +1 -1
- package/cjs/drivers/mongo/mongodb-driver.js +49 -1
- package/cjs/drivers/mongo/mongodb-driver.js.map +1 -1
- package/cjs/migration/migration.d.ts +1143 -0
- package/cjs/migration/migration.d.ts.map +1 -0
- package/cjs/migration/migration.js.map +1 -1
- package/cjs/model/model.d.ts +2 -4
- package/cjs/model/model.d.ts.map +1 -1
- package/cjs/model/model.js +0 -2
- package/cjs/model/model.js.map +1 -1
- package/cjs/utils/define-model.d.ts +372 -0
- package/cjs/utils/define-model.d.ts.map +1 -0
- package/esm/contracts/driver-blueprint.contract.d.ts +4 -0
- package/esm/contracts/driver-blueprint.contract.d.ts.map +1 -1
- package/esm/drivers/mongo/mongodb-driver.d.ts.map +1 -1
- package/esm/drivers/mongo/mongodb-driver.js +49 -1
- package/esm/drivers/mongo/mongodb-driver.js.map +1 -1
- package/esm/migration/migration.d.ts +1143 -0
- package/esm/migration/migration.d.ts.map +1 -0
- package/esm/migration/migration.js.map +1 -1
- package/esm/model/model.d.ts +2 -4
- package/esm/model/model.d.ts.map +1 -1
- package/esm/model/model.js +0 -2
- package/esm/model/model.js.map +1 -1
- package/esm/utils/define-model.d.ts +372 -0
- package/esm/utils/define-model.d.ts.map +1 -0
- package/package.json +5 -15
|
@@ -0,0 +1,1143 @@
|
|
|
1
|
+
import type { ForeignKeyDefinition, FullTextIndexOptions, GeoIndexOptions, IndexDefinition, MigrationDriverContract, VectorIndexOptions } from "../contracts/migration-driver.contract";
|
|
2
|
+
import type { DataSource } from "../data-source/data-source";
|
|
3
|
+
import type { ChildModel, Model } from "../model/model";
|
|
4
|
+
import { ColumnBuilder } from "./column-builder";
|
|
5
|
+
import { ForeignKeyBuilder } from "./foreign-key-builder";
|
|
6
|
+
/**
|
|
7
|
+
* Contract for a migration class.
|
|
8
|
+
*/
|
|
9
|
+
export interface MigrationContract {
|
|
10
|
+
/**
|
|
11
|
+
* Table/collection name for this migration.
|
|
12
|
+
*/
|
|
13
|
+
readonly table: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional data source override.
|
|
16
|
+
*/
|
|
17
|
+
readonly dataSource?: string | DataSource;
|
|
18
|
+
/**
|
|
19
|
+
* Optional timestamp override.
|
|
20
|
+
*/
|
|
21
|
+
readonly createdAt?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Whether to wrap migration in a transaction.
|
|
24
|
+
*/
|
|
25
|
+
readonly transactional?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Define schema changes for the up migration.
|
|
28
|
+
*/
|
|
29
|
+
up(): void | Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Define rollback operations for the down migration.
|
|
32
|
+
*/
|
|
33
|
+
down(): void | Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Set the migration driver.
|
|
36
|
+
*
|
|
37
|
+
* @param driver - Migration driver instance
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
setDriver(driver: MigrationDriverContract): void;
|
|
41
|
+
/**
|
|
42
|
+
* Get the migration driver.
|
|
43
|
+
*
|
|
44
|
+
* @returns The migration driver instance
|
|
45
|
+
*/
|
|
46
|
+
getDriver(): MigrationDriverContract;
|
|
47
|
+
/**
|
|
48
|
+
* Execute all pending operations.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
execute(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Add a pending index definition.
|
|
55
|
+
*
|
|
56
|
+
* @param index - Index definition
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
addPendingIndex(index: IndexDefinition): void;
|
|
60
|
+
/**
|
|
61
|
+
* Add a foreign key operation.
|
|
62
|
+
*
|
|
63
|
+
* @param fk - Foreign key definition
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
addForeignKeyOperation(fk: ForeignKeyDefinition): void;
|
|
67
|
+
/**
|
|
68
|
+
* Create the table/collection.
|
|
69
|
+
*/
|
|
70
|
+
createTable(): MigrationContract;
|
|
71
|
+
/**
|
|
72
|
+
* Create table if not exists
|
|
73
|
+
*/
|
|
74
|
+
createTableIfNotExists(): MigrationContract;
|
|
75
|
+
/**
|
|
76
|
+
* Drop the table/collection.
|
|
77
|
+
*/
|
|
78
|
+
dropTable(): MigrationContract;
|
|
79
|
+
/**
|
|
80
|
+
* Drop the table/collection if it exists.
|
|
81
|
+
*/
|
|
82
|
+
dropTableIfExists(): MigrationContract;
|
|
83
|
+
/**
|
|
84
|
+
* Rename the table/collection.
|
|
85
|
+
*
|
|
86
|
+
* @param newName - New table name
|
|
87
|
+
*/
|
|
88
|
+
renameTableTo(newName: string): MigrationContract;
|
|
89
|
+
/**
|
|
90
|
+
* Add a string/varchar column.
|
|
91
|
+
*/
|
|
92
|
+
string(column: string, length?: number): ColumnBuilder;
|
|
93
|
+
/**
|
|
94
|
+
* Add a fixed-length char column.
|
|
95
|
+
*/
|
|
96
|
+
char(column: string, length: number): ColumnBuilder;
|
|
97
|
+
/**
|
|
98
|
+
* Add a text column (unlimited length).
|
|
99
|
+
*/
|
|
100
|
+
text(column: string): ColumnBuilder;
|
|
101
|
+
/**
|
|
102
|
+
* Add a medium text column.
|
|
103
|
+
*/
|
|
104
|
+
mediumText(column: string): ColumnBuilder;
|
|
105
|
+
/**
|
|
106
|
+
* Add a long text column.
|
|
107
|
+
*/
|
|
108
|
+
longText(column: string): ColumnBuilder;
|
|
109
|
+
/**
|
|
110
|
+
* Add an integer column.
|
|
111
|
+
*/
|
|
112
|
+
integer(column: string): ColumnBuilder;
|
|
113
|
+
/**
|
|
114
|
+
* Alias for integer().
|
|
115
|
+
*/
|
|
116
|
+
int(column: string): ColumnBuilder;
|
|
117
|
+
/**
|
|
118
|
+
* Add a small integer column.
|
|
119
|
+
*/
|
|
120
|
+
smallInteger(column: string): ColumnBuilder;
|
|
121
|
+
/**
|
|
122
|
+
* Alias for smallInteger().
|
|
123
|
+
*/
|
|
124
|
+
smallInt(column: string): ColumnBuilder;
|
|
125
|
+
/**
|
|
126
|
+
* Add a tiny integer column.
|
|
127
|
+
*/
|
|
128
|
+
tinyInteger(column: string): ColumnBuilder;
|
|
129
|
+
/**
|
|
130
|
+
* Alias for tinyInteger().
|
|
131
|
+
*/
|
|
132
|
+
tinyInt(column: string): ColumnBuilder;
|
|
133
|
+
/**
|
|
134
|
+
* Add a big integer column.
|
|
135
|
+
*/
|
|
136
|
+
bigInteger(column: string): ColumnBuilder;
|
|
137
|
+
/**
|
|
138
|
+
* Alias for bigInteger().
|
|
139
|
+
*/
|
|
140
|
+
bigInt(column: string): ColumnBuilder;
|
|
141
|
+
/**
|
|
142
|
+
* Add a float column.
|
|
143
|
+
*/
|
|
144
|
+
float(column: string): ColumnBuilder;
|
|
145
|
+
/**
|
|
146
|
+
* Add a double precision column.
|
|
147
|
+
*/
|
|
148
|
+
double(column: string): ColumnBuilder;
|
|
149
|
+
/**
|
|
150
|
+
* Add a decimal column with precision and scale.
|
|
151
|
+
*/
|
|
152
|
+
decimal(column: string, precision?: number, scale?: number): ColumnBuilder;
|
|
153
|
+
/**
|
|
154
|
+
* Add a boolean column.
|
|
155
|
+
*/
|
|
156
|
+
boolean(column: string): ColumnBuilder;
|
|
157
|
+
/**
|
|
158
|
+
* Alias for boolean().
|
|
159
|
+
*/
|
|
160
|
+
bool(column: string): ColumnBuilder;
|
|
161
|
+
/**
|
|
162
|
+
* Add a date column (date only, no time).
|
|
163
|
+
*/
|
|
164
|
+
date(column: string): ColumnBuilder;
|
|
165
|
+
/**
|
|
166
|
+
* Add a datetime column (date and time).
|
|
167
|
+
*/
|
|
168
|
+
dateTime(column: string): ColumnBuilder;
|
|
169
|
+
/**
|
|
170
|
+
* Add a timestamp column.
|
|
171
|
+
*/
|
|
172
|
+
timestamp(column: string): ColumnBuilder;
|
|
173
|
+
/**
|
|
174
|
+
* Add a time column (time only, no date).
|
|
175
|
+
*/
|
|
176
|
+
time(column: string): ColumnBuilder;
|
|
177
|
+
/**
|
|
178
|
+
* Add a year column.
|
|
179
|
+
*/
|
|
180
|
+
year(column: string): ColumnBuilder;
|
|
181
|
+
/**
|
|
182
|
+
* Add a JSON column.
|
|
183
|
+
*/
|
|
184
|
+
json(column: string): ColumnBuilder;
|
|
185
|
+
/**
|
|
186
|
+
* Alias for json().
|
|
187
|
+
*/
|
|
188
|
+
object(column: string): ColumnBuilder;
|
|
189
|
+
/**
|
|
190
|
+
* Add a binary/blob column.
|
|
191
|
+
*/
|
|
192
|
+
binary(column: string): ColumnBuilder;
|
|
193
|
+
/**
|
|
194
|
+
* Alias for binary().
|
|
195
|
+
*/
|
|
196
|
+
blob(column: string): ColumnBuilder;
|
|
197
|
+
/**
|
|
198
|
+
* Add a UUID column.
|
|
199
|
+
*/
|
|
200
|
+
uuid(column: string): ColumnBuilder;
|
|
201
|
+
/**
|
|
202
|
+
* Add a ULID column.
|
|
203
|
+
*/
|
|
204
|
+
ulid(column: string): ColumnBuilder;
|
|
205
|
+
/**
|
|
206
|
+
* Add an IP address column.
|
|
207
|
+
*/
|
|
208
|
+
ipAddress(column: string): ColumnBuilder;
|
|
209
|
+
/**
|
|
210
|
+
* Add a MAC address column.
|
|
211
|
+
*/
|
|
212
|
+
macAddress(column: string): ColumnBuilder;
|
|
213
|
+
/**
|
|
214
|
+
* Add a geo point column.
|
|
215
|
+
*/
|
|
216
|
+
point(column: string): ColumnBuilder;
|
|
217
|
+
/**
|
|
218
|
+
* Add a polygon column.
|
|
219
|
+
*/
|
|
220
|
+
polygon(column: string): ColumnBuilder;
|
|
221
|
+
/**
|
|
222
|
+
* Add a line string column.
|
|
223
|
+
*/
|
|
224
|
+
lineString(column: string): ColumnBuilder;
|
|
225
|
+
/**
|
|
226
|
+
* Add a generic geometry column.
|
|
227
|
+
*/
|
|
228
|
+
geometry(column: string): ColumnBuilder;
|
|
229
|
+
/**
|
|
230
|
+
* Add a vector column for AI embeddings.
|
|
231
|
+
*/
|
|
232
|
+
vector(column: string, dimensions: number): ColumnBuilder;
|
|
233
|
+
/**
|
|
234
|
+
* Add an enum column with allowed values.
|
|
235
|
+
*/
|
|
236
|
+
enum(column: string, values: string[]): ColumnBuilder;
|
|
237
|
+
/**
|
|
238
|
+
* Add a set column (multiple values from a set).
|
|
239
|
+
*/
|
|
240
|
+
set(column: string, values: string[]): ColumnBuilder;
|
|
241
|
+
/**
|
|
242
|
+
* Add an auto-increment primary key column.
|
|
243
|
+
*/
|
|
244
|
+
id(name?: string): ColumnBuilder;
|
|
245
|
+
/**
|
|
246
|
+
* Add a big integer auto-increment primary key column.
|
|
247
|
+
*/
|
|
248
|
+
bigId(name?: string): ColumnBuilder;
|
|
249
|
+
/**
|
|
250
|
+
* Add a UUID primary key column.
|
|
251
|
+
*/
|
|
252
|
+
uuidId(name?: string): ColumnBuilder;
|
|
253
|
+
/**
|
|
254
|
+
* Add createdAt and updatedAt timestamp columns.
|
|
255
|
+
*/
|
|
256
|
+
timestamps(): MigrationContract;
|
|
257
|
+
/**
|
|
258
|
+
* Add a deletedAt column for soft deletes.
|
|
259
|
+
*/
|
|
260
|
+
softDeletes(column?: string): ColumnBuilder;
|
|
261
|
+
/**
|
|
262
|
+
* Drop a column.
|
|
263
|
+
*/
|
|
264
|
+
dropColumn(column: string): MigrationContract;
|
|
265
|
+
/**
|
|
266
|
+
* Drop multiple columns.
|
|
267
|
+
*/
|
|
268
|
+
dropColumns(...columns: string[]): MigrationContract;
|
|
269
|
+
/**
|
|
270
|
+
* Rename a column.
|
|
271
|
+
*/
|
|
272
|
+
renameColumn(from: string, to: string): MigrationContract;
|
|
273
|
+
/**
|
|
274
|
+
* Create an index on one or more columns.
|
|
275
|
+
*/
|
|
276
|
+
index(columns: string | string[], name?: string): MigrationContract;
|
|
277
|
+
/**
|
|
278
|
+
* Drop an index by name or columns.
|
|
279
|
+
*/
|
|
280
|
+
dropIndex(nameOrColumns: string | string[]): MigrationContract;
|
|
281
|
+
/**
|
|
282
|
+
* Create a unique constraint/index.
|
|
283
|
+
*/
|
|
284
|
+
unique(columns: string | string[], name?: string): MigrationContract;
|
|
285
|
+
/**
|
|
286
|
+
* Drop a unique constraint/index.
|
|
287
|
+
*/
|
|
288
|
+
dropUnique(columns: string | string[]): MigrationContract;
|
|
289
|
+
/**
|
|
290
|
+
* Create a full-text search index.
|
|
291
|
+
*/
|
|
292
|
+
fullText(columns: string | string[], options?: FullTextIndexOptions): MigrationContract;
|
|
293
|
+
/**
|
|
294
|
+
* Drop a full-text search index.
|
|
295
|
+
*/
|
|
296
|
+
dropFullText(name: string): MigrationContract;
|
|
297
|
+
/**
|
|
298
|
+
* Create a geo-spatial index.
|
|
299
|
+
*/
|
|
300
|
+
geoIndex(column: string, options?: GeoIndexOptions): MigrationContract;
|
|
301
|
+
/**
|
|
302
|
+
* Drop a geo-spatial index.
|
|
303
|
+
*/
|
|
304
|
+
dropGeoIndex(column: string): MigrationContract;
|
|
305
|
+
/**
|
|
306
|
+
* Create a vector search index for AI embeddings.
|
|
307
|
+
*/
|
|
308
|
+
vectorIndex(column: string, options: VectorIndexOptions): MigrationContract;
|
|
309
|
+
/**
|
|
310
|
+
* Drop a vector search index.
|
|
311
|
+
*/
|
|
312
|
+
dropVectorIndex(column: string): MigrationContract;
|
|
313
|
+
/**
|
|
314
|
+
* Create a TTL (time-to-live) index for automatic document expiration.
|
|
315
|
+
*/
|
|
316
|
+
ttlIndex(column: string, expireAfterSeconds: number): MigrationContract;
|
|
317
|
+
/**
|
|
318
|
+
* Drop a TTL index.
|
|
319
|
+
*/
|
|
320
|
+
dropTTLIndex(column: string): MigrationContract;
|
|
321
|
+
/**
|
|
322
|
+
* Add a composite primary key.
|
|
323
|
+
*/
|
|
324
|
+
primaryKey(columns: string[]): MigrationContract;
|
|
325
|
+
/**
|
|
326
|
+
* Drop the primary key constraint.
|
|
327
|
+
*/
|
|
328
|
+
dropPrimaryKey(): MigrationContract;
|
|
329
|
+
/**
|
|
330
|
+
* Start building a foreign key constraint.
|
|
331
|
+
*/
|
|
332
|
+
foreign(column: string): ForeignKeyBuilder;
|
|
333
|
+
/**
|
|
334
|
+
* Drop a foreign key constraint by name.
|
|
335
|
+
*/
|
|
336
|
+
dropForeign(name: string): MigrationContract;
|
|
337
|
+
/**
|
|
338
|
+
* Set JSON schema validation rules on the collection.
|
|
339
|
+
*/
|
|
340
|
+
schemaValidation(schema: object): MigrationContract;
|
|
341
|
+
/**
|
|
342
|
+
* Remove schema validation rules from the collection.
|
|
343
|
+
*/
|
|
344
|
+
dropSchemaValidation(): MigrationContract;
|
|
345
|
+
/**
|
|
346
|
+
* Execute raw operations with direct driver access.
|
|
347
|
+
*/
|
|
348
|
+
raw<T>(callback: (connection: unknown) => Promise<T>): Promise<T>;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Constructor for the migration class.
|
|
352
|
+
*/
|
|
353
|
+
export interface MigrationConstructor {
|
|
354
|
+
new (): MigrationContract;
|
|
355
|
+
migrationName?: string;
|
|
356
|
+
createdAt?: string;
|
|
357
|
+
transactional?: boolean;
|
|
358
|
+
order?: number;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Base class for all database migrations.
|
|
362
|
+
*
|
|
363
|
+
* Provides a fluent API for defining schema changes that work across
|
|
364
|
+
* both SQL and NoSQL databases. The migration driver handles translating
|
|
365
|
+
* operations to native database commands.
|
|
366
|
+
*
|
|
367
|
+
* Migrations are executed in order based on their `createdAt` timestamp,
|
|
368
|
+
* which is typically extracted from the filename (e.g., `2024-01-15_create-users`).
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```typescript
|
|
372
|
+
* // Using Migration.for() to bind to a model
|
|
373
|
+
* export default class extends Migration.for(User) {
|
|
374
|
+
* public up(): void {
|
|
375
|
+
* this.string("email").unique();
|
|
376
|
+
* this.integer("age").nullable();
|
|
377
|
+
* this.geoIndex("location");
|
|
378
|
+
* }
|
|
379
|
+
*
|
|
380
|
+
* public down(): void {
|
|
381
|
+
* this.dropColumn("email");
|
|
382
|
+
* this.dropColumn("age");
|
|
383
|
+
* this.dropGeoIndex("location");
|
|
384
|
+
* }
|
|
385
|
+
* }
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* // Manual table migration (without model binding)
|
|
391
|
+
* export default class CreateUsersTable extends Migration {
|
|
392
|
+
* public readonly table = "users";
|
|
393
|
+
*
|
|
394
|
+
* public up(): void {
|
|
395
|
+
* this.createTable();
|
|
396
|
+
* this.id();
|
|
397
|
+
* this.string("name");
|
|
398
|
+
* this.string("email").unique();
|
|
399
|
+
* this.timestamps();
|
|
400
|
+
* }
|
|
401
|
+
*
|
|
402
|
+
* public down(): void {
|
|
403
|
+
* this.dropTable();
|
|
404
|
+
* }
|
|
405
|
+
* }
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
export declare abstract class Migration implements MigrationContract {
|
|
409
|
+
/**
|
|
410
|
+
* Migration name that will be labeled with
|
|
411
|
+
* If record is enabled in migration, it will be stored as migration name
|
|
412
|
+
* in database
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* "2024-01-15_create-users";
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
static migrationName?: string;
|
|
420
|
+
/**
|
|
421
|
+
* Table/collection name for this migration.
|
|
422
|
+
*
|
|
423
|
+
* Must be defined by each migration class (either directly or via `Migration.for()`).
|
|
424
|
+
*/
|
|
425
|
+
readonly table: string;
|
|
426
|
+
/**
|
|
427
|
+
* Sort order
|
|
428
|
+
* If not provided, it will be ordered alphabetically
|
|
429
|
+
*/
|
|
430
|
+
static readonly order?: number;
|
|
431
|
+
/**
|
|
432
|
+
* Optional data source override.
|
|
433
|
+
*
|
|
434
|
+
* If specified, this migration will use a specific data source
|
|
435
|
+
* instead of the default one. Can be a string name or DataSource instance.
|
|
436
|
+
*/
|
|
437
|
+
readonly dataSource?: string | DataSource;
|
|
438
|
+
/**
|
|
439
|
+
* Optional timestamp override.
|
|
440
|
+
*
|
|
441
|
+
* By default, the migration runner extracts this from the filename.
|
|
442
|
+
* Set explicitly to override the execution order.
|
|
443
|
+
*
|
|
444
|
+
* Format: ISO 8601 or any parseable date string.
|
|
445
|
+
*/
|
|
446
|
+
readonly createdAt?: string;
|
|
447
|
+
/**
|
|
448
|
+
* Whether to wrap migration in a transaction.
|
|
449
|
+
*
|
|
450
|
+
* Defaults to `true` for SQL databases that support DDL transactions.
|
|
451
|
+
* Set to `false` for operations that cannot be transactional.
|
|
452
|
+
*
|
|
453
|
+
* Note: MongoDB does not support transactions for most DDL operations.
|
|
454
|
+
*/
|
|
455
|
+
readonly transactional?: boolean;
|
|
456
|
+
/**
|
|
457
|
+
* Migration driver instance (injected by the runner).
|
|
458
|
+
*/
|
|
459
|
+
protected driver: MigrationDriverContract;
|
|
460
|
+
/**
|
|
461
|
+
* Queued operations to execute.
|
|
462
|
+
*/
|
|
463
|
+
private readonly pendingOperations;
|
|
464
|
+
/**
|
|
465
|
+
* Pending indexes from column builders.
|
|
466
|
+
*/
|
|
467
|
+
private readonly pendingIndexes;
|
|
468
|
+
/**
|
|
469
|
+
* Define schema changes for the up migration.
|
|
470
|
+
*
|
|
471
|
+
* Called when running migrations forward. Add columns, indexes,
|
|
472
|
+
* constraints, etc. in this method.
|
|
473
|
+
*/
|
|
474
|
+
abstract up(): void | Promise<void>;
|
|
475
|
+
/**
|
|
476
|
+
* Define rollback operations for the down migration.
|
|
477
|
+
*
|
|
478
|
+
* Called when rolling back migrations. Drop columns, indexes,
|
|
479
|
+
* and undo any changes made in `up()`.
|
|
480
|
+
*/
|
|
481
|
+
abstract down(): void | Promise<void>;
|
|
482
|
+
/**
|
|
483
|
+
* Create a migration class bound to a specific model.
|
|
484
|
+
*
|
|
485
|
+
* Automatically inherits the model's table name and data source,
|
|
486
|
+
* reducing boilerplate and ensuring consistency.
|
|
487
|
+
*
|
|
488
|
+
* @param model - Model class to bind
|
|
489
|
+
* @returns Abstract migration class bound to the model
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```typescript
|
|
493
|
+
* export default class extends Migration.for(User) {
|
|
494
|
+
* public up(): void {
|
|
495
|
+
* this.string("avatar").nullable();
|
|
496
|
+
* }
|
|
497
|
+
*
|
|
498
|
+
* public down(): void {
|
|
499
|
+
* this.dropColumn("avatar");
|
|
500
|
+
* }
|
|
501
|
+
* }
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
static for<T extends ChildModel<Model>>(model: T): MigrationConstructor;
|
|
505
|
+
/**
|
|
506
|
+
* Set the migration driver.
|
|
507
|
+
*
|
|
508
|
+
* Called by the migration runner before executing up/down.
|
|
509
|
+
*
|
|
510
|
+
* @param driver - Migration driver instance
|
|
511
|
+
* @internal
|
|
512
|
+
*/
|
|
513
|
+
setDriver(driver: MigrationDriverContract): void;
|
|
514
|
+
/**
|
|
515
|
+
* Get the migration driver.
|
|
516
|
+
*
|
|
517
|
+
* @returns The migration driver instance
|
|
518
|
+
*/
|
|
519
|
+
getDriver(): MigrationDriverContract;
|
|
520
|
+
/**
|
|
521
|
+
* Execute all pending operations.
|
|
522
|
+
*
|
|
523
|
+
* Called by the migration runner after up() or down() completes.
|
|
524
|
+
* Executes operations in the order they were defined.
|
|
525
|
+
*
|
|
526
|
+
* @internal
|
|
527
|
+
*/
|
|
528
|
+
execute(): Promise<void>;
|
|
529
|
+
/**
|
|
530
|
+
* Execute a single pending operation.
|
|
531
|
+
*/
|
|
532
|
+
private executeOperation;
|
|
533
|
+
/**
|
|
534
|
+
* Add a pending index definition.
|
|
535
|
+
*
|
|
536
|
+
* Called by ColumnBuilder when .unique() or .index() is chained.
|
|
537
|
+
*
|
|
538
|
+
* @param index - Index definition
|
|
539
|
+
* @internal
|
|
540
|
+
*/
|
|
541
|
+
addPendingIndex(index: IndexDefinition): void;
|
|
542
|
+
/**
|
|
543
|
+
* Add a foreign key operation.
|
|
544
|
+
*
|
|
545
|
+
* Called by ForeignKeyBuilder when .add() is called.
|
|
546
|
+
*
|
|
547
|
+
* @param fk - Foreign key definition
|
|
548
|
+
* @internal
|
|
549
|
+
*/
|
|
550
|
+
addForeignKeyOperation(fk: ForeignKeyDefinition): void;
|
|
551
|
+
/**
|
|
552
|
+
* Create the table/collection.
|
|
553
|
+
*
|
|
554
|
+
* For SQL, this creates an empty table.
|
|
555
|
+
* For MongoDB, this creates the collection.
|
|
556
|
+
*
|
|
557
|
+
* @returns This migration for chaining
|
|
558
|
+
*/
|
|
559
|
+
createTable(): this;
|
|
560
|
+
/**
|
|
561
|
+
* Create table if not exists
|
|
562
|
+
*/
|
|
563
|
+
createTableIfNotExists(): this;
|
|
564
|
+
/**
|
|
565
|
+
* Drop the table/collection.
|
|
566
|
+
*
|
|
567
|
+
* @returns This migration for chaining
|
|
568
|
+
*/
|
|
569
|
+
dropTable(): this;
|
|
570
|
+
/**
|
|
571
|
+
* Drop the table/collection if it exists.
|
|
572
|
+
*
|
|
573
|
+
* No error is thrown if the table doesn't exist.
|
|
574
|
+
*
|
|
575
|
+
* @returns This migration for chaining
|
|
576
|
+
*/
|
|
577
|
+
dropTableIfExists(): this;
|
|
578
|
+
/**
|
|
579
|
+
* Rename the table/collection.
|
|
580
|
+
*
|
|
581
|
+
* @param newName - New table name
|
|
582
|
+
* @returns This migration for chaining
|
|
583
|
+
*/
|
|
584
|
+
renameTableTo(newName: string): this;
|
|
585
|
+
/**
|
|
586
|
+
* Add a string/varchar column.
|
|
587
|
+
*
|
|
588
|
+
* @param column - Column name
|
|
589
|
+
* @param length - Max length (default: 255)
|
|
590
|
+
* @returns Column builder for chaining modifiers
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* ```typescript
|
|
594
|
+
* this.string("name"); // VARCHAR(255)
|
|
595
|
+
* this.string("code", 10); // VARCHAR(10)
|
|
596
|
+
* ```
|
|
597
|
+
*/
|
|
598
|
+
string(column: string, length?: number): ColumnBuilder;
|
|
599
|
+
/**
|
|
600
|
+
* Add a fixed-length char column.
|
|
601
|
+
*
|
|
602
|
+
* @param column - Column name
|
|
603
|
+
* @param length - Exact length
|
|
604
|
+
* @returns Column builder for chaining modifiers
|
|
605
|
+
*/
|
|
606
|
+
char(column: string, length: number): ColumnBuilder;
|
|
607
|
+
/**
|
|
608
|
+
* Add a text column (unlimited length).
|
|
609
|
+
*
|
|
610
|
+
* @param column - Column name
|
|
611
|
+
* @returns Column builder for chaining modifiers
|
|
612
|
+
*/
|
|
613
|
+
text(column: string): ColumnBuilder;
|
|
614
|
+
/**
|
|
615
|
+
* Add a medium text column.
|
|
616
|
+
*
|
|
617
|
+
* @param column - Column name
|
|
618
|
+
* @returns Column builder for chaining modifiers
|
|
619
|
+
*/
|
|
620
|
+
mediumText(column: string): ColumnBuilder;
|
|
621
|
+
/**
|
|
622
|
+
* Add a long text column.
|
|
623
|
+
*
|
|
624
|
+
* @param column - Column name
|
|
625
|
+
* @returns Column builder for chaining modifiers
|
|
626
|
+
*/
|
|
627
|
+
longText(column: string): ColumnBuilder;
|
|
628
|
+
/**
|
|
629
|
+
* Add an integer column.
|
|
630
|
+
*
|
|
631
|
+
* @param column - Column name
|
|
632
|
+
* @returns Column builder for chaining modifiers
|
|
633
|
+
*/
|
|
634
|
+
integer(column: string): ColumnBuilder;
|
|
635
|
+
/**
|
|
636
|
+
* Alias for integer().
|
|
637
|
+
*/
|
|
638
|
+
int(column: string): ColumnBuilder;
|
|
639
|
+
/**
|
|
640
|
+
* Add a small integer column.
|
|
641
|
+
*
|
|
642
|
+
* @param column - Column name
|
|
643
|
+
* @returns Column builder for chaining modifiers
|
|
644
|
+
*/
|
|
645
|
+
smallInteger(column: string): ColumnBuilder;
|
|
646
|
+
/**
|
|
647
|
+
* Alias for smallInteger().
|
|
648
|
+
*/
|
|
649
|
+
smallInt(column: string): ColumnBuilder;
|
|
650
|
+
/**
|
|
651
|
+
* Add a tiny integer column.
|
|
652
|
+
*
|
|
653
|
+
* @param column - Column name
|
|
654
|
+
* @returns Column builder for chaining modifiers
|
|
655
|
+
*/
|
|
656
|
+
tinyInteger(column: string): ColumnBuilder;
|
|
657
|
+
/**
|
|
658
|
+
* Alias for tinyInteger().
|
|
659
|
+
*/
|
|
660
|
+
tinyInt(column: string): ColumnBuilder;
|
|
661
|
+
/**
|
|
662
|
+
* Add a big integer column.
|
|
663
|
+
*
|
|
664
|
+
* @param column - Column name
|
|
665
|
+
* @returns Column builder for chaining modifiers
|
|
666
|
+
*/
|
|
667
|
+
bigInteger(column: string): ColumnBuilder;
|
|
668
|
+
/**
|
|
669
|
+
* Alias for bigInteger().
|
|
670
|
+
*/
|
|
671
|
+
bigInt(column: string): ColumnBuilder;
|
|
672
|
+
/**
|
|
673
|
+
* Add a float column.
|
|
674
|
+
*
|
|
675
|
+
* @param column - Column name
|
|
676
|
+
* @returns Column builder for chaining modifiers
|
|
677
|
+
*/
|
|
678
|
+
float(column: string): ColumnBuilder;
|
|
679
|
+
/**
|
|
680
|
+
* Add a double precision column.
|
|
681
|
+
*
|
|
682
|
+
* @param column - Column name
|
|
683
|
+
* @returns Column builder for chaining modifiers
|
|
684
|
+
*/
|
|
685
|
+
double(column: string): ColumnBuilder;
|
|
686
|
+
/**
|
|
687
|
+
* Add a decimal column with precision and scale.
|
|
688
|
+
*
|
|
689
|
+
* @param column - Column name
|
|
690
|
+
* @param precision - Total digits (default: 8)
|
|
691
|
+
* @param scale - Decimal places (default: 2)
|
|
692
|
+
* @returns Column builder for chaining modifiers
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```typescript
|
|
696
|
+
* this.decimal("price", 10, 2); // DECIMAL(10,2) - up to 99999999.99
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
decimal(column: string, precision?: number, scale?: number): ColumnBuilder;
|
|
700
|
+
/**
|
|
701
|
+
* Add a boolean column.
|
|
702
|
+
*
|
|
703
|
+
* @param column - Column name
|
|
704
|
+
* @returns Column builder for chaining modifiers
|
|
705
|
+
*/
|
|
706
|
+
boolean(column: string): ColumnBuilder;
|
|
707
|
+
/**
|
|
708
|
+
* Alias for boolean().
|
|
709
|
+
*/
|
|
710
|
+
bool(column: string): ColumnBuilder;
|
|
711
|
+
/**
|
|
712
|
+
* Add a date column (date only, no time).
|
|
713
|
+
*
|
|
714
|
+
* @param column - Column name
|
|
715
|
+
* @returns Column builder for chaining modifiers
|
|
716
|
+
*/
|
|
717
|
+
date(column: string): ColumnBuilder;
|
|
718
|
+
/**
|
|
719
|
+
* Add a datetime column (date and time).
|
|
720
|
+
*
|
|
721
|
+
* @param column - Column name
|
|
722
|
+
* @returns Column builder for chaining modifiers
|
|
723
|
+
*/
|
|
724
|
+
dateTime(column: string): ColumnBuilder;
|
|
725
|
+
/**
|
|
726
|
+
* Add a timestamp column.
|
|
727
|
+
*
|
|
728
|
+
* @param column - Column name
|
|
729
|
+
* @returns Column builder for chaining modifiers
|
|
730
|
+
*/
|
|
731
|
+
timestamp(column: string): ColumnBuilder;
|
|
732
|
+
/**
|
|
733
|
+
* Add a time column (time only, no date).
|
|
734
|
+
*
|
|
735
|
+
* @param column - Column name
|
|
736
|
+
* @returns Column builder for chaining modifiers
|
|
737
|
+
*/
|
|
738
|
+
time(column: string): ColumnBuilder;
|
|
739
|
+
/**
|
|
740
|
+
* Add a year column.
|
|
741
|
+
*
|
|
742
|
+
* @param column - Column name
|
|
743
|
+
* @returns Column builder for chaining modifiers
|
|
744
|
+
*/
|
|
745
|
+
year(column: string): ColumnBuilder;
|
|
746
|
+
/**
|
|
747
|
+
* Add a JSON column.
|
|
748
|
+
*
|
|
749
|
+
* @param column - Column name
|
|
750
|
+
* @returns Column builder for chaining modifiers
|
|
751
|
+
*/
|
|
752
|
+
json(column: string): ColumnBuilder;
|
|
753
|
+
/**
|
|
754
|
+
* Alias for json().
|
|
755
|
+
*/
|
|
756
|
+
object(column: string): ColumnBuilder;
|
|
757
|
+
/**
|
|
758
|
+
* Add a binary/blob column.
|
|
759
|
+
*
|
|
760
|
+
* @param column - Column name
|
|
761
|
+
* @returns Column builder for chaining modifiers
|
|
762
|
+
*/
|
|
763
|
+
binary(column: string): ColumnBuilder;
|
|
764
|
+
/**
|
|
765
|
+
* Alias for binary().
|
|
766
|
+
*/
|
|
767
|
+
blob(column: string): ColumnBuilder;
|
|
768
|
+
/**
|
|
769
|
+
* Add a UUID column.
|
|
770
|
+
*
|
|
771
|
+
* @param column - Column name
|
|
772
|
+
* @returns Column builder for chaining modifiers
|
|
773
|
+
*/
|
|
774
|
+
uuid(column: string): ColumnBuilder;
|
|
775
|
+
/**
|
|
776
|
+
* Add a ULID column.
|
|
777
|
+
*
|
|
778
|
+
* @param column - Column name
|
|
779
|
+
* @returns Column builder for chaining modifiers
|
|
780
|
+
*/
|
|
781
|
+
ulid(column: string): ColumnBuilder;
|
|
782
|
+
/**
|
|
783
|
+
* Add an IP address column.
|
|
784
|
+
*
|
|
785
|
+
* @param column - Column name
|
|
786
|
+
* @returns Column builder for chaining modifiers
|
|
787
|
+
*/
|
|
788
|
+
ipAddress(column: string): ColumnBuilder;
|
|
789
|
+
/**
|
|
790
|
+
* Add a MAC address column.
|
|
791
|
+
*
|
|
792
|
+
* @param column - Column name
|
|
793
|
+
* @returns Column builder for chaining modifiers
|
|
794
|
+
*/
|
|
795
|
+
macAddress(column: string): ColumnBuilder;
|
|
796
|
+
/**
|
|
797
|
+
* Add a geo point column.
|
|
798
|
+
*
|
|
799
|
+
* @param column - Column name
|
|
800
|
+
* @returns Column builder for chaining modifiers
|
|
801
|
+
*/
|
|
802
|
+
point(column: string): ColumnBuilder;
|
|
803
|
+
/**
|
|
804
|
+
* Add a polygon column.
|
|
805
|
+
*
|
|
806
|
+
* @param column - Column name
|
|
807
|
+
* @returns Column builder for chaining modifiers
|
|
808
|
+
*/
|
|
809
|
+
polygon(column: string): ColumnBuilder;
|
|
810
|
+
/**
|
|
811
|
+
* Add a line string column.
|
|
812
|
+
*
|
|
813
|
+
* @param column - Column name
|
|
814
|
+
* @returns Column builder for chaining modifiers
|
|
815
|
+
*/
|
|
816
|
+
lineString(column: string): ColumnBuilder;
|
|
817
|
+
/**
|
|
818
|
+
* Add a generic geometry column.
|
|
819
|
+
*
|
|
820
|
+
* @param column - Column name
|
|
821
|
+
* @returns Column builder for chaining modifiers
|
|
822
|
+
*/
|
|
823
|
+
geometry(column: string): ColumnBuilder;
|
|
824
|
+
/**
|
|
825
|
+
* Add a vector column for AI embeddings.
|
|
826
|
+
*
|
|
827
|
+
* Used for storing and searching ML embeddings (e.g., OpenAI, Cohere).
|
|
828
|
+
*
|
|
829
|
+
* @param column - Column name
|
|
830
|
+
* @param dimensions - Vector dimensions (e.g., 1536 for OpenAI ada-002)
|
|
831
|
+
* @returns Column builder for chaining modifiers
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* ```typescript
|
|
835
|
+
* this.vector("embedding", 1536); // OpenAI ada-002
|
|
836
|
+
* this.vector("embedding", 384); // Sentence Transformers
|
|
837
|
+
* ```
|
|
838
|
+
*/
|
|
839
|
+
vector(column: string, dimensions: number): ColumnBuilder;
|
|
840
|
+
/**
|
|
841
|
+
* Add an enum column with allowed values.
|
|
842
|
+
*
|
|
843
|
+
* @param column - Column name
|
|
844
|
+
* @param values - Allowed enum values
|
|
845
|
+
* @returns Column builder for chaining modifiers
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
* ```typescript
|
|
849
|
+
* this.enum("status", ["pending", "active", "archived"]);
|
|
850
|
+
* ```
|
|
851
|
+
*/
|
|
852
|
+
enum(column: string, values: string[]): ColumnBuilder;
|
|
853
|
+
/**
|
|
854
|
+
* Add a set column (multiple values from a set).
|
|
855
|
+
*
|
|
856
|
+
* @param column - Column name
|
|
857
|
+
* @param values - Allowed set values
|
|
858
|
+
* @returns Column builder for chaining modifiers
|
|
859
|
+
*/
|
|
860
|
+
set(column: string, values: string[]): ColumnBuilder;
|
|
861
|
+
/**
|
|
862
|
+
* Add an auto-increment primary key column.
|
|
863
|
+
*
|
|
864
|
+
* Creates an unsigned integer with primary key and auto-increment.
|
|
865
|
+
*
|
|
866
|
+
* @param name - Column name (default: "id")
|
|
867
|
+
* @returns Column builder for chaining modifiers
|
|
868
|
+
*
|
|
869
|
+
* @example
|
|
870
|
+
* ```typescript
|
|
871
|
+
* this.id(); // Creates "id" column
|
|
872
|
+
* this.id("userId"); // Creates "userId" column
|
|
873
|
+
* ```
|
|
874
|
+
*/
|
|
875
|
+
id(name?: string): ColumnBuilder;
|
|
876
|
+
/**
|
|
877
|
+
* Add a big integer auto-increment primary key column.
|
|
878
|
+
*
|
|
879
|
+
* @param name - Column name (default: "id")
|
|
880
|
+
* @returns Column builder for chaining modifiers
|
|
881
|
+
*/
|
|
882
|
+
bigId(name?: string): ColumnBuilder;
|
|
883
|
+
/**
|
|
884
|
+
* Add a UUID primary key column.
|
|
885
|
+
*
|
|
886
|
+
* @param name - Column name (default: "id")
|
|
887
|
+
* @returns Column builder for chaining modifiers
|
|
888
|
+
*/
|
|
889
|
+
uuidId(name?: string): ColumnBuilder;
|
|
890
|
+
/**
|
|
891
|
+
* Add createdAt and updatedAt timestamp columns.
|
|
892
|
+
*
|
|
893
|
+
* @returns This migration for chaining
|
|
894
|
+
*
|
|
895
|
+
* @example
|
|
896
|
+
* ```typescript
|
|
897
|
+
* this.timestamps(); // Creates createdAt and updatedAt
|
|
898
|
+
* ```
|
|
899
|
+
*/
|
|
900
|
+
timestamps(): this;
|
|
901
|
+
/**
|
|
902
|
+
* Add a deletedAt column for soft deletes.
|
|
903
|
+
*
|
|
904
|
+
* @param column - Column name (default: "deletedAt")
|
|
905
|
+
* @returns Column builder for chaining modifiers
|
|
906
|
+
*/
|
|
907
|
+
softDeletes(column?: string): ColumnBuilder;
|
|
908
|
+
/**
|
|
909
|
+
* Drop a column.
|
|
910
|
+
*
|
|
911
|
+
* @param column - Column name to drop
|
|
912
|
+
* @returns This migration for chaining
|
|
913
|
+
*/
|
|
914
|
+
dropColumn(column: string): this;
|
|
915
|
+
/**
|
|
916
|
+
* Drop multiple columns.
|
|
917
|
+
*
|
|
918
|
+
* @param columns - Column names to drop
|
|
919
|
+
* @returns This migration for chaining
|
|
920
|
+
*/
|
|
921
|
+
dropColumns(...columns: string[]): this;
|
|
922
|
+
/**
|
|
923
|
+
* Rename a column.
|
|
924
|
+
*
|
|
925
|
+
* @param from - Current column name
|
|
926
|
+
* @param to - New column name
|
|
927
|
+
* @returns This migration for chaining
|
|
928
|
+
*/
|
|
929
|
+
renameColumn(from: string, to: string): this;
|
|
930
|
+
/**
|
|
931
|
+
* Create an index on one or more columns.
|
|
932
|
+
*
|
|
933
|
+
* @param columns - Column(s) to index
|
|
934
|
+
* @param name - Optional index name
|
|
935
|
+
* @returns This migration for chaining
|
|
936
|
+
*
|
|
937
|
+
* @example
|
|
938
|
+
* ```typescript
|
|
939
|
+
* this.index("email");
|
|
940
|
+
* this.index(["firstName", "lastName"], "name_idx");
|
|
941
|
+
* ```
|
|
942
|
+
*/
|
|
943
|
+
index(columns: string | string[], name?: string): this;
|
|
944
|
+
/**
|
|
945
|
+
* Drop an index by name or columns.
|
|
946
|
+
*
|
|
947
|
+
* @param nameOrColumns - Index name (string) or columns array
|
|
948
|
+
* @returns This migration for chaining
|
|
949
|
+
*
|
|
950
|
+
* @example
|
|
951
|
+
* ```typescript
|
|
952
|
+
* this.dropIndex("email_idx"); // Drop by name
|
|
953
|
+
* this.dropIndex(["firstName", "lastName"]); // Drop by columns
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
956
|
+
dropIndex(nameOrColumns: string | string[]): this;
|
|
957
|
+
/**
|
|
958
|
+
* Create a unique constraint/index.
|
|
959
|
+
*
|
|
960
|
+
* @param columns - Column(s) to make unique
|
|
961
|
+
* @param name - Optional constraint name
|
|
962
|
+
* @returns This migration for chaining
|
|
963
|
+
*/
|
|
964
|
+
unique(columns: string | string[], name?: string): this;
|
|
965
|
+
/**
|
|
966
|
+
* Drop a unique constraint/index.
|
|
967
|
+
*
|
|
968
|
+
* @param columns - Columns in the unique constraint
|
|
969
|
+
* @returns This migration for chaining
|
|
970
|
+
*/
|
|
971
|
+
dropUnique(columns: string | string[]): this;
|
|
972
|
+
/**
|
|
973
|
+
* Create a full-text search index.
|
|
974
|
+
*
|
|
975
|
+
* @param columns - Column(s) to index
|
|
976
|
+
* @param options - Full-text options
|
|
977
|
+
* @returns This migration for chaining
|
|
978
|
+
*/
|
|
979
|
+
fullText(columns: string | string[], options?: FullTextIndexOptions): this;
|
|
980
|
+
/**
|
|
981
|
+
* Drop a full-text search index.
|
|
982
|
+
*
|
|
983
|
+
* @param name - Index name
|
|
984
|
+
* @returns This migration for chaining
|
|
985
|
+
*/
|
|
986
|
+
dropFullText(name: string): this;
|
|
987
|
+
/**
|
|
988
|
+
* Create a geo-spatial index.
|
|
989
|
+
*
|
|
990
|
+
* @param column - Geo column
|
|
991
|
+
* @param options - Geo index options
|
|
992
|
+
* @returns This migration for chaining
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```typescript
|
|
996
|
+
* this.geoIndex("location"); // 2dsphere index
|
|
997
|
+
* this.geoIndex("coordinates", { type: "2d" }); // 2d index
|
|
998
|
+
* ```
|
|
999
|
+
*/
|
|
1000
|
+
geoIndex(column: string, options?: GeoIndexOptions): this;
|
|
1001
|
+
/**
|
|
1002
|
+
* Drop a geo-spatial index.
|
|
1003
|
+
*
|
|
1004
|
+
* @param column - Geo column
|
|
1005
|
+
* @returns This migration for chaining
|
|
1006
|
+
*/
|
|
1007
|
+
dropGeoIndex(column: string): this;
|
|
1008
|
+
/**
|
|
1009
|
+
* Create a vector search index for AI embeddings.
|
|
1010
|
+
*
|
|
1011
|
+
* @param column - Vector column
|
|
1012
|
+
* @param options - Vector index options
|
|
1013
|
+
* @returns This migration for chaining
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* ```typescript
|
|
1017
|
+
* this.vectorIndex("embedding", {
|
|
1018
|
+
* dimensions: 1536,
|
|
1019
|
+
* similarity: "cosine",
|
|
1020
|
+
* });
|
|
1021
|
+
* ```
|
|
1022
|
+
*/
|
|
1023
|
+
vectorIndex(column: string, options: VectorIndexOptions): this;
|
|
1024
|
+
/**
|
|
1025
|
+
* Drop a vector search index.
|
|
1026
|
+
*
|
|
1027
|
+
* @param column - Vector column
|
|
1028
|
+
* @returns This migration for chaining
|
|
1029
|
+
*/
|
|
1030
|
+
dropVectorIndex(column: string): this;
|
|
1031
|
+
/**
|
|
1032
|
+
* Create a TTL (time-to-live) index for automatic document expiration.
|
|
1033
|
+
*
|
|
1034
|
+
* Primarily for MongoDB. Documents are automatically deleted after the
|
|
1035
|
+
* specified time has passed since the date in the column.
|
|
1036
|
+
*
|
|
1037
|
+
* @param column - Date column to check for expiration
|
|
1038
|
+
* @param expireAfterSeconds - Seconds after which documents expire
|
|
1039
|
+
* @returns This migration for chaining
|
|
1040
|
+
*
|
|
1041
|
+
* @example
|
|
1042
|
+
* ```typescript
|
|
1043
|
+
* // Delete sessions 24 hours after createdAt
|
|
1044
|
+
* this.ttlIndex("createdAt", 86400);
|
|
1045
|
+
* ```
|
|
1046
|
+
*/
|
|
1047
|
+
ttlIndex(column: string, expireAfterSeconds: number): this;
|
|
1048
|
+
/**
|
|
1049
|
+
* Drop a TTL index.
|
|
1050
|
+
*
|
|
1051
|
+
* @param column - Column with TTL
|
|
1052
|
+
* @returns This migration for chaining
|
|
1053
|
+
*/
|
|
1054
|
+
dropTTLIndex(column: string): this;
|
|
1055
|
+
/**
|
|
1056
|
+
* Add a composite primary key.
|
|
1057
|
+
*
|
|
1058
|
+
* @param columns - Columns to include in the primary key
|
|
1059
|
+
* @returns This migration for chaining
|
|
1060
|
+
*/
|
|
1061
|
+
primaryKey(columns: string[]): this;
|
|
1062
|
+
/**
|
|
1063
|
+
* Drop the primary key constraint.
|
|
1064
|
+
*
|
|
1065
|
+
* @returns This migration for chaining
|
|
1066
|
+
*/
|
|
1067
|
+
dropPrimaryKey(): this;
|
|
1068
|
+
/**
|
|
1069
|
+
* Start building a foreign key constraint.
|
|
1070
|
+
*
|
|
1071
|
+
* SQL-only feature; NoSQL drivers ignore foreign keys.
|
|
1072
|
+
*
|
|
1073
|
+
* @param column - Local column that references another table
|
|
1074
|
+
* @returns Foreign key builder for chaining
|
|
1075
|
+
*
|
|
1076
|
+
* @example
|
|
1077
|
+
* ```typescript
|
|
1078
|
+
* this.foreign("user_id")
|
|
1079
|
+
* .references("users", "id")
|
|
1080
|
+
* .onDelete("cascade")
|
|
1081
|
+
* .add();
|
|
1082
|
+
* ```
|
|
1083
|
+
*/
|
|
1084
|
+
foreign(column: string): ForeignKeyBuilder;
|
|
1085
|
+
/**
|
|
1086
|
+
* Drop a foreign key constraint by name.
|
|
1087
|
+
*
|
|
1088
|
+
* @param name - Constraint name
|
|
1089
|
+
* @returns This migration for chaining
|
|
1090
|
+
*/
|
|
1091
|
+
dropForeign(name: string): this;
|
|
1092
|
+
/**
|
|
1093
|
+
* Set JSON schema validation rules on the collection.
|
|
1094
|
+
*
|
|
1095
|
+
* MongoDB-only feature. SQL databases ignore this.
|
|
1096
|
+
*
|
|
1097
|
+
* @param schema - JSON Schema object
|
|
1098
|
+
* @returns This migration for chaining
|
|
1099
|
+
*
|
|
1100
|
+
* @example
|
|
1101
|
+
* ```typescript
|
|
1102
|
+
* this.schemaValidation({
|
|
1103
|
+
* bsonType: "object",
|
|
1104
|
+
* required: ["name", "email"],
|
|
1105
|
+
* properties: {
|
|
1106
|
+
* name: { bsonType: "string" },
|
|
1107
|
+
* email: { bsonType: "string" },
|
|
1108
|
+
* },
|
|
1109
|
+
* });
|
|
1110
|
+
* ```
|
|
1111
|
+
*/
|
|
1112
|
+
schemaValidation(schema: object): this;
|
|
1113
|
+
/**
|
|
1114
|
+
* Remove schema validation rules from the collection.
|
|
1115
|
+
*
|
|
1116
|
+
* @returns This migration for chaining
|
|
1117
|
+
*/
|
|
1118
|
+
dropSchemaValidation(): this;
|
|
1119
|
+
/**
|
|
1120
|
+
* Execute raw operations with direct driver access.
|
|
1121
|
+
*
|
|
1122
|
+
* Use this for database-specific operations not covered by the API.
|
|
1123
|
+
*
|
|
1124
|
+
* @param callback - Callback receiving the native connection
|
|
1125
|
+
* @returns Result from callback
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* ```typescript
|
|
1129
|
+
* await this.raw(async (db) => {
|
|
1130
|
+
* await db.collection("users").updateMany({}, { $set: { active: true } });
|
|
1131
|
+
* });
|
|
1132
|
+
* ```
|
|
1133
|
+
*/
|
|
1134
|
+
raw<T>(callback: (connection: unknown) => Promise<T>): Promise<T>;
|
|
1135
|
+
}
|
|
1136
|
+
export declare function migrate(model: ChildModel<Model<any>>, options?: {
|
|
1137
|
+
createdAt?: string;
|
|
1138
|
+
name?: string;
|
|
1139
|
+
up?: (this: MigrationContract) => void;
|
|
1140
|
+
down?: (this: MigrationContract) => void;
|
|
1141
|
+
transactional?: boolean;
|
|
1142
|
+
}): MigrationConstructor;
|
|
1143
|
+
//# sourceMappingURL=migration.d.ts.map
|