rake-db 2.32.2 → 2.33.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/dist/index.d.ts CHANGED
@@ -1,567 +1,522 @@
1
- import * as pqb_internal from 'pqb/internal';
2
- import { SearchWeight, RecordOptionalString, DefaultPrivileges, AdapterBase, TableData, ColumnsShape, NoPrimaryKeyOption, MaybeArray, Column, RawSqlBase, RecordString, EmptyObject, EnumColumn, DbResult, QueryLogObject, ColumnSchemaConfig, raw, TableDataFn, TableDataItem, DbDomainArg, DefaultColumnTypes, DefaultSchemaConfig, QueryLogger, QueryLogOptions, MaybePromise, ColumnsByType, DbStructureDomainsMap } from 'pqb/internal';
3
- import { Db, QuerySchema } from 'pqb';
4
-
1
+ import { Adapter, Column as Column$1, ColumnSchemaConfig, ColumnsByType, ColumnsShape, DbDomainArg, DbResult, DbStructureDomainsMap, DefaultColumnTypes, DefaultPrivileges, DefaultSchemaConfig, EmptyObject, EnumColumn, MaybeArray, MaybePromise, NoPrimaryKeyOption, QueryLogObject, QueryLogOptions, QueryLogger, QuerySchema, RawSqlBase, RecordOptionalString, RecordString, SearchWeight, TableData, TableDataFn, TableDataItem, TableDataMethods, raw } from "pqb/internal";
2
+ import { Db } from "pqb";
5
3
  declare namespace DbStructure {
6
- interface TableNameAndSchemaName {
7
- schemaName: string;
8
- tableName: string;
9
- }
10
- interface Table {
11
- schemaName: string;
12
- name: string;
13
- comment?: string;
14
- columns: Column[];
15
- }
16
- interface View {
17
- schemaName: string;
18
- name: string;
19
- deps: RakeDbAst.View['deps'];
20
- isRecursive: boolean;
21
- with?: string[];
22
- columns: Column[];
23
- sql: string;
24
- }
25
- interface Procedure {
26
- schemaName: string;
27
- name: string;
28
- returnSet: boolean;
29
- returnType: string;
30
- kind: string;
31
- isTrigger: boolean;
32
- types: string[];
33
- argTypes: string[];
34
- argModes: ('i' | 'o')[];
35
- argNames?: string[];
36
- }
37
- interface Column extends TableNameAndSchemaName {
38
- name: string;
39
- typeSchema: string;
40
- type: string;
41
- arrayDims: number;
42
- maxChars?: number;
43
- numericPrecision?: number;
44
- numericScale?: number;
45
- dateTimePrecision?: number;
46
- default?: string;
47
- isNullable: boolean;
48
- collate?: string;
49
- compression?: 'pglz' | 'lz4';
50
- comment?: string;
51
- identity?: {
52
- always: boolean;
53
- start: number;
54
- increment: number;
55
- min?: number;
56
- max?: number;
57
- cache: number;
58
- cycle: boolean;
59
- };
60
- extension?: string;
61
- typmod: number;
62
- }
63
- interface Index extends TableNameAndSchemaName {
64
- name: string;
65
- using: string;
66
- unique: boolean;
67
- columns: (({
68
- column: string;
69
- } | {
70
- expression: string;
71
- }) & {
72
- collate?: string;
73
- opclass?: string;
74
- order?: string;
75
- weight?: SearchWeight;
76
- })[];
77
- include?: string[];
78
- nullsNotDistinct?: boolean;
79
- with?: string;
80
- tablespace?: string;
81
- where?: string;
82
- tsVector?: boolean;
83
- language?: string;
84
- languageColumn?: string;
85
- }
86
- interface Exclude extends Index {
87
- exclude: string[];
88
- }
89
- type ForeignKeyMatch = 'f' | 'p' | 's';
90
- type ForeignKeyAction = 'a' | 'r' | 'c' | 'n' | 'd';
91
- interface Constraint extends TableNameAndSchemaName {
92
- name: string;
93
- primaryKey?: string[];
94
- references?: References;
95
- check?: Check;
96
- }
97
- interface References {
98
- foreignSchema: string;
99
- foreignTable: string;
100
- columns: string[];
101
- foreignColumns: string[];
102
- match: ForeignKeyMatch;
103
- onUpdate: ForeignKeyAction;
104
- onDelete: ForeignKeyAction;
105
- }
106
- interface Check {
107
- columns?: string[];
108
- expression: string;
109
- }
110
- interface Trigger extends TableNameAndSchemaName {
111
- triggerSchema: string;
112
- name: string;
113
- events: string[];
114
- activation: string;
115
- condition?: string;
116
- definition: string;
117
- }
118
- interface Extension {
119
- schemaName: string;
120
- name: string;
121
- version?: string;
122
- }
123
- interface Enum {
124
- schemaName: string;
125
- name: string;
126
- values: [string, ...string[]];
127
- }
128
- interface Domain {
129
- schemaName: string;
130
- name: string;
131
- type: string;
132
- typeSchema: string;
133
- arrayDims: number;
134
- isNullable: boolean;
135
- maxChars?: number;
136
- numericPrecision?: number;
137
- numericScale?: number;
138
- dateTimePrecision?: number;
139
- collate?: string;
140
- default?: string;
141
- checks?: string[];
142
- }
143
- interface Collation {
144
- schemaName: string;
145
- name: string;
146
- provider: string;
147
- deterministic: boolean;
148
- lcCollate?: string;
149
- lcCType?: string;
150
- locale?: string;
151
- version?: string;
152
- }
153
- interface Role {
154
- name: string;
155
- super: boolean;
156
- inherit: boolean;
157
- createRole: boolean;
158
- createDb: boolean;
159
- canLogin: boolean;
160
- replication: boolean;
161
- connLimit: number;
162
- validUntil?: Date;
163
- bypassRls: boolean;
164
- config?: RecordOptionalString;
165
- }
166
- interface DefaultPrivilegeConfig {
167
- privilege: string;
168
- isGrantable: boolean;
169
- }
170
- interface DefaultPrivilegeObjectConfig {
171
- object: DefaultPrivileges.ObjectType;
172
- privilegeConfigs: DefaultPrivilegeConfig[];
173
- }
174
- interface DefaultPrivilege {
175
- owner?: string;
176
- grantee: string;
177
- schema?: string;
178
- objectConfigs: DefaultPrivilegeObjectConfig[];
179
- }
4
+ interface TableNameAndSchemaName {
5
+ schemaName: string;
6
+ tableName: string;
7
+ }
8
+ interface Table {
9
+ schemaName: string;
10
+ name: string;
11
+ comment?: string;
12
+ columns: Column[];
13
+ }
14
+ interface View {
15
+ schemaName: string;
16
+ name: string;
17
+ deps: RakeDbAst.View['deps'];
18
+ isRecursive: boolean;
19
+ with?: string[];
20
+ columns: Column[];
21
+ sql: string;
22
+ }
23
+ interface Procedure {
24
+ schemaName: string;
25
+ name: string;
26
+ returnSet: boolean;
27
+ returnType: string;
28
+ kind: string;
29
+ isTrigger: boolean;
30
+ types: string[];
31
+ argTypes: string[];
32
+ argModes: ('i' | 'o')[];
33
+ argNames?: string[];
34
+ }
35
+ interface Column extends TableNameAndSchemaName {
36
+ name: string;
37
+ typeSchema: string;
38
+ type: string;
39
+ arrayDims: number;
40
+ maxChars?: number;
41
+ numericPrecision?: number;
42
+ numericScale?: number;
43
+ dateTimePrecision?: number;
44
+ default?: string;
45
+ isNullable: boolean;
46
+ collate?: string;
47
+ compression?: 'pglz' | 'lz4';
48
+ comment?: string;
49
+ identity?: {
50
+ always: boolean;
51
+ start: number;
52
+ increment: number;
53
+ min?: number;
54
+ max?: number;
55
+ cache: number;
56
+ cycle: boolean;
57
+ };
58
+ extension?: string;
59
+ typmod: number;
60
+ }
61
+ interface Index extends TableNameAndSchemaName {
62
+ name: string;
63
+ using: string;
64
+ unique: boolean;
65
+ columns: (({
66
+ column: string;
67
+ } | {
68
+ expression: string;
69
+ }) & {
70
+ collate?: string;
71
+ opclass?: string;
72
+ order?: string;
73
+ weight?: SearchWeight;
74
+ })[];
75
+ include?: string[];
76
+ nullsNotDistinct?: boolean;
77
+ with?: string;
78
+ tablespace?: string;
79
+ where?: string;
80
+ tsVector?: boolean;
81
+ language?: string;
82
+ languageColumn?: string;
83
+ }
84
+ interface Exclude extends Index {
85
+ exclude: string[];
86
+ }
87
+ type ForeignKeyMatch = 'f' | 'p' | 's';
88
+ type ForeignKeyAction = 'a' | 'r' | 'c' | 'n' | 'd';
89
+ interface Constraint extends TableNameAndSchemaName {
90
+ name: string;
91
+ primaryKey?: string[];
92
+ references?: References;
93
+ check?: Check;
94
+ }
95
+ interface References {
96
+ foreignSchema: string;
97
+ foreignTable: string;
98
+ columns: string[];
99
+ foreignColumns: string[];
100
+ match: ForeignKeyMatch;
101
+ onUpdate: ForeignKeyAction;
102
+ onDelete: ForeignKeyAction;
103
+ }
104
+ interface Check {
105
+ columns?: string[];
106
+ expression: string;
107
+ }
108
+ interface Trigger extends TableNameAndSchemaName {
109
+ triggerSchema: string;
110
+ name: string;
111
+ events: string[];
112
+ activation: string;
113
+ condition?: string;
114
+ definition: string;
115
+ }
116
+ interface Extension {
117
+ schemaName: string;
118
+ name: string;
119
+ version?: string;
120
+ }
121
+ interface Enum {
122
+ schemaName: string;
123
+ name: string;
124
+ values: [string, ...string[]];
125
+ }
126
+ interface Domain {
127
+ schemaName: string;
128
+ name: string;
129
+ type: string;
130
+ typeSchema: string;
131
+ arrayDims: number;
132
+ isNullable: boolean;
133
+ maxChars?: number;
134
+ numericPrecision?: number;
135
+ numericScale?: number;
136
+ dateTimePrecision?: number;
137
+ collate?: string;
138
+ default?: string;
139
+ checks?: string[];
140
+ }
141
+ interface Collation {
142
+ schemaName: string;
143
+ name: string;
144
+ provider: string;
145
+ deterministic: boolean;
146
+ lcCollate?: string;
147
+ lcCType?: string;
148
+ locale?: string;
149
+ version?: string;
150
+ }
151
+ interface Role {
152
+ name: string;
153
+ super: boolean;
154
+ inherit: boolean;
155
+ createRole: boolean;
156
+ createDb: boolean;
157
+ canLogin: boolean;
158
+ replication: boolean;
159
+ connLimit: number;
160
+ validUntil?: Date;
161
+ bypassRls: boolean;
162
+ config?: RecordOptionalString;
163
+ }
164
+ interface DefaultPrivilegeConfig {
165
+ privilege: string;
166
+ isGrantable: boolean;
167
+ }
168
+ interface DefaultPrivilegeObjectConfig {
169
+ object: DefaultPrivileges.ObjectType;
170
+ privilegeConfigs: DefaultPrivilegeConfig[];
171
+ }
172
+ interface DefaultPrivilege {
173
+ owner?: string;
174
+ grantee: string;
175
+ schema?: string;
176
+ objectConfigs: DefaultPrivilegeObjectConfig[];
177
+ }
180
178
  }
181
179
  interface IntrospectedStructure {
182
- version: number;
183
- schemas: string[];
184
- tables: DbStructure.Table[];
185
- views: DbStructure.View[];
186
- indexes: DbStructure.Index[];
187
- excludes: DbStructure.Exclude[];
188
- constraints: DbStructure.Constraint[];
189
- triggers: DbStructure.Trigger[];
190
- extensions: DbStructure.Extension[];
191
- enums: DbStructure.Enum[];
192
- domains: DbStructure.Domain[];
193
- collations: DbStructure.Collation[];
194
- roles?: DbStructure.Role[];
195
- defaultPrivileges?: DbStructure.DefaultPrivilege[];
196
- managedRolesSql?: string;
180
+ version: number;
181
+ schemas: string[];
182
+ tables: DbStructure.Table[];
183
+ views: DbStructure.View[];
184
+ indexes: DbStructure.Index[];
185
+ excludes: DbStructure.Exclude[];
186
+ constraints: DbStructure.Constraint[];
187
+ triggers: DbStructure.Trigger[];
188
+ extensions: DbStructure.Extension[];
189
+ enums: DbStructure.Enum[];
190
+ domains: DbStructure.Domain[];
191
+ collations: DbStructure.Collation[];
192
+ roles?: DbStructure.Role[];
193
+ defaultPrivileges?: DbStructure.DefaultPrivilege[];
194
+ managedRolesSql?: string;
197
195
  }
198
196
  interface IntrospectDbStructureParams {
199
- roles?: {
200
- whereSql?: string;
201
- };
202
- loadDefaultPrivileges?: boolean;
197
+ roles?: {
198
+ whereSql?: string;
199
+ };
200
+ loadDefaultPrivileges?: boolean;
203
201
  }
204
- declare function getDbVersion(db: AdapterBase): Promise<number>;
205
- declare function introspectDbSchema(db: AdapterBase, params?: IntrospectDbStructureParams): Promise<IntrospectedStructure>;
206
-
202
+ declare function getDbVersion(db: Adapter): Promise<number>;
203
+ declare function introspectDbSchema(db: Adapter, params?: IntrospectDbStructureParams): Promise<IntrospectedStructure>;
207
204
  type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameType | RakeDbAst.Schema | RakeDbAst.RenameSchema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.EnumValues | RakeDbAst.RenameEnumValues | RakeDbAst.ChangeEnumValues | RakeDbAst.Domain | RakeDbAst.Collation | RakeDbAst.Constraint | RakeDbAst.RenameTableItem | RakeDbAst.View | RakeDbAst.Role | RakeDbAst.RenameRole | RakeDbAst.ChangeRole | RakeDbAst.DefaultPrivilege;
