@contember/database-migrations 2.2.0-alpha.20 → 2.2.0-alpha.22
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/development/index.cjs +2 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +3 -1
- package/dist/development/src/MigrationBuilder.cjs +38 -6
- package/dist/development/src/MigrationBuilder.cjs.map +1 -1
- package/dist/development/src/MigrationBuilder.js +39 -7
- package/dist/development/src/MigrationBuilder.js.map +1 -1
- package/dist/development/src/helpers.cjs +1 -0
- package/dist/development/src/helpers.cjs.map +1 -1
- package/dist/development/src/helpers.js +2 -1
- package/dist/development/src/helpers.js.map +1 -1
- package/dist/production/index.cjs +2 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +3 -1
- package/dist/production/src/MigrationBuilder.cjs +38 -6
- package/dist/production/src/MigrationBuilder.cjs.map +1 -1
- package/dist/production/src/MigrationBuilder.js +39 -7
- package/dist/production/src/MigrationBuilder.js.map +1 -1
- package/dist/production/src/helpers.cjs +1 -0
- package/dist/production/src/helpers.cjs.map +1 -1
- package/dist/production/src/helpers.js +2 -1
- package/dist/production/src/helpers.js.map +1 -1
- package/dist/types/MigrationBuilder.d.ts +5 -0
- package/dist/types/MigrationBuilder.d.ts.map +1 -1
- package/dist/types/helpers.d.ts +1 -1
- package/dist/types/helpers.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/MigrationBuilder.ts +49 -9
- package/src/helpers.ts +1 -1
- package/src/index.ts +1 -1
- package/tests/cases/unit/migrationBuilder.test.ts +60 -13
|
@@ -280,6 +280,21 @@ describe('migration builder SQL', () => {
|
|
|
280
280
|
})
|
|
281
281
|
|
|
282
282
|
describe('migration builder edge cases', () => {
|
|
283
|
+
test('a double quote in a table, schema or column name is doubled', () => {
|
|
284
|
+
const payload = 'x" (id int); DROP TABLE "article"; --'
|
|
285
|
+
expect(sqlOf(b => {
|
|
286
|
+
b.createTable({ schema: payload, name: payload }, { [payload]: { type: 'text' } })
|
|
287
|
+
b.renameColumn('article', 'title', payload)
|
|
288
|
+
})).toEqual([
|
|
289
|
+
lines(
|
|
290
|
+
'CREATE TABLE "x"" (id int); DROP TABLE ""article""; --"."x"" (id int); DROP TABLE ""article""; --" (',
|
|
291
|
+
' "x"" (id int); DROP TABLE ""article""; --" text',
|
|
292
|
+
');',
|
|
293
|
+
),
|
|
294
|
+
'ALTER TABLE "article" RENAME "title" TO "x"" (id int); DROP TABLE ""article""; --";',
|
|
295
|
+
])
|
|
296
|
+
})
|
|
297
|
+
|
|
283
298
|
test('sql does not double a trailing semicolon', () => {
|
|
284
299
|
expect(sqlOf(b => {
|
|
285
300
|
b.sql('SELECT 1;')
|
|
@@ -367,6 +382,15 @@ describe('migration builder edge cases', () => {
|
|
|
367
382
|
])
|
|
368
383
|
})
|
|
369
384
|
|
|
385
|
+
test('sequence options with SQL in them are rejected', () => {
|
|
386
|
+
const payload = 'ALWAYS AS IDENTITY, ADD x int; DROP TABLE "t"; --'
|
|
387
|
+
expect(() => sqlOf(b => b.addColumn('t', { id: { type: 'integer', sequenceGenerated: { precedence: 'ALWAYS', owner: payload } } })))
|
|
388
|
+
.toThrow('Invalid sequence owner')
|
|
389
|
+
expect(() => sqlOf(b => b.addColumn('t', { id: { type: 'integer', sequenceGenerated: { precedence: 'ALWAYS', type: payload } } })))
|
|
390
|
+
.toThrow('Invalid sequence type')
|
|
391
|
+
expect(() => sqlOf(b => b.alterColumn('t', 'id', { sequenceGenerated: { precedence: 'ALWAYS', owner: 't.id' } }))).not.toThrow()
|
|
392
|
+
})
|
|
393
|
+
|
|
370
394
|
test('an empty index name or domain check falls back like node-pg-migrate', () => {
|
|
371
395
|
expect(sqlOf(b => {
|
|
372
396
|
b.createIndex({ schema: 's', name: 't' }, ['a', 'b'], { name: '' })
|
|
@@ -421,19 +445,42 @@ describe('escapeValue', () => {
|
|
|
421
445
|
])
|
|
422
446
|
})
|
|
423
447
|
|
|
424
|
-
test('
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
448
|
+
test('nested arrays use bare brackets inside the outer ARRAY', () => {
|
|
449
|
+
expect(escapeValue([['a', 'b'], ['c', 'd']])).toBe('ARRAY[[$pga$a$pga$,$pga$b$pga$],[$pga$c$pga$,$pga$d$pga$]]')
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
test('ARRAY inside an array string element stays inside its dollar quotes', () => {
|
|
453
|
+
const payload = '$pgARRAYa$]; DROP TABLE article; SELECT array[$pgARRAYa$'
|
|
454
|
+
expect(escapeValue([payload])).toBe(`ARRAY[$pga$${payload}$pga$]`)
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
test('a string ending in a prefix of the tag does not close its own quote', () => {
|
|
458
|
+
expect([escapeValue('x$pga'), escapeValue('$pga'), escapeValue('x$pg'), escapeValue('x$')]).toEqual([
|
|
459
|
+
'$pgb$x$pga$pgb$',
|
|
460
|
+
'$pgb$$pga$pgb$',
|
|
461
|
+
'$pga$x$pg$pga$',
|
|
462
|
+
'$pga$x$$pga$',
|
|
431
463
|
])
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
464
|
+
expect(escapeValue(['x$pga'])).toBe('ARRAY[$pgb$x$pga$pgb$]')
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
test('literal objects pass through', () => {
|
|
468
|
+
// Migration JSON (fill values, column defaults) reaches escapeValue unparsed.
|
|
469
|
+
expect([escapeValue({ literal: true, value: 'now()' }), escapeValue({ literal: true, value: 3 })]).toEqual(['now()', 3])
|
|
470
|
+
})
|
|
471
|
+
|
|
472
|
+
test.each<[string, unknown]>([
|
|
473
|
+
['NaN', NaN],
|
|
474
|
+
['Infinity', Infinity],
|
|
475
|
+
['-Infinity', -Infinity],
|
|
476
|
+
['undefined', undefined],
|
|
477
|
+
['a bigint', 1n],
|
|
478
|
+
['an empty object', {}],
|
|
479
|
+
['a plain object', { a: 1 }],
|
|
480
|
+
['an object with literal: false', { literal: false, value: 'x' }],
|
|
481
|
+
['NaN inside an array', [1, NaN]],
|
|
482
|
+
['an object inside an array', [{}]],
|
|
483
|
+
])('%s is rejected', (_, value) => {
|
|
484
|
+
expect(() => escapeValue(value)).toThrow('Cannot escape')
|
|
438
485
|
})
|
|
439
486
|
})
|