@contember/database-migrations 2.2.0-alpha.2 → 2.2.0-alpha.21

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.
Files changed (48) hide show
  1. package/dist/development/index.cjs +5 -1
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +5 -1
  4. package/dist/development/index.js.map +1 -1
  5. package/dist/development/src/Migration.cjs.map +1 -1
  6. package/dist/development/src/Migration.js.map +1 -1
  7. package/dist/development/src/MigrationBuilder.cjs +299 -0
  8. package/dist/development/src/MigrationBuilder.cjs.map +1 -0
  9. package/dist/development/src/MigrationBuilder.js +299 -0
  10. package/dist/development/src/MigrationBuilder.js.map +1 -0
  11. package/dist/development/src/helpers.cjs +4 -16
  12. package/dist/development/src/helpers.cjs.map +1 -1
  13. package/dist/development/src/helpers.js +4 -15
  14. package/dist/development/src/helpers.js.map +1 -1
  15. package/dist/production/index.cjs +5 -1
  16. package/dist/production/index.cjs.map +1 -1
  17. package/dist/production/index.js +5 -1
  18. package/dist/production/index.js.map +1 -1
  19. package/dist/production/src/Migration.cjs.map +1 -1
  20. package/dist/production/src/Migration.js.map +1 -1
  21. package/dist/production/src/MigrationBuilder.cjs +299 -0
  22. package/dist/production/src/MigrationBuilder.cjs.map +1 -0
  23. package/dist/production/src/MigrationBuilder.js +299 -0
  24. package/dist/production/src/MigrationBuilder.js.map +1 -0
  25. package/dist/production/src/helpers.cjs +4 -16
  26. package/dist/production/src/helpers.cjs.map +1 -1
  27. package/dist/production/src/helpers.js +4 -15
  28. package/dist/production/src/helpers.js.map +1 -1
  29. package/dist/types/GroupMigrationsResolver.d.ts.map +1 -1
  30. package/dist/types/Migration.d.ts +1 -1
  31. package/dist/types/Migration.d.ts.map +1 -1
  32. package/dist/types/MigrationBuilder.d.ts +95 -0
  33. package/dist/types/MigrationBuilder.d.ts.map +1 -0
  34. package/dist/types/MigrationsRunner.d.ts.map +1 -1
  35. package/dist/types/SnapshotMigrationResolver.d.ts.map +1 -1
  36. package/dist/types/helpers.d.ts +3 -6
  37. package/dist/types/helpers.d.ts.map +1 -1
  38. package/dist/types/index.d.ts +2 -1
  39. package/dist/types/index.d.ts.map +1 -1
  40. package/dist/types/runner.d.ts.map +1 -1
  41. package/dist/types/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +2 -3
  43. package/readme.md +1 -1
  44. package/src/Migration.ts +1 -1
  45. package/src/MigrationBuilder.ts +419 -0
  46. package/src/helpers.ts +4 -17
  47. package/src/index.ts +2 -1
  48. package/tests/cases/unit/migrationBuilder.test.ts +486 -0