208
205
  declare namespace RakeDbAst {
209
- export interface Table extends TableData {
210
- type: 'table';
211
- action: 'create' | 'drop';
212
- schema?: string;
213
- name: string;
214
- shape: ColumnsShape;
215
- noPrimaryKey: NoPrimaryKeyOption;
216
- createIfNotExists?: boolean;
217
- dropIfExists?: boolean;
218
- dropMode?: DropMode;
219
- comment?: string;
220
- }
221
- export interface ChangeTable {
222
- type: 'changeTable';
223
- schema?: string;
224
- name: string;
225
- comment?: string | [string, string] | null;
226
- shape: ChangeTableShape;
227
- add: TableData;
228
- drop: TableData;
229
- }
230
- export type ChangeTableShape = Record<string, MaybeArray<ChangeTableItem>>;
231
- export type ChangeTableItem = ChangeTableItem.Column | ChangeTableItem.Change | ChangeTableItem.Rename;
232
- export namespace ChangeTableItem {
233
- interface Column {
234
- type: 'add' | 'drop';
235
- item: Column;
236
- dropMode?: DropMode;
237
- }
238
- interface Change {
239
- type: 'change';
240
- name?: string;
241
- from: ColumnChange;
242
- to: ColumnChange;
243
- using?: ChangeUsing;
244
- }
245
- interface ChangeUsing {
246
- usingUp?: RawSqlBase;
247
- usingDown?: RawSqlBase;
248
- }
249
- interface Rename {
250
- type: 'rename';
251
- name: string;
252
- }
253
- }
254
- export interface ColumnChange {
255
- column?: Column;
256
- type?: string;
257
- collate?: string;
258
- default?: unknown | RawSqlBase;
259
- nullable?: boolean;
260
- comment?: string | null;
261
- compression?: string;
262
- primaryKey?: boolean;
263
- checks?: Column.Data.Check[];
264
- foreignKeys?: TableData.ColumnReferences[];
265
- indexes?: TableData.ColumnIndex[];
266
- excludes?: TableData.ColumnExclude[];
267
- identity?: TableData.Identity;
268
- }
269
- export interface RenameType {
270
- type: 'renameType';
271
- kind: 'TABLE' | 'TYPE' | 'DOMAIN';
272
- fromSchema?: string;
273
- from: string;
274
- toSchema?: string;
275
- to: string;
276
- }
277
- export interface Schema {
278
- type: 'schema';
279
- action: 'create' | 'drop';
280
- name: string;
281
- }
282
- export interface RenameSchema {
283
- type: 'renameSchema';
284
- from: string;
285
- to: string;
286
- }
287
- export interface ExtensionArg {
288
- version?: string;
289
- cascade?: boolean;
290
- createIfNotExists?: boolean;
291
- dropIfExists?: boolean;
292
- }
293
- export interface Extension extends ExtensionArg {
294
- type: 'extension';
295
- action: 'create' | 'drop';
296
- schema?: string;
297
- name: string;
298
- }
299
- export interface Enum {
300
- type: 'enum';
301
- action: 'create' | 'drop';
302
- schema?: string;
303
- name: string;
304
- values: [string, ...string[]];
305
- cascade?: boolean;
306
- dropIfExists?: boolean;
307
- }
308
- export interface EnumValues {
309
- type: 'enumValues';
310
- action: 'add' | 'drop';
311
- schema?: string;
312
- name: string;
313
- values: string[];
314
- place?: 'before' | 'after';
315
- relativeTo?: string;
316
- ifNotExists?: boolean;
317
- }
318
- export interface RenameEnumValues {
319
- type: 'renameEnumValues';
320
- schema?: string;
321
- name: string;
322
- values: RecordString;
323
- }
324
- export interface ChangeEnumValues {
325
- type: 'changeEnumValues';
326
- schema?: string;
327
- name: string;
328
- fromValues: string[];
329
- toValues: string[];
330
- }
331
- export interface Domain {
332
- type: 'domain';
333
- action: 'create' | 'drop';
334
- schema?: string;
335
- name: string;
336
- baseType: Column;
337
- }
338
- export interface Collation {
339
- type: 'collation';
340
- action: 'create' | 'drop';
341
- schema?: string;
342
- name: string;
343
- locale?: string;
344
- lcCollate?: string;
345
- lcCType?: string;
346
- provider?: string;
347
- deterministic?: boolean;
348
- version?: string;
349
- fromExisting?: string;
350
- createIfNotExists?: boolean;
351
- dropIfExists?: boolean;
352
- cascade?: boolean;
353
- }
354
- export interface EnumOptions {
355
- createIfNotExists?: boolean;
356
- dropIfExists?: boolean;
357
- }
358
- export interface Constraint extends TableData.Constraint {
359
- type: 'constraint';
360
- action: 'create' | 'drop';
361
- tableSchema?: string;
362
- tableName: string;
363
- }
364
- export interface RenameTableItem {
365
- type: 'renameTableItem';
366
- kind: 'INDEX' | 'CONSTRAINT';
367
- tableSchema?: string;
368
- tableName: string;
369
- from: string;
370
- to: string;
371
- }
372
- export interface View {
373
- type: 'view';
374
- action: 'create' | 'drop';
375
- schema?: string;
376
- name: string;
377
- shape: ColumnsShape;
378
- sql: RawSqlBase;
379
- options: ViewOptions;
380
- deps: {
381
- schemaName: string;
382
- name: string;
383
- }[];
384
- }
385
- export interface ViewOptions {
386
- createOrReplace?: boolean;
387
- dropIfExists?: boolean;
388
- dropMode?: DropMode;
389
- temporary?: boolean;
390
- recursive?: boolean;
391
- columns?: string[];
392
- with?: {
393
- checkOption?: 'LOCAL' | 'CASCADED';
394
- securityBarrier?: boolean;
395
- securityInvoker?: boolean;
396
- };
397
- }
398
- export interface Role extends DbStructure.Role {
399
- type: 'role';
400
- action: 'create' | 'drop';
401
- }
402
- export interface RenameRole {
403
- type: 'renameRole';
404
- from: string;
405
- to: string;
406
- }
407
- export interface ChangeRole {
408
- type: 'changeRole';
409
- name: string;
410
- from: Partial<DbStructure.Role>;
411
- to: Partial<DbStructure.Role>;
206
+ export interface Table extends TableData {
207
+ type: 'table';
208
+ action: 'create' | 'drop';
209
+ schema?: string;
210
+ name: string;
211
+ shape: ColumnsShape;
212
+ noPrimaryKey: NoPrimaryKeyOption;
213
+ createIfNotExists?: boolean;
214
+ dropIfExists?: boolean;
215
+ dropMode?: DropMode;
216
+ comment?: string;
217
+ }
218
+ export interface ChangeTable {
219
+ type: 'changeTable';
220
+ schema?: string;
221
+ name: string;
222
+ comment?: string | [string, string] | null;
223
+ shape: ChangeTableShape;
224
+ add: TableData;
225
+ drop: TableData;
226
+ }
227
+ export type ChangeTableShape = Record<string, MaybeArray<ChangeTableItem>>;
228
+ export type ChangeTableItem = ChangeTableItem.Column | ChangeTableItem.Change | ChangeTableItem.Rename;
229
+ export namespace ChangeTableItem {
230
+ interface Column {
231
+ type: 'add' | 'drop';
232
+ item: Column$1;
233
+ dropMode?: DropMode;
412
234
  }
413
- interface DefaultPrivilegeSetting {
414
- privileges?: string[];
415
- grantablePrivileges?: string[];
235
+ interface Change {
236
+ type: 'change';
237
+ name?: string;
238
+ from: ColumnChange;
239
+ to: ColumnChange;
240
+ using?: ChangeUsing;
416
241
  }
417
- export interface DefaultPrivilegeObjectConfig {
418
- tables?: DefaultPrivilegeSetting;
419
- sequences?: DefaultPrivilegeSetting;
420
- functions?: DefaultPrivilegeSetting;
421
- types?: DefaultPrivilegeSetting;
422
- schemas?: DefaultPrivilegeSetting;
423
- largeObjects?: DefaultPrivilegeSetting;
242
+ interface ChangeUsing {
243
+ usingUp?: RawSqlBase;
244
+ usingDown?: RawSqlBase;
424
245
  }
425
- export interface DefaultPrivilege {
426
- type: 'defaultPrivilege';
427
- owner?: string;
428
- grantee: string;
429
- schema?: string;
430
- grant?: DefaultPrivilegeObjectConfig;
431
- revoke?: DefaultPrivilegeObjectConfig;
246
+ interface Rename {
247
+ type: 'rename';
248
+ name: string;
432
249
  }
433
- export {};
434
- }
435
-
436
- declare function add(item: Column, options?: {
250
+ }
251
+ export interface ColumnChange {
252
+ column?: Column$1;
253
+ type?: string;
254
+ collate?: string;
255
+ default?: unknown | RawSqlBase;
256
+ nullable?: boolean;
257
+ comment?: string | null;
258
+ compression?: string;
259
+ primaryKey?: boolean;
260
+ checks?: Column$1.Data.Check[];
261
+ foreignKeys?: TableData.ColumnReferences[];
262
+ indexes?: TableData.ColumnIndex[];
263
+ excludes?: TableData.ColumnExclude[];
264
+ identity?: TableData.Identity;
265
+ }
266
+ export interface RenameType {
267
+ type: 'renameType';
268
+ kind: 'TABLE' | 'TYPE' | 'DOMAIN';
269
+ fromSchema?: string;
270
+ from: string;
271
+ toSchema?: string;
272
+ to: string;
273
+ }
274
+ export interface Schema {
275
+ type: 'schema';
276
+ action: 'create' | 'drop';
277
+ name: string;
278
+ }
279
+ export interface RenameSchema {
280
+ type: 'renameSchema';
281
+ from: string;
282
+ to: string;
283
+ }
284
+ export interface ExtensionArg {
285
+ version?: string;
286
+ cascade?: boolean;
287
+ createIfNotExists?: boolean;
288
+ dropIfExists?: boolean;
289
+ }
290
+ export interface Extension extends ExtensionArg {
291
+ type: 'extension';
292
+ action: 'create' | 'drop';
293
+ schema?: string;
294
+ name: string;
295
+ }
296
+ export interface Enum {
297
+ type: 'enum';
298
+ action: 'create' | 'drop';
299
+ schema?: string;
300
+ name: string;
301
+ values: [string, ...string[]];
302
+ cascade?: boolean;
303
+ dropIfExists?: boolean;
304
+ }
305
+ export interface EnumValues {
306
+ type: 'enumValues';
307
+ action: 'add' | 'drop';
308
+ schema?: string;
309
+ name: string;
310
+ values: string[];
311
+ place?: 'before' | 'after';
312
+ relativeTo?: string;
313
+ ifNotExists?: boolean;
314
+ }
315
+ export interface RenameEnumValues {
316
+ type: 'renameEnumValues';
317
+ schema?: string;
318
+ name: string;
319
+ values: RecordString;
320
+ }
321
+ export interface ChangeEnumValues {
322
+ type: 'changeEnumValues';
323
+ schema?: string;
324
+ name: string;
325
+ fromValues: string[];
326
+ toValues: string[];
327
+ }
328
+ export interface Domain {
329
+ type: 'domain';
330
+ action: 'create' | 'drop';
331
+ schema?: string;
332
+ name: string;
333
+ baseType: Column$1;
334
+ }
335
+ export interface Collation {
336
+ type: 'collation';
337
+ action: 'create' | 'drop';
338
+ schema?: string;
339
+ name: string;
340
+ locale?: string;
341
+ lcCollate?: string;
342
+ lcCType?: string;
343
+ provider?: string;
344
+ deterministic?: boolean;
345
+ version?: string;
346
+ fromExisting?: string;
347
+ createIfNotExists?: boolean;
348
+ dropIfExists?: boolean;
349
+ cascade?: boolean;
350
+ }
351
+ export interface EnumOptions {
352
+ createIfNotExists?: boolean;
353
+ dropIfExists?: boolean;
354
+ }
355
+ export interface Constraint extends TableData.Constraint {
356
+ type: 'constraint';
357
+ action: 'create' | 'drop';
358
+ tableSchema?: string;
359
+ tableName: string;
360
+ }
361
+ export interface RenameTableItem {
362
+ type: 'renameTableItem';
363
+ kind: 'INDEX' | 'CONSTRAINT';
364
+ tableSchema?: string;
365
+ tableName: string;
366
+ from: string;
367
+ to: string;
368
+ }
369
+ export interface View {
370
+ type: 'view';
371
+ action: 'create' | 'drop';
372
+ schema?: string;
373
+ name: string;
374
+ shape: ColumnsShape;
375
+ sql: RawSqlBase;
376
+ options: ViewOptions;
377
+ deps: {
378
+ schemaName: string;
379
+ name: string;
380
+ }[];
381
+ }
382
+ export interface ViewOptions {
383
+ createOrReplace?: boolean;
384
+ dropIfExists?: boolean;
437
385
  dropMode?: DropMode;
386
+ temporary?: boolean;
387
+ recursive?: boolean;
388
+ columns?: string[];
389
+ with?: {
390
+ checkOption?: 'LOCAL' | 'CASCADED';
391
+ securityBarrier?: boolean;
392
+ securityInvoker?: boolean;
393
+ };
394
+ }
395
+ export interface Role extends DbStructure.Role {
396
+ type: 'role';
397
+ action: 'create' | 'drop';
398
+ }
399
+ export interface RenameRole {
400
+ type: 'renameRole';
401
+ from: string;
402
+ to: string;
403
+ }
404
+ export interface ChangeRole {
405
+ type: 'changeRole';
406
+ name: string;
407
+ from: Partial<DbStructure.Role>;
408
+ to: Partial<DbStructure.Role>;
409
+ }
410
+ interface DefaultPrivilegeSetting {
411
+ privileges?: string[];
412
+ grantablePrivileges?: string[];
413
+ }
414
+ export interface DefaultPrivilegeObjectConfig {
415
+ tables?: DefaultPrivilegeSetting;
416
+ sequences?: DefaultPrivilegeSetting;
417
+ functions?: DefaultPrivilegeSetting;
418
+ types?: DefaultPrivilegeSetting;
419
+ schemas?: DefaultPrivilegeSetting;
420
+ largeObjects?: DefaultPrivilegeSetting;
421
+ }
422
+ export interface DefaultPrivilege {
423
+ type: 'defaultPrivilege';
424
+ owner?: string;
425
+ grantee: string;
426
+ schema?: string;
427
+ grant?: DefaultPrivilegeObjectConfig;
428
+ revoke?: DefaultPrivilegeObjectConfig;
429
+ }
430
+ export {};
431
+ }
432
+ interface TableMethods {
433
+ enum(name: string): EnumColumn<DefaultSchemaConfig, undefined, [string, ...string[]]>;
434
+ }
435
+ type Add = typeof add;
436
+ declare function add(item: Column$1, options?: {
437
+ dropMode?: DropMode;
438
438
  }): SpecialChange;
439
439
  declare function add(emptyObject: EmptyObject): SpecialChange;
440
- declare function add(items: Record<string, Column>, options?: {
441
- dropMode?: DropMode;
440
+ declare function add(items: Record<string, Column$1>, options?: {
441
+ dropMode?: DropMode;
442
442
  }): Record<string, RakeDbAst.ChangeTableItem.Column>;
443
- interface Change extends RakeDbAst.ChangeTableItem.Change, ChangeOptions {
444
- }
443
+ interface Change extends RakeDbAst.ChangeTableItem.Change, ChangeOptions {}
445
444
  type ChangeOptions = RakeDbAst.ChangeTableItem.ChangeUsing;
446
445
  interface SpecialChange {
447
- type: SpecialChange;
446
+ type: SpecialChange;
448
447
  }
449
448
  interface OneWayChange {
450
- type: 'change';
451
- name?: string;
452
- to: RakeDbAst.ColumnChange;
453
- using?: RakeDbAst.ChangeTableItem.ChangeUsing;
449
+ type: 'change';
450
+ name?: string;
451
+ to: RakeDbAst.ColumnChange;
452
+ using?: RakeDbAst.ChangeTableItem.ChangeUsing;
453
+ }
454
+ interface TableChangeMethods extends TableMethods, TableDataMethods<string> {
455
+ name(name: string): TableChangeMethods;
456
+ add: Add;
457
+ drop: Add;
458
+ change(from: Column$1 | OneWayChange, to: Column$1 | OneWayChange, using?: ChangeOptions): Change;
459
+ default(value: unknown | RawSqlBase): OneWayChange;
460
+ nullable(): OneWayChange;
461
+ nonNullable(): OneWayChange;
462
+ comment(comment: string | null): OneWayChange;
463
+ rename(name: string): RakeDbAst.ChangeTableItem.Rename;
454
464
  }
455
- type TableChangeMethods = typeof tableChangeMethods;
456
- declare const tableChangeMethods: {
457
- name(name: string): any;
458
- add: typeof add;
459
- drop: typeof add;
460
- change(from: Column | OneWayChange, to: Column | OneWayChange, using?: ChangeOptions): Change;
461
- default(value: unknown | RawSqlBase): OneWayChange;
462
- nullable(): OneWayChange;
463
- nonNullable(): OneWayChange;
464
- comment(comment: string | null): OneWayChange;
465
- /**
466
- * Rename a column:
467
- *
468
- * ```ts
469
- * import { change } from '../dbScript';
470
- *
471
- * change(async (db) => {
472
- * await db.changeTable('table', (t) => ({
473
- * oldColumnName: t.rename('newColumnName'),
474
- * }));
475
- * });
476
- * ```
477
- *
478
- * Note that the renaming `ALTER TABLE` is executed before the rest of alterations,
479
- * so if you're also adding a new constraint on this column inside the same `changeTable`,
480
- * refer to it with a new name.
481
- *
482
- * @param name
483
- */
484
- rename(name: string): RakeDbAst.ChangeTableItem.Rename;
485
- primaryKey<Columns extends [string, ...string[]], Name extends string>(columns: Columns, name?: Name | undefined): {
486
- tableDataItem: true;
487
- columns: Columns;
488
- name: string extends Name ? never : Name;
489
- };
490
- unique<Columns extends [string | TableData.Index.ColumnOrExpressionOptions<string>, ...(string | TableData.Index.ColumnOrExpressionOptions<string>)[]], Name extends string>(columns: Columns, options?: TableData.Index.UniqueOptionsArg<Name> | undefined): {
491
- tableDataItem: true;
492
- columns: Columns extends (string | TableData.Index.ColumnOptionsForColumn<string>)[] ? { [I in keyof Columns]: "column" extends keyof Columns[I] ? Columns[I][keyof Columns[I] & "column"] : Columns[I]; } : never;
493
- name: string extends Name ? never : Name;
494
- };
495
- index(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.OptionsArg): pqb_internal.NonUniqDataItem;
496
- searchIndex(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.TsVectorArg): pqb_internal.NonUniqDataItem;
497
- exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<string>[], options?: TableData.Exclude.Options): pqb_internal.NonUniqDataItem;
498
- foreignKey<Shape>(columns: [string, ...string[]], fnOrTable: () => new () => {
499
- columns: {
500
- shape: Shape;
501
- };
502
- }, foreignColumns: [keyof Shape, ...(keyof Shape)[]], options?: TableData.References.Options): pqb_internal.NonUniqDataItem;
503
- foreignKey(columns: [string, ...string[]], fnOrTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options): pqb_internal.NonUniqDataItem;
504
- check(check: RawSqlBase, name?: string): pqb_internal.NonUniqDataItem;
505
- sql: pqb_internal.SqlFn;
506
- enum(name: string): EnumColumn<pqb_internal.DefaultSchemaConfig, undefined, [string, ...string[]]>;
507
- };
508
465
  type TableChanger<CT> = MigrationColumnTypes<CT> & TableChangeMethods;
509
- type TableChangeData = Record<string, RakeDbAst.ChangeTableItem.Column | RakeDbAst.ChangeTableItem.Rename | Change | SpecialChange | Column.Pick.Data>;
510
-
466
+ type TableChangeData = Record<string, RakeDbAst.ChangeTableItem.Column | RakeDbAst.ChangeTableItem.Rename | Change | SpecialChange | Column$1.Pick.Data>;
511
467
  interface DefaultPrivilegeObjectSetting<T> {
512
- privileges?: readonly T[];
513
- grantablePrivileges?: readonly T[];
468
+ privileges?: readonly T[];
469
+ grantablePrivileges?: readonly T[];
514
470
  }
515
- interface DefaultPrivilegeObjectConfig {
516
- all?: boolean;
517
- allGrantable?: boolean;
518
- tables?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Table']>;
519
- sequences?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Sequence']>;
520
- functions?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Function']>;
521
- types?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Type']>;
522
- schemas?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Schema']>;
523
- largeObjects?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['LargeObject']>;
471
+ interface DefaultPrivilegeObjectConfig$1 {
472
+ all?: boolean;
473
+ allGrantable?: boolean;
474
+ tables?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Table']>;
475
+ sequences?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Sequence']>;
476
+ functions?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Function']>;
477
+ types?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Type']>;
478
+ schemas?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['Schema']>;
479
+ largeObjects?: DefaultPrivilegeObjectSetting<DefaultPrivileges.Privilege['LargeObject']>;
524
480
  }
525
481
  interface ChangeDefaultPrivilegesArg {
526
- owner?: string;
527
- grantee: string;
528
- schema?: string;
529
- grant?: DefaultPrivilegeObjectConfig;
530
- revoke?: DefaultPrivilegeObjectConfig;
482
+ owner?: string;
483
+ grantee: string;
484
+ schema?: string;
485
+ grant?: DefaultPrivilegeObjectConfig$1;
486
+ revoke?: DefaultPrivilegeObjectConfig$1;
531
487
  }
532
-
533
488
  type DropMode = 'CASCADE' | 'RESTRICT';
534
489
  type TableOptions = {
535
- createIfNotExists?: boolean;
536
- dropIfExists?: boolean;
537
- dropMode?: DropMode;
538
- comment?: string;
539
- noPrimaryKey?: boolean;
540
- snakeCase?: boolean;
541
- language?: string;
490
+ createIfNotExists?: boolean;
491
+ dropIfExists?: boolean;
492
+ dropMode?: DropMode;
493
+ comment?: string;
494
+ noPrimaryKey?: boolean;
495
+ snakeCase?: boolean;
496
+ language?: string;
542
497
  };
543
498
  type MigrationColumnTypes<CT> = Omit<CT, 'enum'> & {
544
- enum: (name: string) => EnumColumn<ColumnSchemaConfig, unknown, readonly string[]>;
499
+ enum: (name: string) => EnumColumn<ColumnSchemaConfig, unknown, readonly string[]>;
545
500
  };
546
501
  type ColumnsShapeCallback<CT, Shape extends ColumnsShape = ColumnsShape> = (t: MigrationColumnTypes<CT> & {
547
- raw: typeof raw;
502
+ raw: typeof raw;
548
503
  }) => Shape;
549
504
  type ChangeTableOptions = {
550
- snakeCase?: boolean;
551
- language?: string;
552
- comment?: string | [string, string] | null;
505
+ snakeCase?: boolean;
506
+ language?: string;
507
+ comment?: string | [string, string] | null;
553
508
  };
554
509
  type ChangeTableCallback<CT> = (t: TableChanger<CT>) => TableChangeData;
555
- interface SilentQueries extends AdapterBase {
556
- silentQuery: AdapterBase['query'];
557
- silentArrays: AdapterBase['arrays'];
510
+ interface SilentQueries extends MigrationAdapter {
511
+ silentQuery: Adapter['query'];
512
+ silentArrays: Adapter['arrays'];
558
513
  }
559
514
  type DbMigration<CT> = DbResult<CT> & Migration<CT> & {
560
- adapter: SilentQueries;
515
+ adapter: SilentQueries;
561
516
  };
562
517
  interface MigrationInterfaceResult {
563
- adapter: SilentQueries;
564
- getDb(columnTypes: unknown): DbMigration<DefaultColumnTypes<DefaultSchemaConfig>>;
518
+ adapter: SilentQueries;
519
+ getDb(columnTypes: unknown): DbMigration<DefaultColumnTypes<DefaultSchemaConfig>>;
565
520
  }
566
521
  /**
567
522
  * Creates a new `db` instance that is an instance of `pqb` with mixed in migration methods from the `Migration` class.
@@ -574,940 +529,940 @@ interface MigrationInterfaceResult {
574
529
  * @param up - migrate or rollback
575
530
  * @param config - config of `rakeDb`
576
531
  */
577
- declare const createMigrationInterface: (tx: AdapterBase, up: boolean, config: Pick<RakeDbConfig, "log" | "logger">) => MigrationInterfaceResult;
578
- type MigrationAdapter = AdapterBase;
532
+ declare const createMigrationInterface: (tx: Adapter, up: boolean, config: Pick<RakeDbConfig, "log" | "logger">) => MigrationInterfaceResult;
533
+ type MigrationAdapter = Adapter;
579
534
  declare class Migration<CT = unknown> {
580
- adapter: MigrationAdapter;
581
- log?: QueryLogObject;
582
- up: boolean;
583
- options: RakeDbConfig;
584
- columnTypes: CT;
585
- /**
586
- * `createTable` accepts a string for a table name, optional options, and a callback to specify columns.
587
- *
588
- * `dropTable` accepts the same arguments, it will drop the table when migrating and create a table when rolling back.
589
- *
590
- * To create an empty table, the callback with columns may be omitted.
591
- *
592
- * When creating a table within a specific schema, write the table name with schema name: `'schemaName.tableName'`.
593
- *
594
- * Returns object `{ table: TableInterface }` that allows to insert records right after creating a table.
595
- *
596
- * Options are:
597
- *
598
- * ```ts
599
- * type TableOptions = {
600
- * // create the table only if it not exists already
601
- * createIfNotExists?: boolean;
602
- *
603
- * // drop the table only if it exists
604
- * dropIfExists?: boolean;
605
- *
606
- * // used when reverting a `createTable`
607
- * dropMode?: 'CASCADE' | 'RESTRICT';
608
- *
609
- * // add a database comment on the table
610
- * comment?: string;
611
- *
612
- * // by default, it will throw an error when the table has no primary key
613
- * // set `noPrimaryKey` to `true` to bypass it
614
- * noPrimaryKey?: boolean;
615
- *
616
- * // override rakeDb `snakeCase` option for only this table
617
- * snakeCase?: boolean;
618
- * };
619
- * ```
620
- *
621
- * Example:
622
- *
623
- * ```ts
624
- * import { change } from '../dbScript';
625
- *
626
- * change(async (db, up) => {
627
- * // call `createTable` with options
628
- * await db.createTable(
629
- * 'table',
630
- * {
631
- * comment: 'Table comment',
632
- * dropMode: 'CASCADE',
633
- * noPrimaryKey: true,
634
- * },
635
- * (t) => ({
636
- * // ...
637
- * }),
638
- * );
639
- *
640
- * // call without options
641
- * const { table } = await db.createTable('user', (t) => ({
642
- * id: t.identity().primaryKey(),
643
- * email: t.text().unique(),
644
- * name: t.text(),
645
- * active: t.boolean().nullable(),
646
- * ...t.timestamps(),
647
- * }));
648
- *
649
- * // create records only when migrating up
650
- * if (up) {
651
- * // table is a db table interface, all query methods are available
652
- * await table.createMany([...data]);
653
- * }
654
- * });
655
- * ```
656
- *
657
- * @param tableName - name of the table to create
658
- * @param fn - create table callback
659
- * @param dataFn - callback for creating composite indexes, primary keys, foreign keys
660
- */
661
- createTable<Table extends string, Shape extends ColumnsShape>(tableName: Table, fn?: ColumnsShapeCallback<CT, Shape>, dataFn?: TableDataFn<Shape, MaybeArray<TableDataItem>>): Promise<CreateTableResult<Table, Shape>>;
662
- /**
663
- * See {@link createTable}
664
- *
665
- * @param tableName - name of the table to create
666
- * @param options - {@link TableOptions}
667
- * @param fn - create table callback
668
- * @param dataFn - callback for creating composite indexes, primary keys, foreign keys
669
- */
670
- createTable<Table extends string, Shape extends ColumnsShape>(tableName: Table, options: TableOptions, fn?: ColumnsShapeCallback<CT, Shape>, dataFn?: TableDataFn<Shape, MaybeArray<TableDataItem>>): Promise<CreateTableResult<Table, Shape>>;
671
- /**
672
- * Drop the table, create it on rollback. See {@link createTable}.
673
- *
674
- * @param tableName - name of the table to drop
675
- * @param fn - create table callback
676
- * @param dataFn - callback for creating composite indexes, primary keys, foreign keys
677
- */
678
- dropTable<Table extends string, Shape extends ColumnsShape>(tableName: Table, fn?: ColumnsShapeCallback<CT, Shape>, dataFn?: TableDataFn<Shape, MaybeArray<TableDataItem>>): Promise<CreateTableResult<Table, Shape>>;
679
- /**
680
- * Drop the table, create it on rollback. See {@link createTable}.
681
- *
682
- * @param tableName - name of the table to drop
683
- * @param options - {@link TableOptions}
684
- * @param fn - create table callback
685
- * @param dataFn - callback for creating composite indexes, primary keys, foreign keys
686
- */
687
- dropTable<Table extends string, Shape extends ColumnsShape>(tableName: Table, options: TableOptions, fn?: ColumnsShapeCallback<CT, Shape>, dataFn?: TableDataFn<Shape, MaybeArray<TableDataItem>>): Promise<CreateTableResult<Table, Shape>>;
688
- /**
689
- * `changeTable` accepts a table name, optional options, and a special callback with column changes.
690
- *
691
- * When changing a table within a specific schema, write the table name with schema name: `'schemaName.tableName'`.
692
- *
693
- * Options are:
694
- *
695
- * ```ts
696
- * type ChangeTableOptions = {
697
- * comment?:
698
- * | // add a comment to the table on migrating, remove a comment on rollback
699
- * string // change comment from first to second on migrating, from second to first on rollback
700
- * | [string, string] // remove a comment on both migrate and rollback
701
- * | null;
702
- *
703
- * // override rakeDb `snakeCase` option for only this table
704
- * snakeCase?: boolean;
705
- * };
706
- * ```
707
- *
708
- * The callback of the `changeTable` is different from `createTable` in the way that it expects columns to be wrapped in change methods such as `add`, `drop`, and `change`.
709
- *
710
- * @param tableName - name of the table to change (ALTER)
711
- * @param fn - change table callback
712
- */
713
- changeTable(tableName: string, fn: ChangeTableCallback<CT>): Promise<void>;
714
- /**
715
- * See {@link changeTable}
716
- *
717
- * @param tableName - name of the table to change (ALTER)
718
- * @param options - change table options
719
- * @param fn - change table callback
720
- */
721
- changeTable(tableName: string, options: ChangeTableOptions, fn?: ChangeTableCallback<CT>): Promise<void>;
722
- /**
723
- * Rename a table:
724
- *
725
- * ```ts
726
- * import { change } from '../dbScript';
727
- *
728
- * change(async (db) => {
729
- * await db.renameTable('oldTableName', 'newTableName');
730
- * });
731
- * ```
732
- *
733
- * Prefix table name with a schema to set a different schema:
734
- *
735
- * ```ts
736
- * import { change } from '../dbScript';
737
- *
738
- * change(async (db) => {
739
- * await db.renameTable('fromSchema.oldTable', 'toSchema.newTable');
740
- * });
741
- * ```
742
- *
743
- * @param from - rename the table from
744
- * @param to - rename the table to
745
- */
746
- renameTable(from: string, to: string): Promise<void>;
747
- /**
748
- * Set a different schema to the table:
749
- *
750
- * ```ts
751
- * import { change } from '../dbScript';
752
- *
753
- * change(async (db) => {
754
- * await db.changeTableSchema('tableName', 'fromSchema', 'toSchema');
755
- * });
756
- * ```
757
- *
758
- * @param table - table name
759
- * @param from - current table schema
760
- * @param to - desired table schema
761
- */
762
- changeTableSchema(table: string, from: string, to: string): Promise<void>;
763
- /**
764
- * Add a column to the table on migrating, and remove it on rollback.
765
- *
766
- * `dropColumn` takes the same arguments, removes a column on migrate, and adds it on rollback.
767
- *
768
- * ```ts
769
- * import { change } from '../dbScript';
770
- *
771
- * change(async (db) => {
772
- * await db.addColumn('tableName', 'columnName', (t) =>
773
- * t.integer().index().nullable(),
774
- * );
775
- * });
776
- * ```
777
- *
778
- * @param tableName - name of the table to add the column to
779
- * @param columnName - name of the column to add
780
- * @param fn - function returning a type of the column
781
- */
782
- addColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes<CT>) => Column): Promise<void>;
783
- /**
784
- * Drop the schema, create it on rollback. See {@link addColumn}.
785
- *
786
- * @param tableName - name of the table to add the column to
787
- * @param columnName - name of the column to add
788
- * @param fn - function returning a type of the column
789
- */
790
- dropColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes<CT>) => Column): Promise<void>;
791
- /**
792
- * Add an index to the table on migrating, and remove it on rollback.
793
- *
794
- * `dropIndex` takes the same arguments, removes the index on migrate, and adds it on rollback.
795
- *
796
- * The first argument is the table name, other arguments are the same as in [composite index](#composite-index).
797
- *
798
- * ```ts
799
- * import { change } from '../dbScript';
800
- *
801
- * change(async (db) => {
802
- * await db.addIndex(
803
- * 'tableName',
804
- * ['column1', { column: 'column2', order: 'DESC' }],
805
- * {
806
- * name: 'indexName',
807
- * },
808
- * );
809
- * });
810
- * ```
811
- *
812
- * @param tableName - name of the table to add the index for
813
- * @param columns - indexed columns
814
- * @param args - index options
815
- */
816
- addIndex(tableName: string, columns: (string | TableData.Index.ColumnOrExpressionOptions)[], ...args: [options?: TableData.Index.OptionsArg]): Promise<void>;
817
- /**
818
- * Drop the schema, create it on rollback. See {@link addIndex}.
819
- *
820
- * @param tableName - name of the table to add the index for
821
- * @param columns - indexed columns
822
- * @param args - index options
823
- */
824
- dropIndex(tableName: string, columns: (string | TableData.Index.ColumnOrExpressionOptions)[], ...args: [options?: TableData.Index.OptionsArg]): Promise<void>;
825
- /**
826
- * Rename index:
827
- *
828
- * ```ts
829
- * import { change } from '../dbScript';
830
- *
831
- * change(async (db) => {
832
- * // tableName can be prefixed with a schema
833
- * await db.renameIndex('tableName', 'oldIndexName', 'newIndexName');
834
- * });
835
- * ```
836
- *
837
- * @param tableName - table which this index belongs to
838
- * @param from - rename the index from
839
- * @param to - rename the index to
840
- */
841
- renameIndex(tableName: string, from: string, to: string): Promise<void>;
842
- /**
843
- * Add a foreign key to a table on migrating, and remove it on rollback.
844
- *
845
- * `dropForeignKey` takes the same arguments, removes the foreign key on migrate, and adds it on rollback.
846
- *
847
- * Arguments:
848
- *
849
- * - table name
850
- * - column names in the table
851
- * - other table name
852
- * - column names in the other table
853
- * - options:
854
- * - `name`: constraint name
855
- * - `match`: 'FULL', 'PARTIAL', or 'SIMPLE'
856
- * - `onUpdate` and `onDelete`: 'NO ACTION', 'RESTRICT', 'CASCADE', 'SET NULL', or 'SET DEFAULT'
857
- *
858
- * The first argument is the table name, other arguments are the same as in [composite foreign key](#composite-foreign-key).
859
- *
860
- * ```ts
861
- * import { change } from '../dbScript';
862
- *
863
- * change(async (db) => {
864
- * await db.addForeignKey(
865
- * 'tableName',
866
- * ['id', 'name'],
867
- * 'otherTable',
868
- * ['foreignId', 'foreignName'],
869
- * {
870
- * name: 'constraintName',
871
- * match: 'FULL',
872
- * onUpdate: 'RESTRICT',
873
- * onDelete: 'CASCADE',
874
- * },
875
- * );
876
- * });
877
- * ```
878
- *
879
- * @param tableName - table name
880
- * @param columns - column names in the table
881
- * @param foreignTable - other table name
882
- * @param foreignColumns - column names in the other table
883
- * @param options - foreign key options
884
- */
885
- addForeignKey(tableName: string, columns: [string, ...string[]], foreignTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options): Promise<void>;
886
- /**
887
- * Drop the schema, create it on rollback. See {@link addForeignKey}.
888
- *
889
- * @param tableName - table name
890
- * @param columns - column names in the table
891
- * @param foreignTable - other table name
892
- * @param foreignColumns - column names in the other table
893
- * @param options - foreign key options
894
- */
895
- dropForeignKey(tableName: string, columns: [string, ...string[]], foreignTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options): Promise<void>;
896
- /**
897
- * Add a primary key to a table on migrate, and remove it on rollback.
898
- *
899
- * `dropPrimaryKey` takes the same arguments, removes the primary key on migrate, and adds it on rollback.
900
- *
901
- * First argument is a table name, second argument is an array of columns.
902
- * The optional third argument may have a name for the primary key constraint.
903
- *
904
- * ```ts
905
- * import { change } from '../dbScript';
906
- *
907
- * change(async (db) => {
908
- * await db.addPrimaryKey('tableName', ['id', 'name'], {
909
- * name: 'tablePkeyName',
910
- * });
911
- * });
912
- * ```
913
- *
914
- * @param tableName - name of the table
915
- * @param columns - array of the columns
916
- * @param name - optionally, set a primary key constraint name
917
- */
918
- addPrimaryKey(tableName: string, columns: [string, ...string[]], name?: string): Promise<void>;
919
- /**
920
- * Drop the schema, create it on rollback. See {@link addPrimaryKey}.
921
- *
922
- * @param tableName - name of the table
923
- * @param columns - array of the columns
924
- * @param name - optionally, set a primary key constraint name
925
- */
926
- dropPrimaryKey(tableName: string, columns: [string, ...string[]], name?: string): Promise<void>;
927
- /**
928
- * Add or drop a check for multiple columns.
929
- *
930
- * ```ts
931
- * import { change } from '../dbScript';
932
- *
933
- * change(async (db) => {
934
- * await db.addCheck('tableName', t.sql`column > 123`);
935
- * });
936
- * ```
937
- *
938
- * @param tableName - name of the table to add the check into
939
- * @param check - raw SQL for the check
940
- */
941
- addCheck(tableName: string, check: RawSqlBase): Promise<void>;
942
- /**
943
- * Drop the schema, create it on rollback. See {@link addCheck}.
944
- *
945
- * @param tableName - name of the table to add the check into
946
- * @param check - raw SQL for the check
947
- */
948
- dropCheck(tableName: string, check: RawSqlBase): Promise<void>;
949
- /**
950
- * Rename a table constraint such as a primary key or a database check.
951
- *
952
- * ```ts
953
- * import { change } from '../dbScript';
954
- *
955
- * change(async (db) => {
956
- * await db.renameConstraint(
957
- * 'tableName', // may include schema: 'schema.table'
958
- * 'oldConstraintName',
959
- * 'newConstraintName',
960
- * );
961
- * });
962
- * ```
963
- *
964
- * @param tableName - name of the table containing the constraint, may include schema name, may include schema name
965
- * @param from - current name of the constraint
966
- * @param to - desired name
967
- */
968
- renameConstraint(tableName: string, from: string, to: string): Promise<void>;
969
- /**
970
- * Rename a column:
971
- *
972
- * ```ts
973
- * import { change } from '../dbScript';
974
- *
975
- * change(async (db) => {
976
- * await db.renameColumn('tableName', 'oldColumnName', 'newColumnName');
977
- * });
978
- * ```
979
- *
980
- * @param tableName - name of the table to rename the column in
981
- * @param from - rename column from
982
- * @param to - rename column to
983
- */
984
- renameColumn(tableName: string, from: string, to: string): Promise<void>;
985
- /**
986
- * `createSchema` creates a database schema, and removes it on rollback.
987
- *
988
- * `dropSchema` takes the same arguments, removes schema on migration, and adds it on rollback.
989
- *
990
- * ```ts
991
- * import { change } from '../dbScript';
992
- *
993
- * change(async (db) => {
994
- * await db.createSchema('schemaName');
995
- * });
996
- * ```
997
- *
998
- * @param schemaName - name of the schema
999
- */
1000
- createSchema(schemaName: string): Promise<void>;
1001
- /**
1002
- * Renames a database schema, renames it backwards on roll back.
1003
- *
1004
- * ```ts
1005
- * import { change } from '../dbScript';
1006
- *
1007
- * change(async (db) => {
1008
- * await db.renameSchema('from', 'to');
1009
- * });
1010
- * ```
1011
- *
1012
- * @param from - existing schema to rename
1013
- * @param to - desired schema name
1014
- */
1015
- renameSchema(from: string, to: string): Promise<void>;
1016
- /**
1017
- * Drop the schema, create it on rollback. See {@link createSchema}.
1018
- *
1019
- * @param schemaName - name of the schema
1020
- */
1021
- dropSchema(schemaName: string): Promise<void>;
1022
- /**
1023
- * `createExtension` creates a database extension, and removes it on rollback.
1024
- *
1025
- * `dropExtension` takes the same arguments, removes the extension on migrate, and adds it on rollback.
1026
- *
1027
- * ```ts
1028
- * import { change } from '../dbScript';
1029
- *
1030
- * change(async (db) => {
1031
- * await db.createExtension('pg_trgm');
1032
- * });
1033
- * ```
1034
- *
1035
- * @param name - name of the extension
1036
- * @param options - extension options
1037
- */
1038
- createExtension(name: string, options?: RakeDbAst.ExtensionArg): Promise<void>;
1039
- /**
1040
- * Drop the extension, create it on rollback. See {@link createExtension}.
1041
- *
1042
- * @param name - name of the extension
1043
- * @param options - extension options
1044
- */
1045
- dropExtension(name: string, options?: RakeDbAst.ExtensionArg): Promise<void>;
1046
- /**
1047
- * `createEnum` creates an enum on migrate, drops it on rollback.
1048
- *
1049
- * `dropEnum` does the opposite.
1050
- *
1051
- * Third argument for options is optional.
1052
- *
1053
- * ```ts
1054
- * import { change } from '../dbScript';
1055
- *
1056
- * change(async (db) => {
1057
- * await db.createEnum('number', ['one', 'two', 'three']);
1058
- *
1059
- * // use `schemaName.enumName` format to specify a schema
1060
- * await db.createEnum('customSchema.mood', ['sad', 'ok', 'happy'], {
1061
- * // following options are used when dropping enum
1062
- * dropIfExists: true,
1063
- * cascade: true,
1064
- * });
1065
- * });
1066
- * ```
1067
- *
1068
- * @param name - name of the enum
1069
- * @param values - possible enum values
1070
- * @param options - enum options
1071
- */
1072
- createEnum(name: string, values: [string, ...string[]], options?: Omit<RakeDbAst.Enum, 'type' | 'action' | 'name' | 'values' | 'schema'>): Promise<void>;
1073
- /**
1074
- * Drop the enum, create it on rollback. See {@link createEnum}.
1075
- *
1076
- * @param name - name of the enum
1077
- * @param values - possible enum values
1078
- * @param options - enum options
1079
- */
1080
- dropEnum(name: string, values: [string, ...string[]], options?: Omit<RakeDbAst.Enum, 'type' | 'action' | 'name' | 'values' | 'schema'>): Promise<void>;
1081
- /**
1082
- * Use these methods to add or drop one or multiple values from an existing enum.
1083
- *
1084
- * `addEnumValues` will drop values when rolling back the migration.
1085
- *
1086
- * Dropping a value internally acts in multiple steps:
1087
- *
1088
- * 1. Select all columns from the database that depends on the enum;
1089
- * 2. Alter all these columns to have text type;
1090
- * 3. Drop the enum;
1091
- * 4. Re-create the enum without the value given;
1092
- * 5. Alter all columns from the first step to have the enum type;
1093
- *
1094
- * In the case when the value is used by some table,
1095
- * migrating `dropEnumValue` or rolling back `addEnumValue` will throw an error with a descriptive message,
1096
- * in such case you'd need to manually resolve the issue by deleting rows with the value, or changing such values.
1097
- *
1098
- * ```ts
1099
- * import { change } from '../dbScript';
1100
- *
1101
- * change(async (db) => {
1102
- * await db.addEnumValue('numbers', 'four');
1103
- *
1104
- * // you can pass options
1105
- * await db.addEnumValue('numbers', 'three', {
1106
- * // where to insert
1107
- * before: 'four',
1108
- * // skip if already exists
1109
- * ifNotExists: true,
1110
- * });
1111
- *
1112
- * // enum name can be prefixed with schema
1113
- * await db.addEnumValue('public.numbers', 'five', {
1114
- * after: 'four',
1115
- * });
1116
- * });
1117
- * ```
1118
- *
1119
- * @param enumName - target enum name
1120
- * @param values - array of values to add
1121
- * @param options - optional object with options
1122
- * @param options.before - insert before the specified value
1123
- * @param options.after - insert after the specified value
1124
- * @param options.ifNotExists - skip adding if already exists
1125
- */
1126
- addEnumValues(enumName: string, values: string[], options?: AddEnumValueOptions): Promise<void>;
1127
- /**
1128
- * See {@link addEnumValues}
1129
- */
1130
- dropEnumValues(enumName: string, values: string[], options?: AddEnumValueOptions): Promise<void>;
1131
- /**
1132
- * Rename one or multiple enum values using this method:
1133
- *
1134
- * ```ts
1135
- * import { change } from '../dbScript';
1136
- *
1137
- * change(async (db) => {
1138
- * // rename value "from" to "to"
1139
- * await db.rename('numbers', { from: 'to' });
1140
- *
1141
- * // enum name can be prefixed with schema
1142
- * await db.rename('public.numbers', { from: 'to' });
1143
- * });
1144
- * ```
1145
- *
1146
- * @param enumName - target enum name, can be prefixed with schema
1147
- * @param values - object where keys are for old names, values are for new names
1148
- */
1149
- renameEnumValues(enumName: string, values: RecordString): Promise<void>;
1150
- /**
1151
- * Drops the enum and re-creates it with a new set of values.
1152
- * Before dropping, changes all related column types to text, and after creating changes types back to the enum,
1153
- * in the same way as [dropEnumValues](/guide/migration-writing.html#addenumvalues,-dropenumvalues) works.
1154
- *
1155
- * ```ts
1156
- * import { change } from '../dbScript';
1157
- *
1158
- * change(async (db) => {
1159
- * await db.changeEnumValues(
1160
- * // can be prefixed with schema: 'public.numbers'
1161
- * 'numbers',
1162
- * // change from:
1163
- * ['one', 'two'],
1164
- * // change to:
1165
- * ['three', 'four'],
1166
- * );
1167
- * });
1168
- * ```
1169
- *
1170
- * @param enumName - target enum name, can be prefixed with schema
1171
- * @param fromValues - array of values before the change
1172
- * @param toValues - array of values to set
1173
- */
1174
- changeEnumValues(enumName: string, fromValues: string[], toValues: string[]): Promise<void>;
1175
- /**
1176
- * Rename a type (such as enum):
1177
- *
1178
- * ```ts
1179
- * import { change } from '../dbScript';
1180
- *
1181
- * change(async (db) => {
1182
- * await db.renameType('oldTypeName', 'newTypeName');
1183
- * });
1184
- * ```
1185
- *
1186
- * Prefix the type name with a schema to set a different schema:
1187
- *
1188
- * ```ts
1189
- * import { change } from '../dbScript';
1190
- *
1191
- * change(async (db) => {
1192
- * await db.renameType('fromSchema.oldType', 'toSchema.newType');
1193
- * });
1194
- * ```
1195
- *
1196
- * @param from - rename the type from
1197
- * @param to - rename the type to
1198
- */
1199
- renameType(from: string, to: string): Promise<void>;
1200
- /**
1201
- * Set a different schema to the type (such as enum):
1202
- *
1203
- * ```ts
1204
- * import { change } from '../dbScript';
1205
- *
1206
- * change(async (db) => {
1207
- * await db.changeTypeSchema('typeName', 'fromSchema', 'toSchema');
1208
- * });
1209
- * ```
1210
- *
1211
- * @param name - type name
1212
- * @param from - current table schema
1213
- * @param to - desired table schema
1214
- */
1215
- changeTypeSchema(name: string, from: string, to: string): Promise<void>;
1216
- /**
1217
- * Domain is a custom database type that is based on other type and can include `NOT NULL` and a `CHECK` (see [postgres tutorial](https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-user-defined-data-types/)).
1218
- *
1219
- * Construct a column type in the function as the second argument.
1220
- *
1221
- * Specifiers [nullable](/guide/common-column-methods.html#nullable), [default](/guide/common-column-methods.html#default), [check](/guide/migration-column-methods.html#check), [collate](/guide/migration-column-methods.html#collate)
1222
- * will be saved to the domain type on database level.
1223
- *
1224
- * ```ts
1225
- * import { change } from '../dbScript';
1226
- *
1227
- * change(async (db) => {
1228
- * await db.createDomain('domainName', (t) =>
1229
- * t.integer().check(t.sql`value = 42`),
1230
- * );
1231
- *
1232
- * // use `schemaName.domainName` format to specify a schema
1233
- * await db.createDomain('schemaName.domainName', (t) =>
1234
- * t
1235
- * .text()
1236
- * .nullable()
1237
- * .collate('C')
1238
- * .default('default text')
1239
- * .check(t.sql`length(value) > 10`),
1240
- * );
1241
- * });
1242
- * ```
1243
- *
1244
- * @param name - name of the domain
1245
- * @param fn - function returning a column type. Options `nullable`, `collate`, `default`, `check` will be applied to domain
1246
- */
1247
- createDomain(name: string, fn: DbDomainArg<CT>): Promise<void>;
1248
- /**
1249
- * Drop the domain, create it on rollback. See {@link dropDomain}.
1250
- *
1251
- * @param name - name of the domain
1252
- * @param fn - function returning a column type. Options `nullable`, `collate`, `default`, `check` will be applied to domain
1253
- */
1254
- dropDomain(name: string, fn: DbDomainArg<CT>): Promise<void>;
1255
- /**
1256
- * To rename a domain:
1257
- *
1258
- * ```ts
1259
- * import { change } from '../dbScript';
1260
- *
1261
- * change(async (db) => {
1262
- * await db.renameDomain('oldName', 'newName');
1263
- *
1264
- * // to move domain to a different schema
1265
- * await db.renameDomain('oldSchema.domain', 'newSchema.domain');
1266
- * });
1267
- * ```
1268
- *
1269
- * @param from - old domain name (can include schema)
1270
- * @param to - new domain name (can include schema)
1271
- */
1272
- renameDomain(from: string, to: string): Promise<void>;
1273
- /**
1274
- * Create and drop a database collation, (see [Postgres docs](https://www.postgresql.org/docs/current/sql-createcollation.html)).
1275
- *
1276
- * ```ts
1277
- * import { change } from '../dbScript';
1278
- *
1279
- * change(async (db) => {
1280
- * await db.createCollation('myCollation', {
1281
- * // This is a shortcut for setting lcCollate and lcCType at once.
1282
- * locale: 'en-u-kn-true',
1283
- *
1284
- * // set `lcType` and `lcCType` only if the `locale` is not set.
1285
- * // lcType: 'C',
1286
- * // lcCType: 'C',
1287
- *
1288
- * // provider can be 'icu' or 'libc'. 'libc' is a default.
1289
- * provider: 'icu',
1290
- *
1291
- * // true by default, false is only supported with 'icu' provider.
1292
- * deterministic: true,
1293
- *
1294
- * // Is intended to by used by `pg_upgrade`. Normally, it should be omitted.
1295
- * version: '1.2.3',
1296
- *
1297
- * // For `CREATE IF NOT EXISTS` when creating.
1298
- * createIfNotExists: true,
1299
- *
1300
- * // For `DROP IF EXISTS` when dropping.
1301
- * dropIfExists: true,
1302
- *
1303
- * // For `DROP ... CASCADE` when dropping.
1304
- * cascase: true,
1305
- * });
1306
- * });
1307
- * ```
1308
- *
1309
- * Instead of specifying the collation options, you can specify a collation to copy options from.
1310
- *
1311
- * ```ts
1312
- * import { change } from '../dbScript';
1313
- *
1314
- * change(async (db) => {
1315
- * await db.createCollation('myCollation', {
1316
- * fromExisting: 'otherCollation',
1317
- * });
1318
- * });
1319
- * ```
1320
- *
1321
- * To create a collation withing a specific database schema, prepend it to the collation name:
1322
- *
1323
- * ```ts
1324
- * import { change } from '../dbScript';
1325
- *
1326
- * change(async (db) => {
1327
- * await db.createCollation('schemaName.myCollation', {
1328
- * // `fromExisting` also can accept a collation name with a schema.
1329
- * fromExisting: 'schemaName.otherCollation',
1330
- * });
1331
- * });
1332
- * ```
1333
- *
1334
- * @param name - name of the collation, can contain a name of schema separated with a dot.
1335
- * @param options - options to create and drop the collation.
1336
- */
1337
- createCollation(name: string, options: Omit<RakeDbAst.Collation, 'type' | 'action' | 'schema' | 'name'>): Promise<void>;
1338
- /**
1339
- * Drop the collation, create it on rollback. See {@link createCollation}.
1340
- *
1341
- * @param name - name of the collation, can contain a name of schema separated with a dot.
1342
- * @param options - options to create and drop the collation.
1343
- */
1344
- dropCollation(name: string, options: Omit<RakeDbAst.Collation, 'type' | 'action' | 'schema' | 'name'>): Promise<void>;
1345
- /**
1346
- * Create and drop database views.
1347
- *
1348
- * Provide SQL as a string or via `t.sql` that can accept variables.
1349
- *
1350
- * ```ts
1351
- * import { change } from '../dbScript';
1352
- *
1353
- * change(async (db) => {
1354
- * await db.createView(
1355
- * 'simpleView',
1356
- * `
1357
- * SELECT a.one, b.two
1358
- * FROM a
1359
- * JOIN b ON b."aId" = a.id
1360
- * `,
1361
- * );
1362
- *
1363
- * // view can accept t.sql with variables in such way:
1364
- * const value = 'some value';
1365
- * await db.createView(
1366
- * 'viewWithVariables',
1367
- * t.sql`
1368
- * SELECT * FROM a WHERE key = ${value}
1369
- * `,
1370
- * );
1371
- *
1372
- * // view with options
1373
- * await db.createView(
1374
- * 'schemaName.recursiveView',
1375
- * {
1376
- * // createOrReplace has effect when creating the view
1377
- * createOrReplace: true,
1378
- *
1379
- * // dropIfExists and dropMode have effect when dropping the view
1380
- * dropIfExists: true,
1381
- * dropMode: 'CASCADE',
1382
- *
1383
- * // for details, check Postgres docs for CREATE VIEW,
1384
- * // these options are matching CREATE VIEW options
1385
- * temporary: true,
1386
- * recursive: true,
1387
- * columns: ['n'],
1388
- * with: {
1389
- * checkOption: 'LOCAL', // or 'CASCADED'
1390
- * securityBarrier: true,
1391
- * securityInvoker: true,
1392
- * },
1393
- * },
1394
- * `
1395
- * VALUES (1)
1396
- * UNION ALL
1397
- * SELECT n + 1 FROM "schemaName"."recursiveView" WHERE n < 100;
1398
- * `,
1399
- * );
1400
- * });
1401
- * ```
1402
- *
1403
- * @param name - name of the view
1404
- * @param options - view options
1405
- * @param sql - SQL to create the view with
1406
- */
1407
- createView(name: string, options: RakeDbAst.ViewOptions, sql: string | RawSqlBase): Promise<void>;
1408
- /**
1409
- * See {@link createView}
1410
- *
1411
- * @param name - name of the view
1412
- * @param sql - SQL to create the view with
1413
- */
1414
- createView(name: string, sql: string | RawSqlBase): Promise<void>;
1415
- /**
1416
- * Drop the view, create it on rollback. See {@link createView}.
1417
- *
1418
- * @param name - name of the view
1419
- * @param options - view options
1420
- * @param sql - SQL to create the view with
1421
- */
1422
- dropView(name: string, options: RakeDbAst.ViewOptions, sql: string | RawSqlBase): Promise<void>;
1423
- /**
1424
- * Drop the view, create it on rollback. See {@link createView}.
1425
- *
1426
- * @param name - name of the view
1427
- * @param sql - SQL to create the view with
1428
- */
1429
- dropView(name: string, sql: string | RawSqlBase): Promise<void>;
1430
- /**
1431
- * Returns boolean to know if table exists:
1432
- *
1433
- * ```ts
1434
- * import { change } from '../dbScript';
1435
- *
1436
- * change(async (db) => {
1437
- * if (await db.tableExists('tableName')) {
1438
- * // ...do something
1439
- * }
1440
- * });
1441
- * ```
1442
- *
1443
- * @param tableName - name of the table
1444
- */
1445
- tableExists(tableName: string): Promise<boolean>;
1446
- /**
1447
- * Returns boolean to know if a column exists:
1448
- *
1449
- * Note that when `snakeCase` option is set to true, this method won't translate column to snake case, unlike other parts.
1450
- *
1451
- * ```ts
1452
- * import { change } from '../dbScript';
1453
- *
1454
- * change(async (db) => {
1455
- * if (await db.columnExists('tableName', 'columnName')) {
1456
- * // ...do something
1457
- * }
1458
- * });
1459
- * ```
1460
- *
1461
- * @param tableName - name of the table to check for the column in
1462
- * @param columnName - name of the column
1463
- */
1464
- columnExists(tableName: string, columnName: string): Promise<boolean>;
1465
- /**
1466
- * Returns boolean to know if constraint exists:
1467
- *
1468
- * ```ts
1469
- * import { change } from '../dbScript';
1470
- *
1471
- * change(async (db) => {
1472
- * if (await db.constraintExists('constraintName')) {
1473
- * // ...do something
1474
- * }
1475
- * });
1476
- * ```
1477
- *
1478
- * @param constraintName - name of the constraint
1479
- */
1480
- constraintExists(constraintName: string): Promise<boolean>;
1481
- createRole(name: string, params?: Partial<DbStructure.Role>): Promise<void>;
1482
- dropRole(name: string, params?: Partial<DbStructure.Role>): Promise<void>;
1483
- renameRole(from: string, to: string): Promise<void>;
1484
- changeRole(name: string, params: {
1485
- from?: Partial<DbStructure.Role>;
1486
- to: Partial<DbStructure.Role>;
1487
- }): Promise<void>;
1488
- changeDefaultPrivileges(params: ChangeDefaultPrivilegesArg): Promise<void>;
535
+ adapter: MigrationAdapter;
536
+ log?: QueryLogObject;
537
+ up: boolean;
538
+ options: RakeDbConfig;
539
+ columnTypes: CT;
540
+ /**
541
+ * `createTable` accepts a string for a table name, optional options, and a callback to specify columns.
542
+ *
543
+ * `dropTable` accepts the same arguments, it will drop the table when migrating and create a table when rolling back.
544
+ *
545
+ * To create an empty table, the callback with columns may be omitted.
546
+ *
547
+ * When creating a table within a specific schema, write the table name with schema name: `'schemaName.tableName'`.
548
+ *
549
+ * Returns object `{ table: TableInterface }` that allows to insert records right after creating a table.
550
+ *
551
+ * Options are:
552
+ *
553
+ * ```ts
554
+ * type TableOptions = {
555
+ * // create the table only if it not exists already
556
+ * createIfNotExists?: boolean;
557
+ *
558
+ * // drop the table only if it exists
559
+ * dropIfExists?: boolean;
560
+ *
561
+ * // used when reverting a `createTable`
562
+ * dropMode?: 'CASCADE' | 'RESTRICT';
563
+ *
564
+ * // add a database comment on the table
565
+ * comment?: string;
566
+ *
567
+ * // by default, it will throw an error when the table has no primary key
568
+ * // set `noPrimaryKey` to `true` to bypass it
569
+ * noPrimaryKey?: boolean;
570
+ *
571
+ * // override rakeDb `snakeCase` option for only this table
572
+ * snakeCase?: boolean;
573
+ * };
574
+ * ```
575
+ *
576
+ * Example:
577
+ *
578
+ * ```ts
579
+ * import { change } from '../dbScript';
580
+ *
581
+ * change(async (db, up) => {
582
+ * // call `createTable` with options
583
+ * await db.createTable(
584
+ * 'table',
585
+ * {
586
+ * comment: 'Table comment',
587
+ * dropMode: 'CASCADE',
588
+ * noPrimaryKey: true,
589
+ * },
590
+ * (t) => ({
591
+ * // ...
592
+ * }),
593
+ * );
594
+ *
595
+ * // call without options
596
+ * const { table } = await db.createTable('user', (t) => ({
597
+ * id: t.identity().primaryKey(),
598
+ * email: t.text().unique(),
599
+ * name: t.text(),
600
+ * active: t.boolean().nullable(),
601
+ * ...t.timestamps(),
602
+ * }));
603
+ *
604
+ * // create records only when migrating up
605
+ * if (up) {
606
+ * // table is a db table interface, all query methods are available
607
+ * await table.createMany([...data]);
608
+ * }
609
+ * });
610
+ * ```
611
+ *
612
+ * @param tableName - name of the table to create
613
+ * @param fn - create table callback
614
+ * @param dataFn - callback for creating composite indexes, primary keys, foreign keys
615
+ */
616
+ createTable<Table extends string, Shape extends ColumnsShape>(tableName: Table, fn?: ColumnsShapeCallback<CT, Shape>, dataFn?: TableDataFn<Shape, MaybeArray<TableDataItem>>): Promise<CreateTableResult<Table, Shape>>;
617
+ /**
618
+ * See {@link createTable}
619
+ *
620
+ * @param tableName - name of the table to create
621
+ * @param options - {@link TableOptions}
622
+ * @param fn - create table callback
623
+ * @param dataFn - callback for creating composite indexes, primary keys, foreign keys
624
+ */
625
+ createTable<Table extends string, Shape extends ColumnsShape>(tableName: Table, options: TableOptions, fn?: ColumnsShapeCallback<CT, Shape>, dataFn?: TableDataFn<Shape, MaybeArray<TableDataItem>>): Promise<CreateTableResult<Table, Shape>>;
626
+ /**
627
+ * Drop the table, create it on rollback. See {@link createTable}.
628
+ *
629
+ * @param tableName - name of the table to drop
630
+ * @param fn - create table callback
631
+ * @param dataFn - callback for creating composite indexes, primary keys, foreign keys
632
+ */
633
+ dropTable<Table extends string, Shape extends ColumnsShape>(tableName: Table, fn?: ColumnsShapeCallback<CT, Shape>, dataFn?: TableDataFn<Shape, MaybeArray<TableDataItem>>): Promise<CreateTableResult<Table, Shape>>;
634
+ /**
635
+ * Drop the table, create it on rollback. See {@link createTable}.
636
+ *
637
+ * @param tableName - name of the table to drop
638
+ * @param options - {@link TableOptions}
639
+ * @param fn - create table callback
640
+ * @param dataFn - callback for creating composite indexes, primary keys, foreign keys
641
+ */
642
+ dropTable<Table extends string, Shape extends ColumnsShape>(tableName: Table, options: TableOptions, fn?: ColumnsShapeCallback<CT, Shape>, dataFn?: TableDataFn<Shape, MaybeArray<TableDataItem>>): Promise<CreateTableResult<Table, Shape>>;
643
+ /**
644
+ * `changeTable` accepts a table name, optional options, and a special callback with column changes.
645
+ *
646
+ * When changing a table within a specific schema, write the table name with schema name: `'schemaName.tableName'`.
647
+ *
648
+ * Options are:
649
+ *
650
+ * ```ts
651
+ * type ChangeTableOptions = {
652
+ * comment?:
653
+ * | // add a comment to the table on migrating, remove a comment on rollback
654
+ * string // change comment from first to second on migrating, from second to first on rollback
655
+ * | [string, string] // remove a comment on both migrate and rollback
656
+ * | null;
657
+ *
658
+ * // override rakeDb `snakeCase` option for only this table
659
+ * snakeCase?: boolean;
660
+ * };
661
+ * ```
662
+ *
663
+ * The callback of the `changeTable` is different from `createTable` in the way that it expects columns to be wrapped in change methods such as `add`, `drop`, and `change`.
664
+ *
665
+ * @param tableName - name of the table to change (ALTER)
666
+ * @param fn - change table callback
667
+ */
668
+ changeTable(tableName: string, fn: ChangeTableCallback<CT>): Promise<void>;
669
+ /**
670
+ * See {@link changeTable}
671
+ *
672
+ * @param tableName - name of the table to change (ALTER)
673
+ * @param options - change table options
674
+ * @param fn - change table callback
675
+ */
676
+ changeTable(tableName: string, options: ChangeTableOptions, fn?: ChangeTableCallback<CT>): Promise<void>;
677
+ /**
678
+ * Rename a table:
679
+ *
680
+ * ```ts
681
+ * import { change } from '../dbScript';
682
+ *
683
+ * change(async (db) => {
684
+ * await db.renameTable('oldTableName', 'newTableName');
685
+ * });
686
+ * ```
687
+ *
688
+ * Prefix table name with a schema to set a different schema:
689
+ *
690
+ * ```ts
691
+ * import { change } from '../dbScript';
692
+ *
693
+ * change(async (db) => {
694
+ * await db.renameTable('fromSchema.oldTable', 'toSchema.newTable');
695
+ * });
696
+ * ```
697
+ *
698
+ * @param from - rename the table from
699
+ * @param to - rename the table to
700
+ */
701
+ renameTable(from: string, to: string): Promise<void>;
702
+ /**
703
+ * Set a different schema to the table:
704
+ *
705
+ * ```ts
706
+ * import { change } from '../dbScript';
707
+ *
708
+ * change(async (db) => {
709
+ * await db.changeTableSchema('tableName', 'fromSchema', 'toSchema');
710
+ * });
711
+ * ```
712
+ *
713
+ * @param table - table name
714
+ * @param from - current table schema
715
+ * @param to - desired table schema
716
+ */
717
+ changeTableSchema(table: string, from: string, to: string): Promise<void>;
718
+ /**
719
+ * Add a column to the table on migrating, and remove it on rollback.
720
+ *
721
+ * `dropColumn` takes the same arguments, removes a column on migrate, and adds it on rollback.
722
+ *
723
+ * ```ts
724
+ * import { change } from '../dbScript';
725
+ *
726
+ * change(async (db) => {
727
+ * await db.addColumn('tableName', 'columnName', (t) =>
728
+ * t.integer().index().nullable(),
729
+ * );
730
+ * });
731
+ * ```
732
+ *
733
+ * @param tableName - name of the table to add the column to
734
+ * @param columnName - name of the column to add
735
+ * @param fn - function returning a type of the column
736
+ */
737
+ addColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes<CT>) => Column$1): Promise<void>;
738
+ /**
739
+ * Drop the schema, create it on rollback. See {@link addColumn}.
740
+ *
741
+ * @param tableName - name of the table to add the column to
742
+ * @param columnName - name of the column to add
743
+ * @param fn - function returning a type of the column
744
+ */
745
+ dropColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes<CT>) => Column$1): Promise<void>;
746
+ /**
747
+ * Add an index to the table on migrating, and remove it on rollback.
748
+ *
749
+ * `dropIndex` takes the same arguments, removes the index on migrate, and adds it on rollback.
750
+ *
751
+ * The first argument is the table name, other arguments are the same as in [composite index](#composite-index).
752
+ *
753
+ * ```ts
754
+ * import { change } from '../dbScript';
755
+ *
756
+ * change(async (db) => {
757
+ * await db.addIndex(
758
+ * 'tableName',
759
+ * ['column1', { column: 'column2', order: 'DESC' }],
760
+ * {
761
+ * name: 'indexName',
762
+ * },
763
+ * );
764
+ * });
765
+ * ```
766
+ *
767
+ * @param tableName - name of the table to add the index for
768
+ * @param columns - indexed columns
769
+ * @param args - index options
770
+ */
771
+ addIndex(tableName: string, columns: (string | TableData.Index.ColumnOrExpressionOptions)[], ...args: [options?: TableData.Index.OptionsArg]): Promise<void>;
772
+ /**
773
+ * Drop the schema, create it on rollback. See {@link addIndex}.
774
+ *
775
+ * @param tableName - name of the table to add the index for
776
+ * @param columns - indexed columns
777
+ * @param args - index options
778
+ */
779
+ dropIndex(tableName: string, columns: (string | TableData.Index.ColumnOrExpressionOptions)[], ...args: [options?: TableData.Index.OptionsArg]): Promise<void>;
780
+ /**
781
+ * Rename index:
782
+ *
783
+ * ```ts
784
+ * import { change } from '../dbScript';
785
+ *
786
+ * change(async (db) => {
787
+ * // tableName can be prefixed with a schema
788
+ * await db.renameIndex('tableName', 'oldIndexName', 'newIndexName');
789
+ * });
790
+ * ```
791
+ *
792
+ * @param tableName - table which this index belongs to
793
+ * @param from - rename the index from
794
+ * @param to - rename the index to
795
+ */
796
+ renameIndex(tableName: string, from: string, to: string): Promise<void>;
797
+ /**
798
+ * Add a foreign key to a table on migrating, and remove it on rollback.
799
+ *
800
+ * `dropForeignKey` takes the same arguments, removes the foreign key on migrate, and adds it on rollback.
801
+ *
802
+ * Arguments:
803
+ *
804
+ * - table name
805
+ * - column names in the table
806
+ * - other table name
807
+ * - column names in the other table
808
+ * - options:
809
+ * - `name`: constraint name
810
+ * - `match`: 'FULL', 'PARTIAL', or 'SIMPLE'
811
+ * - `onUpdate` and `onDelete`: 'NO ACTION', 'RESTRICT', 'CASCADE', 'SET NULL', or 'SET DEFAULT'
812
+ *
813
+ * The first argument is the table name, other arguments are the same as in [composite foreign key](#composite-foreign-key).
814
+ *
815
+ * ```ts
816
+ * import { change } from '../dbScript';
817
+ *
818
+ * change(async (db) => {
819
+ * await db.addForeignKey(
820
+ * 'tableName',
821
+ * ['id', 'name'],
822
+ * 'otherTable',
823
+ * ['foreignId', 'foreignName'],
824
+ * {
825
+ * name: 'constraintName',
826
+ * match: 'FULL',
827
+ * onUpdate: 'RESTRICT',
828
+ * onDelete: 'CASCADE',
829
+ * },
830
+ * );
831
+ * });
832
+ * ```
833
+ *
834
+ * @param tableName - table name
835
+ * @param columns - column names in the table
836
+ * @param foreignTable - other table name
837
+ * @param foreignColumns - column names in the other table
838
+ * @param options - foreign key options
839
+ */
840
+ addForeignKey(tableName: string, columns: [string, ...string[]], foreignTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options): Promise<void>;
841
+ /**
842
+ * Drop the schema, create it on rollback. See {@link addForeignKey}.
843
+ *
844
+ * @param tableName - table name
845
+ * @param columns - column names in the table
846
+ * @param foreignTable - other table name
847
+ * @param foreignColumns - column names in the other table
848
+ * @param options - foreign key options
849
+ */
850
+ dropForeignKey(tableName: string, columns: [string, ...string[]], foreignTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options): Promise<void>;
851
+ /**
852
+ * Add a primary key to a table on migrate, and remove it on rollback.
853
+ *
854
+ * `dropPrimaryKey` takes the same arguments, removes the primary key on migrate, and adds it on rollback.
855
+ *
856
+ * First argument is a table name, second argument is an array of columns.
857
+ * The optional third argument may have a name for the primary key constraint.
858
+ *
859
+ * ```ts
860
+ * import { change } from '../dbScript';
861
+ *
862
+ * change(async (db) => {
863
+ * await db.addPrimaryKey('tableName', ['id', 'name'], {
864
+ * name: 'tablePkeyName',
865
+ * });
866
+ * });
867
+ * ```
868
+ *
869
+ * @param tableName - name of the table
870
+ * @param columns - array of the columns
871
+ * @param name - optionally, set a primary key constraint name
872
+ */
873
+ addPrimaryKey(tableName: string, columns: [string, ...string[]], name?: string): Promise<void>;
874
+ /**
875
+ * Drop the schema, create it on rollback. See {@link addPrimaryKey}.
876
+ *
877
+ * @param tableName - name of the table
878
+ * @param columns - array of the columns
879
+ * @param name - optionally, set a primary key constraint name
880
+ */
881
+ dropPrimaryKey(tableName: string, columns: [string, ...string[]], name?: string): Promise<void>;
882
+ /**
883
+ * Add or drop a check for multiple columns.
884
+ *
885
+ * ```ts
886
+ * import { change } from '../dbScript';
887
+ *
888
+ * change(async (db) => {
889
+ * await db.addCheck('tableName', t.sql`column > 123`);
890
+ * });
891
+ * ```
892
+ *
893
+ * @param tableName - name of the table to add the check into
894
+ * @param check - raw SQL for the check
895
+ */
896
+ addCheck(tableName: string, check: RawSqlBase): Promise<void>;
897
+ /**
898
+ * Drop the schema, create it on rollback. See {@link addCheck}.
899
+ *
900
+ * @param tableName - name of the table to add the check into
901
+ * @param check - raw SQL for the check
902
+ */
903
+ dropCheck(tableName: string, check: RawSqlBase): Promise<void>;
904
+ /**
905
+ * Rename a table constraint such as a primary key or a database check.
906
+ *
907
+ * ```ts
908
+ * import { change } from '../dbScript';
909
+ *
910
+ * change(async (db) => {
911
+ * await db.renameConstraint(
912
+ * 'tableName', // may include schema: 'schema.table'
913
+ * 'oldConstraintName',
914
+ * 'newConstraintName',
915
+ * );
916
+ * });
917
+ * ```
918
+ *
919
+ * @param tableName - name of the table containing the constraint, may include schema name, may include schema name
920
+ * @param from - current name of the constraint
921
+ * @param to - desired name
922
+ */
923
+ renameConstraint(tableName: string, from: string, to: string): Promise<void>;
924
+ /**
925
+ * Rename a column:
926
+ *
927
+ * ```ts
928
+ * import { change } from '../dbScript';
929
+ *
930
+ * change(async (db) => {
931
+ * await db.renameColumn('tableName', 'oldColumnName', 'newColumnName');
932
+ * });
933
+ * ```
934
+ *
935
+ * @param tableName - name of the table to rename the column in
936
+ * @param from - rename column from
937
+ * @param to - rename column to
938
+ */
939
+ renameColumn(tableName: string, from: string, to: string): Promise<void>;
940
+ /**
941
+ * `createSchema` creates a database schema, and removes it on rollback.
942
+ *
943
+ * `dropSchema` takes the same arguments, removes schema on migration, and adds it on rollback.
944
+ *
945
+ * ```ts
946
+ * import { change } from '../dbScript';
947
+ *
948
+ * change(async (db) => {
949
+ * await db.createSchema('schemaName');
950
+ * });
951
+ * ```
952
+ *
953
+ * @param schemaName - name of the schema
954
+ */
955
+ createSchema(schemaName: string): Promise<void>;
956
+ /**
957
+ * Renames a database schema, renames it backwards on roll back.
958
+ *
959
+ * ```ts
960
+ * import { change } from '../dbScript';
961
+ *
962
+ * change(async (db) => {
963
+ * await db.renameSchema('from', 'to');
964
+ * });
965
+ * ```
966
+ *
967
+ * @param from - existing schema to rename
968
+ * @param to - desired schema name
969
+ */
970
+ renameSchema(from: string, to: string): Promise<void>;
971
+ /**
972
+ * Drop the schema, create it on rollback. See {@link createSchema}.
973
+ *
974
+ * @param schemaName - name of the schema
975
+ */
976
+ dropSchema(schemaName: string): Promise<void>;
977
+ /**
978
+ * `createExtension` creates a database extension, and removes it on rollback.
979
+ *
980
+ * `dropExtension` takes the same arguments, removes the extension on migrate, and adds it on rollback.
981
+ *
982
+ * ```ts
983
+ * import { change } from '../dbScript';
984
+ *
985
+ * change(async (db) => {
986
+ * await db.createExtension('pg_trgm');
987
+ * });
988
+ * ```
989
+ *
990
+ * @param name - name of the extension
991
+ * @param options - extension options
992
+ */
993
+ createExtension(name: string, options?: RakeDbAst.ExtensionArg): Promise<void>;
994
+ /**
995
+ * Drop the extension, create it on rollback. See {@link createExtension}.
996
+ *
997
+ * @param name - name of the extension
998
+ * @param options - extension options
999
+ */
1000
+ dropExtension(name: string, options?: RakeDbAst.ExtensionArg): Promise<void>;
1001
+ /**
1002
+ * `createEnum` creates an enum on migrate, drops it on rollback.
1003
+ *
1004
+ * `dropEnum` does the opposite.
1005
+ *
1006
+ * Third argument for options is optional.
1007
+ *
1008
+ * ```ts
1009
+ * import { change } from '../dbScript';
1010
+ *
1011
+ * change(async (db) => {
1012
+ * await db.createEnum('number', ['one', 'two', 'three']);
1013
+ *
1014
+ * // use `schemaName.enumName` format to specify a schema
1015
+ * await db.createEnum('customSchema.mood', ['sad', 'ok', 'happy'], {
1016
+ * // following options are used when dropping enum
1017
+ * dropIfExists: true,
1018
+ * cascade: true,
1019
+ * });
1020
+ * });
1021
+ * ```
1022
+ *
1023
+ * @param name - name of the enum
1024
+ * @param values - possible enum values
1025
+ * @param options - enum options
1026
+ */
1027
+ createEnum(name: string, values: [string, ...string[]], options?: Omit<RakeDbAst.Enum, 'type' | 'action' | 'name' | 'values' | 'schema'>): Promise<void>;
1028
+ /**
1029
+ * Drop the enum, create it on rollback. See {@link createEnum}.
1030
+ *
1031
+ * @param name - name of the enum
1032
+ * @param values - possible enum values
1033
+ * @param options - enum options
1034
+ */
1035
+ dropEnum(name: string, values: [string, ...string[]], options?: Omit<RakeDbAst.Enum, 'type' | 'action' | 'name' | 'values' | 'schema'>): Promise<void>;
1036
+ /**
1037
+ * Use these methods to add or drop one or multiple values from an existing enum.
1038
+ *
1039
+ * `addEnumValues` will drop values when rolling back the migration.
1040
+ *
1041
+ * Dropping a value internally acts in multiple steps:
1042
+ *
1043
+ * 1. Select all columns from the database that depends on the enum;
1044
+ * 2. Alter all these columns to have text type;
1045
+ * 3. Drop the enum;
1046
+ * 4. Re-create the enum without the value given;
1047
+ * 5. Alter all columns from the first step to have the enum type;
1048
+ *
1049
+ * In the case when the value is used by some table,
1050
+ * migrating `dropEnumValue` or rolling back `addEnumValue` will throw an error with a descriptive message,
1051
+ * in such case you'd need to manually resolve the issue by deleting rows with the value, or changing such values.
1052
+ *
1053
+ * ```ts
1054
+ * import { change } from '../dbScript';
1055
+ *
1056
+ * change(async (db) => {
1057
+ * await db.addEnumValue('numbers', 'four');
1058
+ *
1059
+ * // you can pass options
1060
+ * await db.addEnumValue('numbers', 'three', {
1061
+ * // where to insert
1062
+ * before: 'four',
1063
+ * // skip if already exists
1064
+ * ifNotExists: true,
1065
+ * });
1066
+ *
1067
+ * // enum name can be prefixed with schema
1068
+ * await db.addEnumValue('public.numbers', 'five', {
1069
+ * after: 'four',
1070
+ * });
1071
+ * });
1072
+ * ```
1073
+ *
1074
+ * @param enumName - target enum name
1075
+ * @param values - array of values to add
1076
+ * @param options - optional object with options
1077
+ * @param options.before - insert before the specified value
1078
+ * @param options.after - insert after the specified value
1079
+ * @param options.ifNotExists - skip adding if already exists
1080
+ */
1081
+ addEnumValues(enumName: string, values: string[], options?: AddEnumValueOptions): Promise<void>;
1082
+ /**
1083
+ * See {@link addEnumValues}
1084
+ */
1085
+ dropEnumValues(enumName: string, values: string[], options?: AddEnumValueOptions): Promise<void>;
1086
+ /**
1087
+ * Rename one or multiple enum values using this method:
1088
+ *
1089
+ * ```ts
1090
+ * import { change } from '../dbScript';
1091
+ *
1092
+ * change(async (db) => {
1093
+ * // rename value "from" to "to"
1094
+ * await db.rename('numbers', { from: 'to' });
1095
+ *
1096
+ * // enum name can be prefixed with schema
1097
+ * await db.rename('public.numbers', { from: 'to' });
1098
+ * });
1099
+ * ```
1100
+ *
1101
+ * @param enumName - target enum name, can be prefixed with schema
1102
+ * @param values - object where keys are for old names, values are for new names
1103
+ */
1104
+ renameEnumValues(enumName: string, values: RecordString): Promise<void>;
1105
+ /**
1106
+ * Drops the enum and re-creates it with a new set of values.
1107
+ * Before dropping, changes all related column types to text, and after creating changes types back to the enum,
1108
+ * in the same way as [dropEnumValues](/guide/migration-writing.html#addenumvalues,-dropenumvalues) works.
1109
+ *
1110
+ * ```ts
1111
+ * import { change } from '../dbScript';
1112
+ *
1113
+ * change(async (db) => {
1114
+ * await db.changeEnumValues(
1115
+ * // can be prefixed with schema: 'public.numbers'
1116
+ * 'numbers',
1117
+ * // change from:
1118
+ * ['one', 'two'],
1119
+ * // change to:
1120
+ * ['three', 'four'],
1121
+ * );
1122
+ * });
1123
+ * ```
1124
+ *
1125
+ * @param enumName - target enum name, can be prefixed with schema
1126
+ * @param fromValues - array of values before the change
1127
+ * @param toValues - array of values to set
1128
+ */
1129
+ changeEnumValues(enumName: string, fromValues: string[], toValues: string[]): Promise<void>;
1130
+ /**
1131
+ * Rename a type (such as enum):
1132
+ *
1133
+ * ```ts
1134
+ * import { change } from '../dbScript';
1135
+ *
1136
+ * change(async (db) => {
1137
+ * await db.renameType('oldTypeName', 'newTypeName');
1138
+ * });
1139
+ * ```
1140
+ *
1141
+ * Prefix the type name with a schema to set a different schema:
1142
+ *
1143
+ * ```ts
1144
+ * import { change } from '../dbScript';
1145
+ *
1146
+ * change(async (db) => {
1147
+ * await db.renameType('fromSchema.oldType', 'toSchema.newType');
1148
+ * });
1149
+ * ```
1150
+ *
1151
+ * @param from - rename the type from
1152
+ * @param to - rename the type to
1153
+ */
1154
+ renameType(from: string, to: string): Promise<void>;
1155
+ /**
1156
+ * Set a different schema to the type (such as enum):
1157
+ *
1158
+ * ```ts
1159
+ * import { change } from '../dbScript';
1160
+ *
1161
+ * change(async (db) => {
1162
+ * await db.changeTypeSchema('typeName', 'fromSchema', 'toSchema');
1163
+ * });
1164
+ * ```
1165
+ *
1166
+ * @param name - type name
1167
+ * @param from - current table schema
1168
+ * @param to - desired table schema
1169
+ */
1170
+ changeTypeSchema(name: string, from: string, to: string): Promise<void>;
1171
+ /**
1172
+ * Domain is a custom database type that is based on other type and can include `NOT NULL` and a `CHECK` (see [postgres tutorial](https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-user-defined-data-types/)).
1173
+ *
1174
+ * Construct a column type in the function as the second argument.
1175
+ *
1176
+ * Specifiers [nullable](/guide/common-column-methods.html#nullable), [default](/guide/common-column-methods.html#default), [check](/guide/migration-column-methods.html#check), [collate](/guide/migration-column-methods.html#collate)
1177
+ * will be saved to the domain type on database level.
1178
+ *
1179
+ * ```ts
1180
+ * import { change } from '../dbScript';
1181
+ *
1182
+ * change(async (db) => {
1183
+ * await db.createDomain('domainName', (t) =>
1184
+ * t.integer().check(t.sql`value = 42`),
1185
+ * );
1186
+ *
1187
+ * // use `schemaName.domainName` format to specify a schema
1188
+ * await db.createDomain('schemaName.domainName', (t) =>
1189
+ * t
1190
+ * .text()
1191
+ * .nullable()
1192
+ * .collate('C')
1193
+ * .default('default text')
1194
+ * .check(t.sql`length(value) > 10`),
1195
+ * );
1196
+ * });
1197
+ * ```
1198
+ *
1199
+ * @param name - name of the domain
1200
+ * @param fn - function returning a column type. Options `nullable`, `collate`, `default`, `check` will be applied to domain
1201
+ */
1202
+ createDomain(name: string, fn: DbDomainArg<CT>): Promise<void>;
1203
+ /**
1204
+ * Drop the domain, create it on rollback. See {@link dropDomain}.
1205
+ *
1206
+ * @param name - name of the domain
1207
+ * @param fn - function returning a column type. Options `nullable`, `collate`, `default`, `check` will be applied to domain
1208
+ */
1209
+ dropDomain(name: string, fn: DbDomainArg<CT>): Promise<void>;
1210
+ /**
1211
+ * To rename a domain:
1212
+ *
1213
+ * ```ts
1214
+ * import { change } from '../dbScript';
1215
+ *
1216
+ * change(async (db) => {
1217
+ * await db.renameDomain('oldName', 'newName');
1218
+ *
1219
+ * // to move domain to a different schema
1220
+ * await db.renameDomain('oldSchema.domain', 'newSchema.domain');
1221
+ * });
1222
+ * ```
1223
+ *
1224
+ * @param from - old domain name (can include schema)
1225
+ * @param to - new domain name (can include schema)
1226
+ */
1227
+ renameDomain(from: string, to: string): Promise<void>;
1228
+ /**
1229
+ * Create and drop a database collation, (see [Postgres docs](https://www.postgresql.org/docs/current/sql-createcollation.html)).
1230
+ *
1231
+ * ```ts
1232
+ * import { change } from '../dbScript';
1233
+ *
1234
+ * change(async (db) => {
1235
+ * await db.createCollation('myCollation', {
1236
+ * // This is a shortcut for setting lcCollate and lcCType at once.
1237
+ * locale: 'en-u-kn-true',
1238
+ *
1239
+ * // set `lcType` and `lcCType` only if the `locale` is not set.
1240
+ * // lcType: 'C',
1241
+ * // lcCType: 'C',
1242
+ *
1243
+ * // provider can be 'icu' or 'libc'. 'libc' is a default.
1244
+ * provider: 'icu',
1245
+ *
1246
+ * // true by default, false is only supported with 'icu' provider.
1247
+ * deterministic: true,
1248
+ *
1249
+ * // Is intended to by used by `pg_upgrade`. Normally, it should be omitted.
1250
+ * version: '1.2.3',
1251
+ *
1252
+ * // For `CREATE IF NOT EXISTS` when creating.
1253
+ * createIfNotExists: true,
1254
+ *
1255
+ * // For `DROP IF EXISTS` when dropping.
1256
+ * dropIfExists: true,
1257
+ *
1258
+ * // For `DROP ... CASCADE` when dropping.
1259
+ * cascase: true,
1260
+ * });
1261
+ * });
1262
+ * ```
1263
+ *
1264
+ * Instead of specifying the collation options, you can specify a collation to copy options from.
1265
+ *
1266
+ * ```ts
1267
+ * import { change } from '../dbScript';
1268
+ *
1269
+ * change(async (db) => {
1270
+ * await db.createCollation('myCollation', {
1271
+ * fromExisting: 'otherCollation',
1272
+ * });
1273
+ * });
1274
+ * ```
1275
+ *
1276
+ * To create a collation withing a specific database schema, prepend it to the collation name:
1277
+ *
1278
+ * ```ts
1279
+ * import { change } from '../dbScript';
1280
+ *
1281
+ * change(async (db) => {
1282
+ * await db.createCollation('schemaName.myCollation', {
1283
+ * // `fromExisting` also can accept a collation name with a schema.
1284
+ * fromExisting: 'schemaName.otherCollation',
1285
+ * });
1286
+ * });
1287
+ * ```
1288
+ *
1289
+ * @param name - name of the collation, can contain a name of schema separated with a dot.
1290
+ * @param options - options to create and drop the collation.
1291
+ */
1292
+ createCollation(name: string, options: Omit<RakeDbAst.Collation, 'type' | 'action' | 'schema' | 'name'>): Promise<void>;
1293
+ /**
1294
+ * Drop the collation, create it on rollback. See {@link createCollation}.
1295
+ *
1296
+ * @param name - name of the collation, can contain a name of schema separated with a dot.
1297
+ * @param options - options to create and drop the collation.
1298
+ */
1299
+ dropCollation(name: string, options: Omit<RakeDbAst.Collation, 'type' | 'action' | 'schema' | 'name'>): Promise<void>;
1300
+ /**
1301
+ * Create and drop database views.
1302
+ *
1303
+ * Provide SQL as a string or via `t.sql` that can accept variables.
1304
+ *
1305
+ * ```ts
1306
+ * import { change } from '../dbScript';
1307
+ *
1308
+ * change(async (db) => {
1309
+ * await db.createView(
1310
+ * 'simpleView',
1311
+ * `
1312
+ * SELECT a.one, b.two
1313
+ * FROM a
1314
+ * JOIN b ON b."aId" = a.id
1315
+ * `,
1316
+ * );
1317
+ *
1318
+ * // view can accept t.sql with variables in such way:
1319
+ * const value = 'some value';
1320
+ * await db.createView(
1321
+ * 'viewWithVariables',
1322
+ * t.sql`
1323
+ * SELECT * FROM a WHERE key = ${value}
1324
+ * `,
1325
+ * );
1326
+ *
1327
+ * // view with options
1328
+ * await db.createView(
1329
+ * 'schemaName.recursiveView',
1330
+ * {
1331
+ * // createOrReplace has effect when creating the view
1332
+ * createOrReplace: true,
1333
+ *
1334
+ * // dropIfExists and dropMode have effect when dropping the view
1335
+ * dropIfExists: true,
1336
+ * dropMode: 'CASCADE',
1337
+ *
1338
+ * // for details, check Postgres docs for CREATE VIEW,
1339
+ * // these options are matching CREATE VIEW options
1340
+ * temporary: true,
1341
+ * recursive: true,
1342
+ * columns: ['n'],
1343
+ * with: {
1344
+ * checkOption: 'LOCAL', // or 'CASCADED'
1345
+ * securityBarrier: true,
1346
+ * securityInvoker: true,
1347
+ * },
1348
+ * },
1349
+ * `
1350
+ * VALUES (1)
1351
+ * UNION ALL
1352
+ * SELECT n + 1 FROM "schemaName"."recursiveView" WHERE n < 100;
1353
+ * `,
1354
+ * );
1355
+ * });
1356
+ * ```
1357
+ *
1358
+ * @param name - name of the view
1359
+ * @param options - view options
1360
+ * @param sql - SQL to create the view with
1361
+ */
1362
+ createView(name: string, options: RakeDbAst.ViewOptions, sql: string | RawSqlBase): Promise<void>;
1363
+ /**
1364
+ * See {@link createView}
1365
+ *
1366
+ * @param name - name of the view
1367
+ * @param sql - SQL to create the view with
1368
+ */
1369
+ createView(name: string, sql: string | RawSqlBase): Promise<void>;
1370
+ /**
1371
+ * Drop the view, create it on rollback. See {@link createView}.
1372
+ *
1373
+ * @param name - name of the view
1374
+ * @param options - view options
1375
+ * @param sql - SQL to create the view with
1376
+ */
1377
+ dropView(name: string, options: RakeDbAst.ViewOptions, sql: string | RawSqlBase): Promise<void>;
1378
+ /**
1379
+ * Drop the view, create it on rollback. See {@link createView}.
1380
+ *
1381
+ * @param name - name of the view
1382
+ * @param sql - SQL to create the view with
1383
+ */
1384
+ dropView(name: string, sql: string | RawSqlBase): Promise<void>;
1385
+ /**
1386
+ * Returns boolean to know if table exists:
1387
+ *
1388
+ * ```ts
1389
+ * import { change } from '../dbScript';
1390
+ *
1391
+ * change(async (db) => {
1392
+ * if (await db.tableExists('tableName')) {
1393
+ * // ...do something
1394
+ * }
1395
+ * });
1396
+ * ```
1397
+ *
1398
+ * @param tableName - name of the table
1399
+ */
1400
+ tableExists(tableName: string): Promise<boolean>;
1401
+ /**
1402
+ * Returns boolean to know if a column exists:
1403
+ *
1404
+ * Note that when `snakeCase` option is set to true, this method won't translate column to snake case, unlike other parts.
1405
+ *
1406
+ * ```ts
1407
+ * import { change } from '../dbScript';
1408
+ *
1409
+ * change(async (db) => {
1410
+ * if (await db.columnExists('tableName', 'columnName')) {
1411
+ * // ...do something
1412
+ * }
1413
+ * });
1414
+ * ```
1415
+ *
1416
+ * @param tableName - name of the table to check for the column in
1417
+ * @param columnName - name of the column
1418
+ */
1419
+ columnExists(tableName: string, columnName: string): Promise<boolean>;
1420
+ /**
1421
+ * Returns boolean to know if constraint exists:
1422
+ *
1423
+ * ```ts
1424
+ * import { change } from '../dbScript';
1425
+ *
1426
+ * change(async (db) => {
1427
+ * if (await db.constraintExists('constraintName')) {
1428
+ * // ...do something
1429
+ * }
1430
+ * });
1431
+ * ```
1432
+ *
1433
+ * @param constraintName - name of the constraint
1434
+ */
1435
+ constraintExists(constraintName: string): Promise<boolean>;
1436
+ createRole(name: string, params?: Partial<DbStructure.Role>): Promise<void>;
1437
+ dropRole(name: string, params?: Partial<DbStructure.Role>): Promise<void>;
1438
+ renameRole(from: string, to: string): Promise<void>;
1439
+ changeRole(name: string, params: {
1440
+ from?: Partial<DbStructure.Role>;
1441
+ to: Partial<DbStructure.Role>;
1442
+ }): Promise<void>;
1443
+ changeDefaultPrivileges(params: ChangeDefaultPrivilegesArg): Promise<void>;
1489
1444
  }
