-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathtypes.ts
399 lines (340 loc) · 13.7 KB
/
types.ts
1
2
3
4
5
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import type {
ClientBase,
ClientConfig,
QueryArrayConfig,
QueryArrayResult,
QueryConfig,
QueryResult,
} from 'pg';
import type * as domains from './operations/domainsTypes';
import type * as extensions from './operations/extensionsTypes';
import type * as functions from './operations/functionsTypes';
import type { Name } from './operations/generalTypes';
import type * as indexes from './operations/indexesTypes';
import type * as operators from './operations/operatorsTypes';
import type * as other from './operations/othersTypes';
import type PgLiteral from './operations/PgLiteral';
import type * as policies from './operations/policiesTypes';
import type * as roles from './operations/rolesTypes';
import type * as schemas from './operations/schemasTypes';
import type * as sequences from './operations/sequencesTypes';
import type * as tables from './operations/tablesTypes';
import type * as triggers from './operations/triggersTypes';
import type * as types from './operations/typesTypes';
import type * as mViews from './operations/viewsMaterializedTypes';
import type * as views from './operations/viewsTypes';
export type { ClientConfig, ConnectionConfig } from 'pg';
// see ClientBase in @types/pg
export interface DB {
/* eslint-disable @typescript-eslint/no-explicit-any */
query(
queryConfig: QueryArrayConfig,
values?: any[]
): Promise<QueryArrayResult>;
query(queryConfig: QueryConfig): Promise<QueryResult>;
query(
queryTextOrConfig: string | QueryConfig,
values?: any[]
): Promise<QueryResult>;
select(queryConfig: QueryArrayConfig, values?: any[]): Promise<any[]>;
select(queryConfig: QueryConfig): Promise<any[]>;
select(
queryTextOrConfig: string | QueryConfig,
values?: any[]
): Promise<any[]>;
/* eslint-enable @typescript-eslint/no-explicit-any */
}
export interface MigrationBuilder {
createExtension: (...args: Parameters<extensions.CreateExtension>) => void;
dropExtension: (...args: Parameters<extensions.DropExtension>) => void;
addExtension: (...args: Parameters<extensions.CreateExtension>) => void;
createTable: (...args: Parameters<tables.CreateTable>) => void;
dropTable: (...args: Parameters<tables.DropTable>) => void;
renameTable: (...args: Parameters<tables.RenameTable>) => void;
alterTable: (...args: Parameters<tables.AlterTable>) => void;
addColumns: (...args: Parameters<tables.AddColumns>) => void;
dropColumns: (...args: Parameters<tables.DropColumns>) => void;
renameColumn: (...args: Parameters<tables.RenameColumn>) => void;
alterColumn: (...args: Parameters<tables.AlterColumn>) => void;
addColumn: (...args: Parameters<tables.AddColumns>) => void;
dropColumn: (...args: Parameters<tables.DropColumns>) => void;
addConstraint: (...args: Parameters<tables.CreateConstraint>) => void;
dropConstraint: (...args: Parameters<tables.DropConstraint>) => void;
renameConstraint: (...args: Parameters<tables.RenameConstraint>) => void;
createConstraint: (...args: Parameters<tables.CreateConstraint>) => void;
createType: (...args: Parameters<types.CreateType>) => void;
dropType: (...args: Parameters<types.DropType>) => void;
addType: (...args: Parameters<types.CreateType>) => void;
renameType: (...args: Parameters<types.RenameType>) => void;
renameTypeAttribute: (...args: Parameters<types.RenameTypeAttribute>) => void;
renameTypeValue: (...args: Parameters<types.RenameTypeValue>) => void;
addTypeAttribute: (...args: Parameters<types.AddTypeAttribute>) => void;
dropTypeAttribute: (...args: Parameters<types.DropTypeAttribute>) => void;
setTypeAttribute: (...args: Parameters<types.SetTypeAttribute>) => void;
addTypeValue: (...args: Parameters<types.AddTypeValue>) => void;
createIndex: (...args: Parameters<indexes.CreateIndex>) => void;
dropIndex: (...args: Parameters<indexes.DropIndex>) => void;
addIndex: (...args: Parameters<indexes.CreateIndex>) => void;
createRole: (...args: Parameters<roles.CreateRole>) => void;
dropRole: (...args: Parameters<roles.DropRole>) => void;
alterRole: (...args: Parameters<roles.AlterRole>) => void;
renameRole: (...args: Parameters<roles.RenameRole>) => void;
createFunction: (...args: Parameters<functions.CreateFunction>) => void;
dropFunction: (...args: Parameters<functions.DropFunction>) => void;
renameFunction: (...args: Parameters<functions.RenameFunction>) => void;
createTrigger: (...args: Parameters<triggers.CreateTrigger>) => void;
dropTrigger: (...args: Parameters<triggers.DropTrigger>) => void;
renameTrigger: (...args: Parameters<triggers.RenameTrigger>) => void;
createSchema: (...args: Parameters<schemas.CreateSchema>) => void;
dropSchema: (...args: Parameters<schemas.DropSchema>) => void;
renameSchema: (...args: Parameters<schemas.RenameSchema>) => void;
createDomain: (...args: Parameters<domains.CreateDomain>) => void;
dropDomain: (...args: Parameters<domains.DropDomain>) => void;
alterDomain: (...args: Parameters<domains.AlterDomain>) => void;
renameDomain: (...args: Parameters<domains.RenameDomain>) => void;
createSequence: (...args: Parameters<sequences.CreateSequence>) => void;
dropSequence: (...args: Parameters<sequences.DropSequence>) => void;
alterSequence: (...args: Parameters<sequences.AlterSequence>) => void;
renameSequence: (...args: Parameters<sequences.RenameSequence>) => void;
createOperator: (...args: Parameters<operators.CreateOperator>) => void;
dropOperator: (...args: Parameters<operators.DropOperator>) => void;
createOperatorClass: (
...args: Parameters<operators.CreateOperatorClass>
) => void;
dropOperatorClass: (...args: Parameters<operators.DropOperatorClass>) => void;
renameOperatorClass: (
...args: Parameters<operators.RenameOperatorClass>
) => void;
createOperatorFamily: (
...args: Parameters<operators.CreateOperatorFamily>
) => void;
dropOperatorFamily: (
...args: Parameters<operators.DropOperatorFamily>
) => void;
renameOperatorFamily: (
...args: Parameters<operators.RenameOperatorFamily>
) => void;
addToOperatorFamily: (
...args: Parameters<operators.AddToOperatorFamily>
) => void;
removeFromOperatorFamily: (
...args: Parameters<operators.RemoveFromOperatorFamily>
) => void;
createPolicy: (...args: Parameters<policies.CreatePolicy>) => void;
dropPolicy: (...args: Parameters<policies.DropPolicy>) => void;
alterPolicy: (...args: Parameters<policies.AlterPolicy>) => void;
renamePolicy: (...args: Parameters<policies.RenamePolicy>) => void;
createView: (...args: Parameters<views.CreateView>) => void;
dropView: (...args: Parameters<views.DropView>) => void;
alterView: (...args: Parameters<views.AlterView>) => void;
alterViewColumn: (...args: Parameters<views.AlterViewColumn>) => void;
renameView: (...args: Parameters<views.RenameView>) => void;
createMaterializedView: (
...args: Parameters<mViews.CreateMaterializedView>
) => void;
dropMaterializedView: (
...args: Parameters<mViews.DropMaterializedView>
) => void;
alterMaterializedView: (
...args: Parameters<mViews.AlterMaterializedView>
) => void;
renameMaterializedView: (
...args: Parameters<mViews.RenameMaterializedView>
) => void;
renameMaterializedViewColumn: (
...args: Parameters<mViews.RenameMaterializedViewColumn>
) => void;
refreshMaterializedView: (
...args: Parameters<mViews.RefreshMaterializedView>
) => void;
sql: (...args: Parameters<other.Sql>) => void;
func: (sql: string) => PgLiteral;
noTransaction: () => void;
db: DB;
}
export type MigrationAction = (
pgm: MigrationBuilder,
run?: () => void
) => Promise<void> | void;
export type Literal = (v: Name) => string;
export type LogFn = (msg: string) => void;
export type Logger = {
debug?: LogFn;
info: LogFn;
warn: LogFn;
error: LogFn;
};
export interface MigrationBuilderActions {
up?: MigrationAction | false;
down?: MigrationAction | false;
shorthands?: tables.ColumnDefinitions;
}
export interface MigrationOptions {
typeShorthands?: tables.ColumnDefinitions;
schemalize: Literal;
literal: Literal;
logger: Logger;
}
// Note these currently don't contain the parameterized types like
// bit(n), varchar(n) and so on, they have to be specified as strings
export enum PgType {
BIGINT = 'bigint', // signed eight-byte integer
INT8 = 'int8', // alias for bigint
BIGSERIAL = 'bigserial', // autoincrementing eight-byte integer
BIT_1 = 'bit', // fixed-length bit string
BIT_VARYING = 'bit varying', // variable-length bit string
VARBIT = 'varbit', // alias for bit varying
SERIAL8 = 'serial8', // alias for bigserial
BOOLEAN = 'boolean', // logical Boolean (true/false)
BOOL = 'bool', // alias for boolean
BOX = 'box', // rectangular box on a plane
BYTEA = 'bytea', // binary data ("byte array")
CHARACTER = 'character', // fixed-length character string
CHAR = 'char', // alias for character
CHARACTER_VARYING = 'character varying', // variable-length character string
VARCHAR = 'varchar', // alias for character varying
CIDR = 'cidr', // IPv4 or IPv6 network address
CIRCLE = 'circle', // circle on a plane
DATE = 'date', // calendar date (year, month, day)
DOUBLE_PRECISION = 'double precision', // float8 double precision floating-point number (8 bytes)
INET = 'inet', // IPv4 or IPv6 host address
INTEGER = 'integer', // signed four-byte integer
INT = 'int', // alias for int
INT4 = 'int4', // alias for int
INTERVAL = 'interval', // time span
JSON = 'json', // textual JSON data
JSONB = 'jsonb', // binary JSON data, decomposed
LINE = 'line', // infinite line on a plane
LSEG = 'lseg', // line segment on a plane
MACADDR = 'macaddr', // MAC (Media Access Control) address
MONEY = 'money', // currency amount
NUMERIC = 'numeric', // exact numeric of selectable precision
PATH = 'path', // geometric path on a plane
PG_LSN = 'pg_lsn', // PostgreSQL Log Sequence Number
POINT = 'point', // geometric point on a plane
POLYGON = 'polygon', // closed geometric path on a plane
REAL = 'real', // single precision floating-point number (4 bytes)
FLOAT4 = 'float4', // alias for REAL
SMALLINT = 'smallint', // signed two-byte integer
INT2 = 'int2', // alias for smallint
SMALLSERIAL = 'smallserial', // autoincrementing two-byte integer
SERIAL2 = 'serial2', // alias for smallserial
SERIAL = 'serial', // autoincrementing four-byte integer
SERIAL4 = 'serial4', // alias for serial
TEXT = 'text', // variable-length character string
TIME = 'time', // time of day (no time zone)
TIME_WITHOUT_TIME_ZONE = 'without time zone', // alias of time
TIME_WITH_TIME_ZONE = 'time with time zone', // time of day, including time zone
TIMETZ = 'timetz', // alias of time with time zone
TIMESTAMP = 'timestamp', // date and time (no time zone)
TIMESTAMP_WITHOUT_TIME_ZONE = 'timestamp without time zone', // alias of timestamp
TIMESTAMP_WITH_TIME_ZONE = 'timestamp with time zone', // date and time, including time zone
TIMESTAMPTZ = 'timestamptz', // alias of timestamp with time zone
TSQUERY = 'tsquery', // text search query
TSVECTOR = 'tsvector', // text search document
TXID_SNAPSHOT = 'txid_snapshot', // user-level transaction ID snapshot
UUID = 'uuid', // universally unique identifier
XML = 'xml', // XML data
}
export type MigrationDirection = 'up' | 'down';
export interface RunnerOptionConfig {
/**
* The table storing which migrations have been run.
*/
migrationsTable: string;
/**
* The schema storing table which migrations have been run.
*
* (defaults to same value as `schema`)
*/
migrationsSchema?: string;
/**
* The schema on which migration will be run.
*
* @default 'public'
*/
schema?: string | string[];
/**
* The directory containing your migration files.
*/
dir: string;
/**
* Check order of migrations before running them.
*/
checkOrder?: boolean;
/**
* Direction of migration-run.
*/
direction: MigrationDirection;
/**
* Number of migration to run.
*/
count?: number;
/**
* Treats `count` as timestamp.
*/
timestamp?: boolean;
/**
* Regex pattern for file names to ignore (ignores files starting with `.` by default).
*/
ignorePattern?: string;
/**
* Run only migration with this name.
*/
file?: string;
dryRun?: boolean;
/**
* Creates the configured schema if it doesn't exist.
*/
createSchema?: boolean;
/**
* Creates the configured migration schema if it doesn't exist.
*/
createMigrationsSchema?: boolean;
/**
* Combines all pending migrations into a single transaction so that if any migration fails, all will be rolled back.
*
* @default true
*/
singleTransaction?: boolean;
/**
* Disables locking mechanism and checks.
*/
noLock?: boolean;
/**
* Mark migrations as run without actually performing them (use with caution!).
*/
fake?: boolean;
/**
* Runs [`decamelize`](https://github.com/sindresorhus/decamelize) on table/column/etc. names.
*/
decamelize?: boolean;
/**
* Redirect log messages to this function, rather than `console`.
*/
log?: LogFn;
/**
* Redirect messages to this logger object, rather than `console`.
*/
logger?: Logger;
/**
* Print all debug messages like DB queries run (if you switch it on, it will disable `logger.debug` method).
*/
verbose?: boolean;
}
export interface RunnerOptionUrl {
/**
* Connection string or client config which is passed to [new pg.Client](https://node-postgres.com/api/client#constructor)
*/
databaseUrl: string | ClientConfig;
}
export interface RunnerOptionClient {
/**
* Instance of [new pg.Client](https://node-postgres.com/api/client).
*
* Instance should be connected to DB and after finishing migration, user is responsible to close connection.
*/
dbClient: ClientBase;
}
export type RunnerOption = RunnerOptionConfig &
(RunnerOptionClient | RunnerOptionUrl);