@@ -0,0 +1,419 @@
1
+ /*
2
+ The SQL generation in this file is ported from the migration builder of node-pg-migrate. (https://github.com/salsita/node-pg-migrate)
3
+
4
+ The MIT License (MIT)
5
+
6
+ Copyright (c) 2016-2020 Salsita Software <jando@salsitasoft.com>
7
+
8
+ Copyright (c) 2014-2016 Theo Ephraim
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ */
28
+
29
+ // Collects the SQL of engine and content migrations. The output reproduces node-pg-migrate 5 byte for byte for the
30
+ // operations and options below, because not-yet-run migrations on existing databases must execute the same SQL. It differs
31
+ // only for a name containing `"`, which node-pg-migrate did not escape.
32
+
33
+ export type Name = string | { schema?: string; name: string }
34
+
35
+ export type Value = null | boolean | string | number | readonly Value[]
36
+
37
+ export interface SequenceOptions {
38
+ precedence: 'ALWAYS' | 'BY DEFAULT'
39
+ type?: string
40
+ increment?: number
41
+ minvalue?: number | null | false
42
+ maxvalue?: number | null | false
43
+ start?: number
44
+ cache?: number
45
+ cycle?: boolean
46
+ owner?: string | null | false
47
+ }
48
+
49
+ export interface ColumnDefinition {
50
+ type: string
51
+ collation?: string
52
+ default?: Value
53
+ unique?: boolean
54
+ primaryKey?: boolean
55
+ notNull?: boolean
56
+ references?: Name
57
+ onDelete?: string
58
+ sequenceGenerated?: SequenceOptions
59
+ }
60
+
61
+ export interface AlterColumnOptions {
62
+ type?: string
63
+ collation?: string
64
+ using?: string
65
+ notNull?: boolean
66
+ sequenceGenerated?: SequenceOptions | false
67
+ }
68
+
69
+ export interface TriggerOptions {
70
+ when: 'BEFORE' | 'AFTER'
71
+ operation: string | readonly string[]
72
+ level?: 'ROW' | 'STATEMENT'
73
+ function: Name
74
+ functionParams?: readonly Value[]
75
+ constraint?: boolean
76
+ deferrable?: boolean
77
+ deferred?: boolean
78
+ }
79
+
80
+ export interface FunctionParam {
81
+ name: string
82
+ type: string
83
+ }
84
+
85
+ const quote = (identifier: string): string => `"${identifier.replace(/"/g, '""')}"`
86
+
87
+ const literal = (name: Name): string => typeof name === 'object' ? (name.schema ? `${quote(name.schema)}.` : '') + quote(name.name) : quote(name)
88
+
89
+ const nextDollarTag = function*(): Generator<string> {
90
+ const chars = 'abcdefghijklmnopqrstuvwxyz'
91
+ const ids = [0]
92
+ while (true) {
93
+ yield `$pg${ids.map(id => chars[id]).join('')}$`
94
+ let i = ids.length - 1
95
+ for (; i >= 0; i--) {
96
+ ids[i] += 1
97
+ if (ids[i] < chars.length) {
98
+ break
99
+ }
100
+ ids[i] = 0
101
+ }
102
+ if (i < 0) {
103
+ ids.unshift(0)
104
+ }
105
+ }
106
+ }
107
+
108
+ // Inner arrays stay bare `[..]` (valid inside ARRAY[..]) so the emitted SQL matches what earlier versions generated.
109
+ const escapeArrayBody = (values: unknown[]): string => `[${values.map(it => Array.isArray(it) ? escapeArrayBody(it) : escapeValue(it)).join(',')}]`
110
+
111
+ // node-pg-migrate's PgLiteral shape; migration JSON (e.g. a fill value or column default) can carry it.
112
+ export const isPgLiteral = (value: unknown): value is { literal: true; value: unknown } =>
113
+ typeof value === 'object' && value !== null && 'literal' in value && value.literal === true && 'value' in value
114
+
115
+ const describeUnescapable = (value: unknown): string => {
116
+ if (typeof value === 'number') {
117
+ return String(value)
118
+ }
119
+ if (typeof value === 'object') {
120
+ return 'an object'
121
+ }
122
+ return typeof value === 'undefined' ? 'undefined' : `a ${typeof value}`
123
+ }
124
+
125
+ export const escapeValue = (value: unknown): string | number => {
126
+ if (value === null) {
127
+ return 'NULL'
128
+ }
129
+ if (typeof value === 'boolean') {
130
+ return value.toString()
131
+ }
132
+ if (typeof value === 'string') {
133
+ // The closing tag follows the value, so a value ending in `$pga` would form `$pga$` with it.
134
+ for (const tag of nextDollarTag()) {
135
+ if (!`${value}$`.includes(tag)) {
136
+ return `${tag}${value}${tag}`
137
+ }
138
+ }
139
+ }
140
+ if (typeof value === 'number' && Number.isFinite(value)) {
141
+ return value
142
+ }
143
+ if (Array.isArray(value)) {
144
+ return `ARRAY${escapeArrayBody(value)}`
145
+ }
146
+ if (isPgLiteral(value)) {
147
+ return typeof value.value === 'number' ? value.value : `${value.value}`
148
+ }
149
+ throw new Error(`Cannot escape ${describeUnescapable(value)} as an SQL value`)
150
+ }
151
+
152
+ const typeAdapters: Record<string, string> = {
153
+ int: 'integer',
154
+ string: 'text',
155
+ float: 'real',
156
+ double: 'double precision',
157
+ datetime: 'timestamp',
158
+ bool: 'boolean',
159
+ }
160
+
161
+ const adaptType = (type: string): string => typeAdapters[type] ?? type
162
+
163
+ // `id` is node-pg-migrate's only default type shorthand; on columns it also implies a primary key.
164
+ const resolveType = (type: string): string => type === 'id' ? 'serial' : adaptType(type)
165
+
166
+ const applyColumnShorthand = (column: ColumnDefinition): ColumnDefinition =>
167
+ column.type === 'id' ? { primaryKey: true, ...column, type: 'serial' } : { ...column, type: adaptType(column.type) }
168
+
169
+ const formatLines = (lines: readonly string[], prefix = ' ', separator = ','): string =>
170
+ lines
171
+ .map(line => line.replace(/(?:\r\n|\r|\n)+/g, ' '))
172
+ .join(`${separator}\n`)
173
+ .replace(/^/gm, prefix)
174
+
175
+ const SEQUENCE_PRECEDENCES: readonly string[] = ['ALWAYS', 'BY DEFAULT']
176
+
177
+ // Sequence options arrive unparsed from migration JSON and go into the SQL as is, so each one must have its declared shape.
178
+ export const assertValidSequenceOptions = (sequence: SequenceOptions): void => {
179
+ const { precedence, type, increment, minvalue, maxvalue, start, cache, owner } = sequence
180
+ if (!SEQUENCE_PRECEDENCES.includes(precedence)) {
181
+ throw new Error(`Invalid sequence precedence ${JSON.stringify(precedence)}: expected ALWAYS or BY DEFAULT`)
182
+ }
183
+ for (const [name, value] of Object.entries({ increment, minvalue, maxvalue, start, cache })) {
184
+ if (value !== undefined && value !== null && value !== false && !Number.isInteger(value)) {
185
+ throw new Error(`Invalid sequence option ${name} ${JSON.stringify(value)}: expected an integer`)
186
+ }
187
+ }
188
+ if (type !== undefined && !/^[a-zA-Z_][a-zA-Z0-9_ ]*$/.test(type)) {
189
+ throw new Error(`Invalid sequence type ${JSON.stringify(type)}: expected a type name`)
190
+ }
191
+ if (owner && !/^[_a-zA-Z][_a-zA-Z0-9$]*(\.[_a-zA-Z][_a-zA-Z0-9$]*){1,2}$/.test(owner)) {
192
+ throw new Error(`Invalid sequence owner ${JSON.stringify(owner)}: expected table.column`)
193
+ }
194
+ }
195
+
196
+ // Every option node-pg-migrate rendered is kept.
197
+ const sequenceClause = (sequence: SequenceOptions): string => {
198
+ assertValidSequenceOptions(sequence)
199
+ const { type, increment, minvalue, maxvalue, start, cache, cycle, owner } = sequence
200
+ const clauses: string[] = []
201
+ if (type) {
202
+ clauses.push(`AS ${resolveType(type)}`)
203
+ }
204
+ if (increment) {
205
+ clauses.push(`INCREMENT BY ${increment}`)
206
+ }
207
+ if (minvalue) {
208
+ clauses.push(`MINVALUE ${minvalue}`)
209
+ } else if (minvalue === null || minvalue === false) {
210
+ clauses.push('NO MINVALUE')
211
+ }
212
+ if (maxvalue) {
213
+ clauses.push(`MAXVALUE ${maxvalue}`)
214
+ } else if (maxvalue === null || maxvalue === false) {
215
+ clauses.push('NO MAXVALUE')
216
+ }
217
+ if (start) {
218
+ clauses.push(`START WITH ${start}`)
219
+ }
220
+ if (cache) {
221
+ clauses.push(`CACHE ${cache}`)
222
+ }
223
+ if (cycle) {
224
+ clauses.push('CYCLE')
225
+ } else if (cycle === false) {
226
+ clauses.push('NO CYCLE')
227
+ }
228
+ if (owner) {
229
+ clauses.push(`OWNED BY ${owner}`)
230
+ } else if (owner === null || owner === false) {
231
+ clauses.push('OWNED BY NONE')
232
+ }
233
+ return `GENERATED ${sequence.precedence} AS IDENTITY${clauses.length ? ` (${clauses.join(' ')})` : ''}`
234
+ }
235
+
236
+ const referencesClause = (column: ColumnDefinition & { references: Name }): string => {
237
+ const { references, onDelete } = column
238
+ const target = typeof references === 'string' && (references.startsWith('"') || references.endsWith(')')) ? references : literal(references)
239
+ return `REFERENCES ${target}${onDelete ? ` ON DELETE ${onDelete}` : ''}`
240
+ }
241
+
242
+ const columnLines = (columns: Record<string, ColumnDefinition>): { lines: string[]; primaryKey: string[] } => {
243
+ const applied = Object.entries(columns).map(([name, column]) => [name, applyColumnShorthand(column)] as const)
244
+ const primaryKey = applied.filter(([, column]) => column.primaryKey).map(([name]) => name)
245
+ const lines = applied.map(([name, column]) => {
246
+ const constraints: string[] = []
247
+ if (column.collation) {
248
+ constraints.push(`COLLATE ${column.collation}`)
249
+ }
250
+ if (column.default !== undefined) {
251
+ constraints.push(`DEFAULT ${escapeValue(column.default)}`)
252
+ }
253
+ if (column.unique) {
254
+ constraints.push('UNIQUE')
255
+ }
256
+ if (column.primaryKey && primaryKey.length === 1) {
257
+ constraints.push('PRIMARY KEY')
258
+ }
259
+ if (column.notNull) {
260
+ constraints.push('NOT NULL')
261
+ }
262
+ if (column.references) {
263
+ constraints.push(referencesClause({ ...column, references: column.references }))
264
+ }
265
+ if (column.sequenceGenerated) {
266
+ constraints.push(sequenceClause(column.sequenceGenerated))
267
+ }
268
+ return `${literal(name)} ${column.type}${constraints.length ? ` ${constraints.join(' ')}` : ''}`
269
+ })
270
+ return { lines, primaryKey: primaryKey.length > 1 ? primaryKey : [] }
271
+ }
272
+
273
+ const tableNameOf = (table: Name): string => typeof table === 'object' ? table.name : table
274
+
275
+ export class MigrationBuilder {
276
+ private readonly steps: string[] = []
277
+
278
+ getSqlSteps(): string[] {
279
+ return [...this.steps]
280
+ }
281
+
282
+ getSql(): string {
283
+ return `${this.steps.join('\n')}\n`
284
+ }
285
+
286
+ sql(sql: string): void {
287
+ this.steps.push(sql.lastIndexOf(';') !== sql.length - 1 ? `${sql};` : sql)
288
+ }
289
+
290
+ createTable(table: Name, columns: Record<string, ColumnDefinition>): void {
291
+ const { lines, primaryKey } = columnLines(columns)
292
+ const definition = primaryKey.length > 0
293
+ ? [...lines, `CONSTRAINT ${literal(`${tableNameOf(table)}_pkey`)} PRIMARY KEY (${primaryKey.map(name => literal(name)).join(', ')})`]
294
+ : lines
295
+ this.steps.push(`CREATE TABLE ${literal(table)} (\n${formatLines(definition)}\n);`)
296
+ }
297
+
298
+ dropTable(table: Name): void {
299
+ this.steps.push(`DROP TABLE ${literal(table)};`)
300
+ }
301
+
302
+ renameTable(table: Name, newName: Name): void {
303
+ this.steps.push(`ALTER TABLE ${literal(table)} RENAME TO ${literal(newName)};`)
304
+ }
305
+
306
+ addColumn(table: Name, columns: Record<string, ColumnDefinition>): void {
307
+ this.steps.push(`ALTER TABLE ${literal(table)}\n${formatLines(columnLines(columns).lines, ' ADD ')};`)
308
+ }
309
+
310
+ dropColumn(table: Name, column: string): void {
311
+ this.steps.push(`ALTER TABLE ${literal(table)}\n${formatLines([literal(column)], ' DROP ')};`)
312
+ }
313
+
314
+ renameColumn(table: Name, column: string, newName: string): void {
315
+ this.steps.push(`ALTER TABLE ${literal(table)} RENAME ${literal(column)} TO ${literal(newName)};`)
316
+ }
317
+
318
+ alterColumn(table: Name, column: string, options: AlterColumnOptions): void {
319
+ const actions: string[] = []
320
+ if (options.type) {
321
+ const collation = options.collation ? ` COLLATE ${options.collation}` : ''
322
+ const using = options.using ? ` USING ${options.using}` : ''
323
+ actions.push(`SET DATA TYPE ${adaptType(options.type)}${collation}${using}`)
324
+ }
325
+ if (options.notNull) {
326
+ actions.push('SET NOT NULL')
327
+ } else if (options.notNull === false) {
328
+ actions.push('DROP NOT NULL')
329
+ }
330
+ if (options.sequenceGenerated !== undefined) {
331
+ actions.push(options.sequenceGenerated ? `ADD ${sequenceClause(options.sequenceGenerated)}` : 'DROP IDENTITY')
332
+ }
333
+ if (actions.length > 0) {
334
+ this.steps.push(`ALTER TABLE ${literal(table)}\n${formatLines(actions, ` ALTER ${literal(column)} `)};`)
335
+ } else {
336
+ this.steps.push('')
337
+ }
338
+ }
339
+
340
+ addConstraint(table: Name, constraintName: string | null, options: { primaryKey: readonly string[] }): void {
341
+ const name = literal(constraintName || `${tableNameOf(table)}_pkey`)
342
+ const constraint = `CONSTRAINT ${name} PRIMARY KEY (${options.primaryKey.map(column => literal(column)).join(', ')})`
343
+ this.steps.push(`ALTER TABLE ${literal(table)}\n${formatLines([constraint], ' ADD ')};`)
344
+ }
345
+
346
+ dropConstraint(table: Name, constraintName: string): void {
347
+ this.steps.push(`ALTER TABLE ${literal(table)} DROP CONSTRAINT ${literal(constraintName)};`)
348
+ }
349
+
350
+ createIndex(table: Name, columns: readonly string[], options: { name: string }): void {
351
+ const columnsSql = columns.map(column => /[. ()]/.test(column) ? column : literal(column)).join(', ')
352
+ const name = options.name || `${tableNameOf(table)}_${columns.join('_')}_index`
353
+ this.steps.push(`CREATE INDEX ${literal(name)} ON ${literal(table)} (${columnsSql});`)
354
+ }
355
+
356
+ createDomain(domain: Name, type: string, options: { check: string; constraintName?: string }): void {
357
+ const constraintName = options.constraintName ? ` CONSTRAINT ${literal(options.constraintName)}` : ''
358
+ const check = options.check ? `${constraintName} CHECK (${options.check})` : ''
359
+ this.steps.push(`CREATE DOMAIN ${literal(domain)} AS ${resolveType(type)}${check};`)
360
+ }
361
+
362
+ renameDomain(domain: Name, newName: Name): void {
363
+ this.steps.push(`ALTER DOMAIN ${literal(domain)} RENAME TO ${literal(newName)};`)
364
+ }
365
+
366
+ dropDomain(domain: Name): void {
367
+ this.steps.push(`DROP DOMAIN ${literal(domain)};`)
368
+ }
369
+
370
+ createView(view: Name, options: { replace?: boolean }, definition: string): void {
371
+ this.steps.push(`CREATE${options.replace ? ' OR REPLACE' : ''} VIEW ${literal(view)} AS ${definition};`)
372
+ }
373
+
374
+ renameView(view: Name, newName: Name): void {
375
+ this.steps.push(`ALTER VIEW ${literal(view)} RENAME TO ${literal(newName)};`)
376
+ }
377
+
378
+ dropView(view: Name): void {
379
+ this.steps.push(`DROP VIEW ${literal(view)};`)
380
+ }
381
+
382
+ createMaterializedView(view: Name, options: { data?: boolean }, definition: string): void {
383
+ const data = options.data !== undefined ? ` WITH${options.data ? '' : ' NO'} DATA` : ''
384
+ this.steps.push(`CREATE MATERIALIZED VIEW ${literal(view)} AS ${definition}${data};`)
385
+ }
386
+
387
+ dropMaterializedView(view: Name): void {
388
+ this.steps.push(`DROP MATERIALIZED VIEW ${literal(view)};`)
389
+ }
390
+
391
+ createTrigger(table: Name, trigger: string, options: TriggerOptions): void {
392
+ const { constraint, deferrable, deferred, functionParams = [], level = 'STATEMENT' } = options
393
+ const when = constraint ? 'AFTER' : options.when
394
+ const operations = typeof options.operation === 'string' ? options.operation : options.operation.join(' OR ')
395
+ if (!options.function) {
396
+ throw new Error("Can't determine function name")
397
+ }
398
+ if (!operations) {
399
+ throw new Error('"operation" (INSERT/UPDATE[ OF ...]/DELETE/TRUNCATE) have to be specified')
400
+ }
401
+ const defer = constraint ? `${deferrable ? `DEFERRABLE INITIALLY ${deferred ? 'DEFERRED' : 'IMMEDIATE'}` : 'NOT DEFERRABLE'}\n ` : ''
402
+ this.steps.push(
403
+ `CREATE${constraint ? ' CONSTRAINT' : ''} TRIGGER ${literal(trigger)}\n`
404
+ + ` ${when} ${operations} ON ${literal(table)}\n`
405
+ + ` ${defer}FOR EACH ${level}\n`
406
+ + ` EXECUTE PROCEDURE ${literal(options.function)}(${functionParams.map(escapeValue).join(', ')});`,
407
+ )
408
+ }
409
+
410
+ dropTrigger(table: Name, trigger: string, options: { ifExists?: boolean } = {}): void {
411
+ this.steps.push(`DROP TRIGGER${options.ifExists ? ' IF EXISTS' : ''} ${literal(trigger)} ON ${literal(table)};`)
412
+ }
413
+
414
+ dropFunction(fn: Name, params: readonly FunctionParam[]): void {
415
+ const paramsSql = params.map(param => [param.name ? literal(param.name) : '', param.type ? resolveType(param.type) : ''].filter(Boolean).join(' '))
416
+ .join(', ')
417
+ this.steps.push(`DROP FUNCTION ${literal(fn)}(${paramsSql});`)
418
+ }
419
+ }
package/src/helpers.ts CHANGED
@@ -1,23 +1,10 @@
1
- import { MigrationBuilder } from 'node-pg-migrate'
2
1
  import { Migration, RunMigration } from './Migration.js'