1490
1445
  interface AddEnumValueOptions {
1491
- ifNotExists?: boolean;
1492
- before?: string;
1493
- after?: string;
1446
+ ifNotExists?: boolean;
1447
+ before?: string;
1448
+ after?: string;
1494
1449
  }
1495
-
1496
1450
  interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
1497
- table: Db<Table, Shape>;
1451
+ table: Db<Table, Shape>;
1498
1452
  }
1499
-
1500
1453
  interface RakeDbCtx {
1501
- migrationsPromise?: Promise<MigrationsSet>;
1454
+ migrationsPromise?: Promise<MigrationsSet>;
1502
1455
  }
1503
1456
  declare const getSchemaAndTableFromName: (schema: QuerySchema | undefined, name: string) => [string | undefined, string];
1504
- declare const concatSchemaAndName: ({ schema, name, }: {
1505
- schema?: string;
1506
- name: string;
1457
+ declare const concatSchemaAndName: ({
1458
+ schema,
1459
+ name
1460
+ }: {
1461
+ schema?: string;
1462
+ name: string;
1507
1463
  }, excludeCurrentSchema?: string) => string;
1508
-
1509
1464
  interface RakeDbChangeFnConfig {
1510
- columnTypes: unknown;
1465
+ columnTypes: unknown;
1511
1466
  }
1512
1467
  /**
1513
1468
  * Function to use in migrations to wrap database changes
@@ -1515,59 +1470,56 @@ interface RakeDbChangeFnConfig {
1515
1470
  * and also returns the callback in case you want to export it from migration.
1516
1471
  */
1517
1472
  interface MigrationChangeFn<ColumnTypes> {
1518
- (fn: ChangeCallback$1<ColumnTypes>): MigrationChange;
1473
+ (fn: ChangeCallback<ColumnTypes>): MigrationChange;
1519
1474
  }
1520
1475
  declare const createMigrationChangeFn: <ColumnTypes = DefaultColumnTypes<DefaultSchemaConfig>>(config: {
1521
- columnTypes?: ColumnTypes;
1476
+ columnTypes?: ColumnTypes;
1522
1477
  }) => MigrationChangeFn<ColumnTypes>;
1523
1478
  interface MigrationChange {
1524
- fn: ChangeCallback$1<unknown>;
1525
- config: RakeDbChangeFnConfig;
1479
+ fn: ChangeCallback<unknown>;
1480
+ config: RakeDbChangeFnConfig;
1526
1481
  }
1527
- type ChangeCallback$1<ColumnTypes> = (db: DbMigration<ColumnTypes>, up: boolean) => Promise<void>;
1528
-
1482
+ type ChangeCallback<ColumnTypes> = (db: DbMigration<ColumnTypes>, up: boolean) => Promise<void>;
1529
1483
  interface OrmParam {
1530
- $getAdapter(): AdapterBase;
1484
+ $getAdapter(): Adapter;
1531
1485
  }
1532
- type DbParam = OrmParam | AdapterBase;
1533
-
1486
+ type DbParam = OrmParam | Adapter;
1534
1487
  declare const saveMigratedVersion: (db: SilentQueries, version: string, name: string, config: Pick<RakeDbConfig, "migrationsTable">) => Promise<void>;
1535
1488
  declare const createMigrationsSchemaAndTable: (db: DbParam, config: {
1536
- migrationsTable: string;
1537
- logger?: QueryLogger;
1489
+ migrationsTable: string;
1490
+ logger?: QueryLogger;
1538
1491
  }) => Promise<void>;
1539
-
1540
1492
  interface MigrateFnParams {
1541
- ctx?: RakeDbCtx;
1542
- count?: number;
1543
- force?: boolean;
1493
+ ctx?: RakeDbCtx;
1494
+ count?: number;
1495
+ force?: boolean;
1544
1496
  }
1545
1497
  interface MigrateConfigBase extends QueryLogOptions {
1546
- migrationId?: RakeDbMigrationId;
1547
- renameMigrations?: RakeDbRenameMigrationsInput;
1548
- migrationsTable?: string;
1549
- transaction?: 'single' | 'per-migration';
1550
- transactionSearchPath?: SearchPath;
1551
- forceDefaultExports?: boolean;
1552
- beforeChange?: ChangeCallback;
1553
- afterChange?: ChangeCallback;
1554
- afterChangeCommit?: ChangeCommitCallback;
1555
- beforeMigrate?: MigrationCallback;
1556
- afterMigrate?: MigrationCallback;
1557
- beforeRollback?: MigrationCallback;
1558
- afterRollback?: MigrationCallback;
1559
- snakeCase?: boolean;
1560
- language?: string;
1561
- noPrimaryKey?: NoPrimaryKeyOption;
1562
- baseTable?: RakeDbBaseTable<unknown>;
1498
+ migrationId?: RakeDbMigrationId;
1499
+ renameMigrations?: RakeDbRenameMigrationsInput;
1500
+ migrationsTable?: string;
1501
+ transaction?: 'single' | 'per-migration';
1502
+ transactionSearchPath?: SearchPath;
1503
+ forceDefaultExports?: boolean;
1504
+ beforeChange?: ChangeCallback$1;
1505
+ afterChange?: ChangeCallback$1;
1506
+ afterChangeCommit?: ChangeCommitCallback;
1507
+ beforeMigrate?: MigrationCallback;
1508
+ afterMigrate?: MigrationCallback;
1509
+ beforeRollback?: MigrationCallback;
1510
+ afterRollback?: MigrationCallback;
1511
+ snakeCase?: boolean;
1512
+ language?: string;
1513
+ noPrimaryKey?: NoPrimaryKeyOption;
1514
+ baseTable?: RakeDbBaseTable<unknown>;
1563
1515
  }
1564
1516
  interface MigrateConfigFileBased extends MigrateConfigBase {
1565
- basePath?: string;
1566
- migrationsPath: string;
1567
- import(path: string): Promise<unknown>;
1517
+ basePath?: string;
1518
+ migrationsPath: string;
1519
+ import(path: string): Promise<unknown>;
1568
1520
  }
1569
1521
  interface MigrateConfigMigrationsProvided extends MigrateConfigBase {
1570
- migrations: ModuleExportsRecord;
1522
+ migrations: ModuleExportsRecord;
1571
1523
  }
1572
1524
  /**
1573
1525
  * Minimal configuration required by public migration functions
@@ -1581,7 +1533,7 @@ interface MigrateConfigMigrationsProvided extends MigrateConfigBase {
1581
1533
  */
1582
1534
  type MigrateConfig = MigrateConfigFileBased | MigrateConfigMigrationsProvided;
1583
1535
  interface MigrateFn {
1584
- (db: DbParam, config: MigrateConfig, params?: MigrateFnParams): Promise<void>;
1536
+ (db: DbParam, config: MigrateConfig, params?: MigrateFnParams): Promise<void>;
1585
1537
  }
1586
1538
  /**
1587
1539
  * Will run all pending yet migrations, sequentially in order,
@@ -1599,7 +1551,7 @@ interface MigrateFn {
1599
1551
  declare const migrate: MigrateFn;
1600
1552
  declare const migrateAndClose: MigrateFn;
1601
1553
  interface RunMigrationConfig extends QueryLogOptions {
1602
- transactionSearchPath?: SearchPath;
1554
+ transactionSearchPath?: SearchPath;
1603
1555
  }
1604
1556
  declare function runMigration(db: DbParam, migration: () => MaybePromise<unknown>): Promise<void>;
1605
1557
  declare function runMigration(db: DbParam, config: RunMigrationConfig, migration: () => MaybePromise<unknown>): Promise<void>;
@@ -1634,315 +1586,313 @@ declare const rollback: MigrateFn;
1634
1586
  * @param params - optional redo parameters (ctx, count, force)
1635
1587
  */
1636
1588
  declare const redo: MigrateFn;
1637
-
1638
1589
  interface MigrationItemHasLoad {
1639
- path?: string;
1640
- /**
1641
- * Function that loads the migration content,
1642
- * can store lazy import of a migration file.
1643
- * Promise can return `{ default: x }` where `x` is a return of `change` or an array of such returns.
1644
- */
1645
- load(): MaybePromise<unknown>;
1590
+ path?: string;
1591
+ /**
1592
+ * Function that loads the migration content,
1593
+ * can store lazy import of a migration file.
1594
+ * Promise can return `{ default: x }` where `x` is a return of `change` or an array of such returns.
1595
+ */
1596
+ load(): MaybePromise<unknown>;
1646
1597
  }
1647
1598
  interface MigrationItem extends MigrationItemHasLoad {
1648
- path: string;
1649
- version: string;
1599
+ path: string;
1600
+ version: string;
1650
1601
  }
1651
1602
  interface MigrationsSet {
1652
- renameTo?: RakeDbRenameMigrations;
1653
- migrations: MigrationItem[];
1603
+ renameTo?: RakeDbRenameMigrations;
1604
+ migrations: MigrationItem[];
1654
1605
  }
1655
-
1656
1606
  type SearchPath = (() => string) | string;
1657
1607
  interface RakeDbCliConfigInputBase<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends QueryLogOptions {
1658
- columnTypes?: CT | ((t: DefaultColumnTypes<DefaultSchemaConfig>) => CT);
1659
- baseTable?: RakeDbBaseTable<CT>;
1660
- schemaConfig?: SchemaConfig;
1661
- basePath?: string;
1662
- dbScript?: string;
1663
- migrationId?: 'serial' | RakeDbMigrationId;
1664
- recurrentPath?: string;
1665
- migrationsTable?: string;
1666
- snakeCase?: boolean;
1667
- language?: string;
1668
- commands?: {
1669
- [commandName: string]: RakeDbCommandFn | RakeDbCommand;
1670
- };
1671
- noPrimaryKey?: NoPrimaryKeyOption;
1672
- transactionSearchPath?: SearchPath;
1673
- /**
1674
- * Throw if a migration doesn't have a default export.
1675
- * This is needed when in your setup you're importing migration files first and execute them later,
1676
- * in that case you should export changes in migrations.
1677
- */
1678
- forceDefaultExports?: boolean;
1679
- /**
1680
- * Is called once per db before migrating or rolling back a set of migrations.
1681
- *
1682
- * @param arg.db - query builder
1683
- * @param arg.up - whether it's migrating up or down
1684
- * @param arg.redo - whether it's migrating down and then up for `redo` command
1685
- * @param arg.migrations - array of executed (up or down) migrations
1686
- */
1687
- beforeChange?: ChangeCallback;
1688
- /**
1689
- * Is called once per db after migrating or rolling back a set of migrations.
1690
- * Runs inside the same transaction as migrations,
1691
- * for running after commit use {@link afterChangeCommit}.
1692
- *
1693
- * @param arg.db - query builder
1694
- * @param arg.up - whether it's migrating up or down
1695
- * @param arg.redo - whether it's migrating down and then up for `redo` command
1696
- * @param arg.migrations - array of executed (up or down) migrations
1697
- */
1698
- afterChange?: ChangeCallback;
1699
- /**
1700
- * Is called once per db after migrating or rolling back a set of migrations.
1701
- * Runs **after** committing migrations transaction.
1702
- *
1703
- * @param arg.options - database connection options
1704
- * @param arg.up - whether it's migrating up or down
1705
- * @param arg.migrations - array of executed (up or down) migrations
1706
- */
1707
- afterChangeCommit?: ChangeCommitCallback;
1708
- /**
1709
- * Is called once per db before migrating (up) a set of migrations.
1710
- *
1711
- * @param arg.db - query builder
1712
- * @param arg.migrations - applied migrations
1713
- */
1714
- beforeMigrate?: MigrationCallback;
1715
- /**
1716
- * Is called once per db after migrating (up) a set of migrations.
1717
- *
1718
- * @param arg.db - query builder
1719
- * @param arg.migrations - applied migrations
1720
- */
1721
- afterMigrate?: MigrationCallback;
1722
- /**
1723
- * Is called once per db before rolling back a set of migrations.
1724
- *
1725
- * @param arg.db - query builder
1726
- * @param arg.migrations - rolled back migrations
1727
- */
1728
- beforeRollback?: MigrationCallback;
1729
- /**
1730
- * Is called once per db before rolling back a set of migrations.
1731
- *
1732
- * @param arg.db - query builder
1733
- * @param arg.migrations - rolled back migrations
1734
- */
1735
- afterRollback?: MigrationCallback;
1736
- /**
1737
- * It may look odd, but it's required for `tsx` and other bundlers to have such `import` config specified explicitly.
1738
- */
1739
- import?(path: string): Promise<unknown>;
1608
+ columnTypes?: CT | ((t: DefaultColumnTypes<DefaultSchemaConfig>) => CT);
1609
+ baseTable?: RakeDbBaseTable<CT>;
1610
+ schemaConfig?: SchemaConfig;
1611
+ basePath?: string;
1612
+ dbScript?: string;
1613
+ migrationId?: 'serial' | RakeDbMigrationId;
1614
+ recurrentPath?: string;
1615
+ migrationsTable?: string;
1616
+ snakeCase?: boolean;
1617
+ language?: string;
1618
+ commands?: {
1619
+ [commandName: string]: RakeDbCommandFn | RakeDbCommand;
1620
+ };
1621
+ noPrimaryKey?: NoPrimaryKeyOption;
1622
+ transactionSearchPath?: SearchPath;
1623
+ /**
1624
+ * Throw if a migration doesn't have a default export.
1625
+ * This is needed when in your setup you're importing migration files first and execute them later,
1626
+ * in that case you should export changes in migrations.
1627
+ */
1628
+ forceDefaultExports?: boolean;
1629
+ /**
1630
+ * Is called once per db before migrating or rolling back a set of migrations.
1631
+ *
1632
+ * @param arg.db - query builder
1633
+ * @param arg.up - whether it's migrating up or down
1634
+ * @param arg.redo - whether it's migrating down and then up for `redo` command
1635
+ * @param arg.migrations - array of executed (up or down) migrations
1636
+ */
1637
+ beforeChange?: ChangeCallback$1;
1638
+ /**
1639
+ * Is called once per db after migrating or rolling back a set of migrations.
1640
+ * Runs inside the same transaction as migrations,
1641
+ * for running after commit use {@link afterChangeCommit}.
1642
+ *
1643
+ * @param arg.db - query builder
1644
+ * @param arg.up - whether it's migrating up or down
1645
+ * @param arg.redo - whether it's migrating down and then up for `redo` command
1646
+ * @param arg.migrations - array of executed (up or down) migrations
1647
+ */
1648
+ afterChange?: ChangeCallback$1;
1649
+ /**
1650
+ * Is called once per db after migrating or rolling back a set of migrations.
1651
+ * Runs **after** committing migrations transaction.
1652
+ *
1653
+ * @param arg.options - database connection options
1654
+ * @param arg.up - whether it's migrating up or down
1655
+ * @param arg.migrations - array of executed (up or down) migrations
1656
+ */
1657
+ afterChangeCommit?: ChangeCommitCallback;
1658
+ /**
1659
+ * Is called once per db before migrating (up) a set of migrations.
1660
+ *
1661
+ * @param arg.db - query builder
1662
+ * @param arg.migrations - applied migrations
1663
+ */
1664
+ beforeMigrate?: MigrationCallback;
1665
+ /**
1666
+ * Is called once per db after migrating (up) a set of migrations.
1667
+ *
1668
+ * @param arg.db - query builder
1669
+ * @param arg.migrations - applied migrations
1670
+ */
1671
+ afterMigrate?: MigrationCallback;
1672
+ /**
1673
+ * Is called once per db before rolling back a set of migrations.
1674
+ *
1675
+ * @param arg.db - query builder
1676
+ * @param arg.migrations - rolled back migrations
1677
+ */
1678
+ beforeRollback?: MigrationCallback;
1679
+ /**
1680
+ * Is called once per db before rolling back a set of migrations.
1681
+ *
1682
+ * @param arg.db - query builder
1683
+ * @param arg.migrations - rolled back migrations
1684
+ */
1685
+ afterRollback?: MigrationCallback;
1686
+ /**
1687
+ * It may look odd, but it's required for `tsx` and other bundlers to have such `import` config specified explicitly.
1688
+ */
1689
+ import?(path: string): Promise<unknown>;
1740
1690
  }
1741
1691
  interface RakeDbCliConfigInputFileBased<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends RakeDbCliConfigInputBase<SchemaConfig, CT> {
1742
- migrationsPath?: string;
1743
- /**
1744
- * required for `tsx` and other bundlers to have such `import` config specified explicitly.
1745
- */
1746
- import(path: string): Promise<unknown>;
1692
+ migrationsPath?: string;
1693
+ /**
1694
+ * required for `tsx` and other bundlers to have such `import` config specified explicitly.
1695
+ */
1696
+ import(path: string): Promise<unknown>;
1747
1697
  }
1748
1698
  interface RakeDbCliConfigInputCodeBased<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends RakeDbCliConfigInputBase<SchemaConfig, CT> {
1749
- /**
1750
- * To specify array of migrations explicitly, without loading them from files.
1751
- */
1752
- migrations: ModuleExportsRecord;
1753
- renameMigrations?: RakeDbRenameMigrationsInput;
1699
+ /**
1700
+ * To specify array of migrations explicitly, without loading them from files.
1701
+ */
1702
+ migrations: ModuleExportsRecord;
1703
+ renameMigrations?: RakeDbRenameMigrationsInput;
1754
1704
  }
1755
1705
  type RakeDbCliConfigInput<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> = RakeDbCliConfigInputFileBased<SchemaConfig, CT> | RakeDbCliConfigInputCodeBased<SchemaConfig, CT>;
1756
1706
  interface RakeDbConfig<ColumnTypes = unknown> extends QueryLogOptions {
1757
- /**
1758
- * Set by makeRakeDbConfig to distinguish between the user-provided initial config from the processed one.
1759
- */
1760
- __rakeDbConfig: true;
1761
- migrationsTable: string;
1762
- recurrentPath?: string;
1763
- columnTypes: ColumnTypes;
1764
- beforeChange?: ChangeCallback;
1765
- afterChange?: ChangeCallback;
1766
- beforeMigrate?: MigrationCallback;
1767
- afterMigrate?: MigrationCallback;
1768
- beforeRollback?: MigrationCallback;
1769
- afterRollback?: MigrationCallback;
1770
- migrationId: RakeDbMigrationId;
1771
- transactionSearchPath?: SearchPath;
1772
- forceDefaultExports?: boolean;
1773
- afterChangeCommit?: ChangeCommitCallback;
1774
- basePath: string;
1775
- import(path: string): Promise<unknown>;
1776
- migrationsPath: string;
1777
- transaction: 'single' | 'per-migration';
1778
- snakeCase?: boolean;
1779
- schemaConfig: ColumnSchemaConfig;
1780
- migrations?: ModuleExportsRecord;
1781
- dbScript: string;
1782
- renameMigrations?: RakeDbRenameMigrationsInput;
1783
- language?: string;
1784
- noPrimaryKey?: NoPrimaryKeyOption;
1785
- baseTable?: RakeDbBaseTable<unknown>;
1786
- commands: RakeDbCommands;
1707
+ /**
1708
+ * Set by makeRakeDbConfig to distinguish between the user-provided initial config from the processed one.
1709
+ */
1710
+ __rakeDbConfig: true;
1711
+ migrationsTable: string;
1712
+ recurrentPath?: string;
1713
+ columnTypes: ColumnTypes;
1714
+ beforeChange?: ChangeCallback$1;
1715
+ afterChange?: ChangeCallback$1;
1716
+ beforeMigrate?: MigrationCallback;
1717
+ afterMigrate?: MigrationCallback;
1718
+ beforeRollback?: MigrationCallback;
1719
+ afterRollback?: MigrationCallback;
1720
+ migrationId: RakeDbMigrationId;
1721
+ transactionSearchPath?: SearchPath;
1722
+ forceDefaultExports?: boolean;
1723
+ afterChangeCommit?: ChangeCommitCallback;
1724
+ basePath: string;
1725
+ import(path: string): Promise<unknown>;
1726
+ migrationsPath: string;
1727
+ transaction: 'single' | 'per-migration';
1728
+ snakeCase?: boolean;
1729
+ schemaConfig: ColumnSchemaConfig;
1730
+ migrations?: ModuleExportsRecord;
1731
+ dbScript: string;
1732
+ renameMigrations?: RakeDbRenameMigrationsInput;
1733
+ language?: string;
1734
+ noPrimaryKey?: NoPrimaryKeyOption;
1735
+ baseTable?: RakeDbBaseTable<unknown>;
1736
+ commands: RakeDbCommands;
1787
1737
  }
1788
1738
  declare const rakeDbConfigDefaults: {
1789
- schemaConfig: DefaultSchemaConfig;
1790
- snakeCase: boolean;
1791
- commands: {};
1792
- log: boolean;
1793
- logger: Console;
1794
- import(): never;
1795
- migrationId: {
1796
- serial: number;
1797
- };
1798
- migrationsTable: string;
1799
- transaction: string;
1739
+ schemaConfig: any;
1740
+ snakeCase: boolean;
1741
+ commands: {};
1742
+ log: boolean;
1743
+ logger: Console;
1744
+ import(): never;
1745
+ migrationId: {
1746
+ serial: number;
1747
+ };
1748
+ migrationsTable: string;
1749
+ transaction: string;
1800
1750
  };
1801
1751
  interface RakeDbCommandFn {
1802
- (adapters: AdapterBase[], config: RakeDbConfig, args: string[]): MaybePromise<unknown>;
1752
+ (adapters: Adapter[], config: RakeDbConfig, args: string[]): MaybePromise<unknown>;
1803
1753
  }
1804
1754
  interface RakeDbCommand {
1805
- run: RakeDbCommandFn;
1806
- help?: string;
1807
- helpArguments?: RecordString;
1808
- helpAfter?: string;
1755
+ run: RakeDbCommandFn;
1756
+ help?: string;
1757
+ helpArguments?: RecordString;
1758
+ helpAfter?: string;
1809
1759
  }
1810
1760
  interface RakeDbCommands {
1811
- [K: string]: RakeDbCommand;
1761
+ [K: string]: RakeDbCommand;
1812
1762
  }
1813
- interface ChangeCallback {
1814
- (arg: {
1815
- db: DbResult<unknown>;
1816
- up: boolean;
1817
- redo: boolean;
1818
- migrations: MigrationItem[];
1819
- }): void | Promise<void>;
1763
+ interface ChangeCallback$1 {
1764
+ (arg: {
1765
+ db: DbResult<unknown>;
1766
+ up: boolean;
1767
+ redo: boolean;
1768
+ migrations: MigrationItem[];
1769
+ }): void | Promise<void>;
1820
1770
  }
1821
1771
  interface ChangeCommitCallback {
1822
- (arg: {
1823
- adapter: AdapterBase;
1824
- up: boolean;
1825
- migrations: MigrationItem[];
1826
- }): void | Promise<void>;
1772
+ (arg: {
1773
+ adapter: Adapter;
1774
+ up: boolean;
1775
+ migrations: MigrationItem[];
1776
+ }): void | Promise<void>;
1827
1777
  }
1828
1778
  interface MigrationCallback {
1829
- (arg: {
1830
- db: DbResult<unknown>;
1831
- migrations: MigrationItem[];
1832
- }): void | Promise<void>;
1779
+ (arg: {
1780
+ db: DbResult<unknown>;
1781
+ migrations: MigrationItem[];
1782
+ }): void | Promise<void>;
1833
1783
  }
1834
1784
  interface RakeDbBaseTable<CT> {
1835
- exportAs: string;
1836
- getFilePath(): string;
1837
- nowSQL?: string;
1838
- new (): {
1839
- types: CT;
1840
- snakeCase?: boolean;
1841
- language?: string;
1842
- };
1785
+ exportAs: string;
1786
+ getFilePath(): string;
1787
+ nowSQL?: string;
1788
+ new (): {
1789
+ types: CT;
1790
+ snakeCase?: boolean;
1791
+ language?: string;
1792
+ };
1843
1793
  }
1844
1794
  interface ModuleExportsRecord {
1845
- [fileName: string]: () => Promise<unknown>;
1795
+ [fileName: string]: () => Promise<unknown>;
1846
1796
  }
1847
1797
  type RakeDbMigrationId = 'timestamp' | {
1848
- serial: number;
1798
+ serial: number;
1849
1799
  };
1850
1800
  interface RakeDbRenameMigrationsMap {
1851
- [K: string]: number;
1801
+ [K: string]: number;
1852
1802
  }
1853
1803
  interface RakeDbRenameMigrations {
1854
- to: RakeDbMigrationId;
1855
- map(): MaybePromise<RakeDbRenameMigrationsMap>;
1804
+ to: RakeDbMigrationId;
1805
+ map(): MaybePromise<RakeDbRenameMigrationsMap>;
1856
1806
  }
1857
1807
  interface RakeDbRenameMigrationsInput {
1858
- to: RakeDbMigrationId;
1859
- map: RakeDbRenameMigrationsMap;
1808
+ to: RakeDbMigrationId;
1809
+ map: RakeDbRenameMigrationsMap;
1860
1810
  }
1861
-
1862
1811
  interface RakeDbCliResult<ColumnTypes, Options> {
1863
- change: MigrationChangeFn<ColumnTypes>;
1864
- run(options: Options, args?: string[]): Promise<void>;
1812
+ change: MigrationChangeFn<ColumnTypes>;
1813
+ run(options: Options, args?: string[]): Promise<void>;
1865
1814
  }
1866
1815
  interface RakeDbFn<Options> {
1867
- <SchemaConfig extends ColumnSchemaConfig, ColumnTypes = DefaultColumnTypes<DefaultSchemaConfig>>(config: RakeDbCliConfigInput<SchemaConfig, ColumnTypes> | RakeDbConfig<ColumnTypes>, args?: string[]): RakeDbCliResult<ColumnTypes, Options>;
1868
- run<SchemaConfig extends ColumnSchemaConfig, ColumnTypes = DefaultColumnTypes<DefaultSchemaConfig>>(options: Options, config: RakeDbCliConfigInput<SchemaConfig, ColumnTypes> | RakeDbConfig<ColumnTypes>, args?: string[]): MigrationChangeFn<ColumnTypes>;
1816
+ <SchemaConfig extends ColumnSchemaConfig, ColumnTypes = DefaultColumnTypes<DefaultSchemaConfig>>(config: RakeDbCliConfigInput<SchemaConfig, ColumnTypes> | RakeDbConfig<ColumnTypes>, args?: string[]): RakeDbCliResult<ColumnTypes, Options>;
1817
+ run<SchemaConfig extends ColumnSchemaConfig, ColumnTypes = DefaultColumnTypes<DefaultSchemaConfig>>(options: Options, config: RakeDbCliConfigInput<SchemaConfig, ColumnTypes> | RakeDbConfig<ColumnTypes>, args?: string[]): MigrationChangeFn<ColumnTypes>;
1869
1818
  }
1870
- declare const rakeDbCliWithAdapter: RakeDbFn<MaybeArray<AdapterBase>>;
1819
+ declare const rakeDbCliWithAdapter: RakeDbFn<MaybeArray<Adapter>>;
1871
1820
  declare const setRakeDbCliRunFn: <T>(rakeDbCli: RakeDbFn<T>) => void;
1872
-
1873
1821
  declare const rakeDbCommands: RakeDbCommands;
1874
1822
  declare const incrementIntermediateCaller: () => void;
1875
-
1876
- declare const encodeColumnDefault: (def: unknown, values: unknown[], column?: Column.Pick.Data) => string | null;
1823
+ declare const encodeColumnDefault: (def: unknown, values: unknown[], column?: Column$1.Pick.Data) => string | null;
1877
1824
  declare const getConstraintName: (table: string, constraint: {
1878
- references?: {
1879
- columns: string[];
1880
- };
1881
- check?: unknown;
1882
- identity?: unknown;
1825
+ references?: {
1826
+ columns: string[];
1827
+ };
1828
+ check?: unknown;
1829
+ identity?: unknown;
1883
1830
  }, snakeCase: boolean | undefined) => string;
1884
1831
  interface GetIndexOrExcludeName {
1885
- (table: string, columns: ({
1886
- column?: string;
1887
- } | {
1888
- expression: string;
1889
- })[]): string;
1832
+ (table: string, columns: ({
1833
+ column?: string;
1834
+ } | {
1835
+ expression: string;
1836
+ })[]): string;
1890
1837
  }
1891
1838
  declare const getIndexName: GetIndexOrExcludeName;
1892
1839
  declare const getExcludeName: GetIndexOrExcludeName;
1893
- declare const getMigrationsSchemaAndTable: (adapter: AdapterBase, config: {
1894
- migrationsTable: string;
1840
+ declare const getMigrationsSchemaAndTable: (adapter: Adapter, config: {
1841
+ migrationsTable: string;
1895
1842
  }) => {
1896
- schema?: string;
1897
- table: string;
1843
+ schema?: string;
1844
+ table: string;
1898
1845
  };
1899
-
1900
- declare const promptSelect: ({ message, options, active, inactive, }: {
1901
- message: string;
1902
- options: string[];
1903
- active?: (s: string) => string;
1904
- inactive?: (s: string) => string;
1846
+ declare const promptSelect: ({
1847
+ message,
1848
+ options,
1849
+ active,
1850
+ inactive
1851
+ }: {
1852
+ message: string;
1853
+ options: string[];
1854
+ active?: (s: string) => string;
1855
+ inactive?: (s: string) => string;
1905
1856
  }) => Promise<number>;
1906
-
1907
1857
  declare const astToMigration: (currentSchema: string, config: RakeDbConfig, asts: RakeDbAst[]) => string | undefined;
1908
-
1909
1858
  interface StructureToAstCtx {
1910
- snakeCase?: boolean;
1911
- unsupportedTypes: Record<string, string[]>;
1912
- currentSchema: string;
1913
- columnSchemaConfig: ColumnSchemaConfig;
1914
- columnsByType: ColumnsByType;
1859
+ snakeCase?: boolean;
1860
+ unsupportedTypes: Record<string, string[]>;
1861
+ currentSchema: string;
1862
+ columnSchemaConfig: ColumnSchemaConfig;
1863
+ columnsByType: ColumnsByType;
1915
1864
  }
1916
1865
  interface StructureToAstTableData {
1917
- primaryKey?: TableData.PrimaryKey;
1918
- indexes: DbStructure.Index[];
1919
- excludes: DbStructure.Exclude[];
1920
- constraints: DbStructure.Constraint[];
1921
- roles?: DbStructure.Role[];
1866
+ primaryKey?: TableData.PrimaryKey;
1867
+ indexes: DbStructure.Index[];
1868
+ excludes: DbStructure.Exclude[];
1869
+ constraints: DbStructure.Constraint[];
1870
+ roles?: DbStructure.Role[];
1922
1871
  }
1923
1872
  declare const makeStructureToAstCtx: (config: Pick<RakeDbConfig, "snakeCase" | "schemaConfig">, currentSchema: string) => StructureToAstCtx;
1924
- declare const structureToAst: (ctx: StructureToAstCtx, adapter: AdapterBase, config: Pick<RakeDbConfig, "migrationsTable">) => Promise<RakeDbAst[]>;
1873
+ declare const structureToAst: (ctx: StructureToAstCtx, adapter: Adapter, config: Pick<RakeDbConfig, "migrationsTable">) => Promise<RakeDbAst[]>;
1925
1874
  declare const makeDomainsMap: (ctx: StructureToAstCtx, data: IntrospectedStructure) => DbStructureDomainsMap;
1926
- declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => Column<pqb_internal.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any>;
1875
+ declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => Column$1;
1927
1876
  declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: "create" | "drop", domains: DbStructureDomainsMap) => RakeDbAst.Table;
1928
- declare const getDbStructureTableData: (data: IntrospectedStructure, { name, schemaName }: DbStructure.Table) => StructureToAstTableData;
1877
+ declare const getDbStructureTableData: (data: IntrospectedStructure, {
1878
+ name,
1879
+ schemaName
1880
+ }: DbStructure.Table) => StructureToAstTableData;
1929
1881
  interface ColumnChecks {
1930
- [K: string]: string[];
1882
+ [K: string]: string[];
1931
1883
  }
1932
1884
  declare const getDbTableColumnsChecks: (tableData: StructureToAstTableData) => ColumnChecks;
1933
- declare const dbColumnToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, tableName: string, item: DbStructure.Column, table?: DbStructure.Table, tableData?: StructureToAstTableData, checks?: ColumnChecks) => [key: string, column: Column];
1934
-
1885
+ declare const dbColumnToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, tableName: string, item: DbStructure.Column, table?: DbStructure.Table, tableData?: StructureToAstTableData, checks?: ColumnChecks) => [key: string, column: Column$1];
1935
1886
  declare const writeMigrationFile: (config: RakeDbConfig, version: string, name: string, migrationCode: string) => Promise<void>;
1936
1887
  declare const makeFileVersion: (ctx: RakeDbCtx, config: RakeDbConfig) => Promise<string>;
1937
-
1938
1888
  type CreateOrDropOk = 'done' | 'already';
1939
1889
  /**
1940
- * To create a database, reconfigure the connection with a power user and an existing database to connect to.
1890
+ * To create a database, clone the connection with a power user and an existing database to connect to.
1941
1891
  *
1942
1892
  * ```ts
1943
1893
  * import { createDatabase } from 'orchid-orm/migrations';
1944
1894
  *
1945
- * const adapter = db.$adapter.reconfigure({
1895
+ * const adapter = db.$adapter.clone({
1946
1896
  * user: 'postgres',
1947
1897
  * database: 'postgres',
1948
1898
  * });
@@ -1953,19 +1903,22 @@ type CreateOrDropOk = 'done' | 'already';
1953
1903
  * });
1954
1904
  * ```
1955
1905
  */
1956
- declare const createDatabase: (db: DbParam, { database, owner, }: {
1957
- database: string;
1958
- owner?: string;
1906
+ declare const createDatabase: (db: DbParam, {
1907
+ database,
1908
+ owner
1909
+ }: {
1910
+ database: string;
1911
+ owner?: string;
1959
1912
  }) => Promise<CreateOrDropOk>;
1960
1913
  /**
1961
- * To drop a database, reconfigure the connection with a power user and a different database to connect to.
1914
+ * To drop a database, clone the connection with a power user and a different database to connect to.
1962
1915
  *
1963
1916
  * Ensure the connections to the database are closed before dropping, because Postgres won't be able to drop it otherwise.
1964
1917
  *
1965
1918
  * ```ts
1966
1919
  * import { createDatabase } from 'orchid-orm/migrations';
1967
1920
  *
1968
- * const adapter = db.$adapter.reconfigure({
1921
+ * const adapter = db.$adapter.clone({
1969
1922
  * user: 'postgres',
1970
1923
  * database: 'postgres',
1971
1924
  * });
@@ -1976,8 +1929,10 @@ declare const createDatabase: (db: DbParam, { database, owner, }: {
1976
1929
  * });
1977
1930
  * ```
1978
1931
  */
1979
- declare const dropDatabase: (db: DbParam, { database }: {
1980
- database: string;
1932
+ declare const dropDatabase: (db: DbParam, {
1933
+ database
1934
+ }: {
1935
+ database: string;
1981
1936
  }) => Promise<CreateOrDropOk>;
1982
1937
  /**
1983
1938
  * `createSchema` uses a savepoint when it is called in a transaction to not break it if the schema already exists.
@@ -2027,9 +1982,5 @@ declare const createTable: (db: DbParam, sql: string) => Promise<"done" | "alrea
2027
1982
  * ```
2028
1983
  */
2029
1984
  declare const dropTable: (db: DbParam, sql: string) => Promise<"done" | "already">;
2030
-
2031
- declare class RakeDbError extends Error {
2032
- }
2033
-
2034
- export { DbStructure, RakeDbAst, RakeDbError, astToMigration, concatSchemaAndName, createDatabase, createMigrationChangeFn, createMigrationInterface, createMigrationsSchemaAndTable, createSchema, createTable, dbColumnToAst, dropDatabase, dropSchema, dropTable, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getDbVersion, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, incrementIntermediateCaller, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeStructureToAstCtx, migrate, migrateAndClose, promptSelect, rakeDbCliWithAdapter, rakeDbCommands, rakeDbConfigDefaults, redo, rollback, runMigration, saveMigratedVersion, setRakeDbCliRunFn, structureToAst, tableToAst, writeMigrationFile };
2035
- export type { ChangeCallback$1 as ChangeCallback, DbMigration, IntrospectedStructure, MigrateConfig, MigrateFn, MigrationChangeFn, RakeDbChangeFnConfig, RakeDbCliConfigInput, RakeDbCliResult, RakeDbConfig, RakeDbFn, SilentQueries, StructureToAstCtx, StructureToAstTableData };
1985
+ declare class RakeDbError extends Error {}
1986
+ export { type ChangeCallback, type DbMigration, type DbStructure, type IntrospectedStructure, type MigrateConfig, type MigrateFn, type MigrationChangeFn, type RakeDbAst, type RakeDbChangeFnConfig, type RakeDbCliConfigInput, type RakeDbCliResult, type RakeDbConfig, RakeDbError, type RakeDbFn, type SilentQueries, type StructureToAstCtx, type StructureToAstTableData, astToMigration, concatSchemaAndName, createDatabase, createMigrationChangeFn, createMigrationInterface, createMigrationsSchemaAndTable, createSchema, createTable, dbColumnToAst, dropDatabase, dropSchema, dropTable, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getDbVersion, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, incrementIntermediateCaller, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeStructureToAstCtx, migrate, migrateAndClose, promptSelect, rakeDbCliWithAdapter, rakeDbCommands, rakeDbConfigDefaults, redo, rollback, runMigration, saveMigratedVersion, setRakeDbCliRunFn, structureToAst, tableToAst, writeMigrationFile };