rake-db 2.32.2 → 2.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1681 -1730
- package/dist/index.js +4422 -5878
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4397 -5874
- package/dist/index.mjs.map +1 -1
- package/dist/node-postgres.d.ts +4 -6
- package/dist/node-postgres.js +23 -24
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +21 -21
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.d.ts +4 -6
- package/dist/postgres-js.js +23 -24
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +21 -21
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +27 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,567 +1,522 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
197
|
+
roles?: {
|
|
198
|
+
whereSql?: string;
|
|
199
|
+
};
|
|
200
|
+
loadDefaultPrivileges?: boolean;
|
|
203
201
|
}
|
|
204
|
-
declare function getDbVersion(db:
|
|
205
|
-
declare function introspectDbSchema(db:
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
|
414
|
-
|
|
415
|
-
|
|
235
|
+
interface Change {
|
|
236
|
+
type: 'change';
|
|
237
|
+
name?: string;
|
|
238
|
+
from: ColumnChange;
|
|
239
|
+
to: ColumnChange;
|
|
240
|
+
using?: ChangeUsing;
|
|
416
241
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
functions?: DefaultPrivilegeSetting;
|
|
421
|
-
types?: DefaultPrivilegeSetting;
|
|
422
|
-
schemas?: DefaultPrivilegeSetting;
|
|
423
|
-
largeObjects?: DefaultPrivilegeSetting;
|
|
242
|
+
interface ChangeUsing {
|
|
243
|
+
usingUp?: RawSqlBase;
|
|
244
|
+
usingDown?: RawSqlBase;
|
|
424
245
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
grantee: string;
|
|
429
|
-
schema?: string;
|
|
430
|
-
grant?: DefaultPrivilegeObjectConfig;
|
|
431
|
-
revoke?: DefaultPrivilegeObjectConfig;
|
|
246
|
+
interface Rename {
|
|
247
|
+
type: 'rename';
|
|
248
|
+
name: string;
|
|
432
249
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
-
|
|
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
|
-
|
|
446
|
+
type: SpecialChange;
|
|
448
447
|
}
|
|
449
448
|
interface OneWayChange {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
513
|
-
|
|
468
|
+
privileges?: readonly T[];
|
|
469
|
+
grantablePrivileges?: readonly T[];
|
|
514
470
|
}
|
|
515
|
-
interface DefaultPrivilegeObjectConfig {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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
|
-
|
|
499
|
+
enum: (name: string) => EnumColumn<ColumnSchemaConfig, unknown, readonly string[]>;
|
|
545
500
|
};
|
|
546
501
|
type ColumnsShapeCallback<CT, Shape extends ColumnsShape = ColumnsShape> = (t: MigrationColumnTypes<CT> & {
|
|
547
|
-
|
|
502
|
+
raw: typeof raw;
|
|
548
503
|
}) => Shape;
|
|
549
504
|
type ChangeTableOptions = {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
|
556
|
-
|
|
557
|
-
|
|
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
|
-
|
|
515
|
+
adapter: SilentQueries;
|
|
561
516
|
};
|
|
562
517
|
interface MigrationInterfaceResult {
|
|
563
|
-
|
|
564
|
-
|
|
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:
|
|
578
|
-
type MigrationAdapter =
|
|
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
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
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
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1446
|
+
ifNotExists?: boolean;
|
|
1447
|
+
before?: string;
|
|
1448
|
+
after?: string;
|
|
1494
1449
|
}
|
|
1495
|
-
|
|
1496
1450
|
interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
|
|
1497
|
-
|
|
1451
|
+
table: Db<Table, Shape>;
|
|
1498
1452
|
}
|
|
1499
|
-
|
|
1500
1453
|
interface RakeDbCtx {
|
|
1501
|
-
|
|
1454
|
+
migrationsPromise?: Promise<MigrationsSet>;
|
|
1502
1455
|
}
|
|
1503
1456
|
declare const getSchemaAndTableFromName: (schema: QuerySchema | undefined, name: string) => [string | undefined, string];
|
|
1504
|
-
declare const concatSchemaAndName: ({
|
|
1505
|
-
|
|
1506
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1473
|
+
(fn: ChangeCallback<ColumnTypes>): MigrationChange;
|
|
1519
1474
|
}
|
|
1520
1475
|
declare const createMigrationChangeFn: <ColumnTypes = DefaultColumnTypes<DefaultSchemaConfig>>(config: {
|
|
1521
|
-
|
|
1476
|
+
columnTypes?: ColumnTypes;
|
|
1522
1477
|
}) => MigrationChangeFn<ColumnTypes>;
|
|
1523
1478
|
interface MigrationChange {
|
|
1524
|
-
|
|
1525
|
-
|
|
1479
|
+
fn: ChangeCallback<unknown>;
|
|
1480
|
+
config: RakeDbChangeFnConfig;
|
|
1526
1481
|
}
|
|
1527
|
-
type ChangeCallback
|
|
1528
|
-
|
|
1482
|
+
type ChangeCallback<ColumnTypes> = (db: DbMigration<ColumnTypes>, up: boolean) => Promise<void>;
|
|
1529
1483
|
interface OrmParam {
|
|
1530
|
-
|
|
1484
|
+
$getAdapter(): Adapter;
|
|
1531
1485
|
}
|
|
1532
|
-
type DbParam = OrmParam |
|
|
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
|
-
|
|
1537
|
-
|
|
1489
|
+
migrationsTable: string;
|
|
1490
|
+
logger?: QueryLogger;
|
|
1538
1491
|
}) => Promise<void>;
|
|
1539
|
-
|
|
1540
1492
|
interface MigrateFnParams {
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1493
|
+
ctx?: RakeDbCtx;
|
|
1494
|
+
count?: number;
|
|
1495
|
+
force?: boolean;
|
|
1544
1496
|
}
|
|
1545
1497
|
interface MigrateConfigBase extends QueryLogOptions {
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
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
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1517
|
+
basePath?: string;
|
|
1518
|
+
migrationsPath: string;
|
|
1519
|
+
import(path: string): Promise<unknown>;
|
|
1568
1520
|
}
|
|
1569
1521
|
interface MigrateConfigMigrationsProvided extends MigrateConfigBase {
|
|
1570
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
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
|
-
|
|
1649
|
-
|
|
1599
|
+
path: string;
|
|
1600
|
+
version: string;
|
|
1650
1601
|
}
|
|
1651
1602
|
interface MigrationsSet {
|
|
1652
|
-
|
|
1653
|
-
|
|
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
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
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
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
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
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
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
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
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
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
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
|
-
|
|
1752
|
+
(adapters: Adapter[], config: RakeDbConfig, args: string[]): MaybePromise<unknown>;
|
|
1803
1753
|
}
|
|
1804
1754
|
interface RakeDbCommand {
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1755
|
+
run: RakeDbCommandFn;
|
|
1756
|
+
help?: string;
|
|
1757
|
+
helpArguments?: RecordString;
|
|
1758
|
+
helpAfter?: string;
|
|
1809
1759
|
}
|
|
1810
1760
|
interface RakeDbCommands {
|
|
1811
|
-
|
|
1761
|
+
[K: string]: RakeDbCommand;
|
|
1812
1762
|
}
|
|
1813
|
-
interface ChangeCallback {
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
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
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1772
|
+
(arg: {
|
|
1773
|
+
adapter: Adapter;
|
|
1774
|
+
up: boolean;
|
|
1775
|
+
migrations: MigrationItem[];
|
|
1776
|
+
}): void | Promise<void>;
|
|
1827
1777
|
}
|
|
1828
1778
|
interface MigrationCallback {
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1779
|
+
(arg: {
|
|
1780
|
+
db: DbResult<unknown>;
|
|
1781
|
+
migrations: MigrationItem[];
|
|
1782
|
+
}): void | Promise<void>;
|
|
1833
1783
|
}
|
|
1834
1784
|
interface RakeDbBaseTable<CT> {
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
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
|
-
|
|
1795
|
+
[fileName: string]: () => Promise<unknown>;
|
|
1846
1796
|
}
|
|
1847
1797
|
type RakeDbMigrationId = 'timestamp' | {
|
|
1848
|
-
|
|
1798
|
+
serial: number;
|
|
1849
1799
|
};
|
|
1850
1800
|
interface RakeDbRenameMigrationsMap {
|
|
1851
|
-
|
|
1801
|
+
[K: string]: number;
|
|
1852
1802
|
}
|
|
1853
1803
|
interface RakeDbRenameMigrations {
|
|
1854
|
-
|
|
1855
|
-
|
|
1804
|
+
to: RakeDbMigrationId;
|
|
1805
|
+
map(): MaybePromise<RakeDbRenameMigrationsMap>;
|
|
1856
1806
|
}
|
|
1857
1807
|
interface RakeDbRenameMigrationsInput {
|
|
1858
|
-
|
|
1859
|
-
|
|
1808
|
+
to: RakeDbMigrationId;
|
|
1809
|
+
map: RakeDbRenameMigrationsMap;
|
|
1860
1810
|
}
|
|
1861
|
-
|
|
1862
1811
|
interface RakeDbCliResult<ColumnTypes, Options> {
|
|
1863
|
-
|
|
1864
|
-
|
|
1812
|
+
change: MigrationChangeFn<ColumnTypes>;
|
|
1813
|
+
run(options: Options, args?: string[]): Promise<void>;
|
|
1865
1814
|
}
|
|
1866
1815
|
interface RakeDbFn<Options> {
|
|
1867
|
-
|
|
1868
|
-
|
|
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<
|
|
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
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1825
|
+
references?: {
|
|
1826
|
+
columns: string[];
|
|
1827
|
+
};
|
|
1828
|
+
check?: unknown;
|
|
1829
|
+
identity?: unknown;
|
|
1883
1830
|
}, snakeCase: boolean | undefined) => string;
|
|
1884
1831
|
interface GetIndexOrExcludeName {
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
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:
|
|
1894
|
-
|
|
1840
|
+
declare const getMigrationsSchemaAndTable: (adapter: Adapter, config: {
|
|
1841
|
+
migrationsTable: string;
|
|
1895
1842
|
}) => {
|
|
1896
|
-
|
|
1897
|
-
|
|
1843
|
+
schema?: string;
|
|
1844
|
+
table: string;
|
|
1898
1845
|
};
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
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
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1859
|
+
snakeCase?: boolean;
|
|
1860
|
+
unsupportedTypes: Record<string, string[]>;
|
|
1861
|
+
currentSchema: string;
|
|
1862
|
+
columnSchemaConfig: ColumnSchemaConfig;
|
|
1863
|
+
columnsByType: ColumnsByType;
|
|
1915
1864
|
}
|
|
1916
1865
|
interface StructureToAstTableData {
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
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:
|
|
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
|
|
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, {
|
|
1877
|
+
declare const getDbStructureTableData: (data: IntrospectedStructure, {
|
|
1878
|
+
name,
|
|
1879
|
+
schemaName
|
|
1880
|
+
}: DbStructure.Table) => StructureToAstTableData;
|
|
1929
1881
|
interface ColumnChecks {
|
|
1930
|
-
|
|
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,
|
|
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.
|
|
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, {
|
|
1957
|
-
|
|
1958
|
-
|
|
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,
|
|
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.
|
|
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, {
|
|
1980
|
-
|
|
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
|
-
|
|
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 };
|