3
- import MigrationBuilderImpl from 'node-pg-migrate/dist/migration-builder.js'
4
- import { escapeValue as pgEscape } from 'node-pg-migrate/dist/utils.js'
2
+ import { MigrationBuilder } from './MigrationBuilder.js'
5
3
 
6
- export function createMigrationBuilder(): MigrationBuilder & { getSql: () => string; getSqlSteps: () => string[] } {
7
- const impl = 'default' in MigrationBuilderImpl ? (MigrationBuilderImpl as any).default : MigrationBuilderImpl
8
- return new impl(
9
- {
10
- query: null,
11
- select: null,
12
- } as any,
13
- {},
14
- false,
15
- {} as any,
16
- )
17
- }
4
+ export { escapeValue, isPgLiteral } from './MigrationBuilder.js'
18
5
 
19
- export function escapeValue(value: any): string | number {
20
- return pgEscape(value)
6
+ export function createMigrationBuilder(): MigrationBuilder {
7
+ return new MigrationBuilder()
21
8
  }
22
9
 
23
10
  export const timePrefixLength = 'YYYY-MM-DD-XXXXXX'.length
package/src/index.ts CHANGED
@@ -4,5 +4,6 @@ export * from './SnapshotMigrationResolver.js'
4
4
  export * from './helpers.js'
5
5
  export * from './Migration.js'
6
6
  export * from './MigrationsResolver.js'
7
- export type { MigrationBuilder, Name } from 'node-pg-migrate'
7
+ export { assertValidSequenceOptions, MigrationBuilder } from './MigrationBuilder.js'
8
+ export type { AlterColumnOptions, ColumnDefinition, FunctionParam, Name, SequenceOptions, TriggerOptions, Value } from './MigrationBuilder.js'
8
9
  export type { DatabaseConfig } from '@contember/database'