@contember/database-migrations 2.1.0-alpha.8 → 2.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/development/src/GroupMigrationsResolver.cjs.map +1 -1
  2. package/dist/development/src/GroupMigrationsResolver.js.map +1 -1
  3. package/dist/development/src/Migration.cjs.map +1 -1
  4. package/dist/development/src/Migration.js.map +1 -1
  5. package/dist/development/src/MigrationsRunner.cjs.map +1 -1
  6. package/dist/development/src/MigrationsRunner.js.map +1 -1
  7. package/dist/development/src/SnapshotMigrationResolver.cjs.map +1 -1
  8. package/dist/development/src/SnapshotMigrationResolver.js.map +1 -1
  9. package/dist/development/src/helpers.cjs.map +1 -1
  10. package/dist/development/src/helpers.js.map +1 -1
  11. package/dist/development/src/runner.cjs +2 -4
  12. package/dist/development/src/runner.cjs.map +1 -1
  13. package/dist/development/src/runner.js +2 -4
  14. package/dist/development/src/runner.js.map +1 -1
  15. package/dist/production/src/GroupMigrationsResolver.cjs.map +1 -1
  16. package/dist/production/src/GroupMigrationsResolver.js.map +1 -1
  17. package/dist/production/src/Migration.cjs.map +1 -1
  18. package/dist/production/src/Migration.js.map +1 -1
  19. package/dist/production/src/MigrationsRunner.cjs.map +1 -1
  20. package/dist/production/src/MigrationsRunner.js.map +1 -1
  21. package/dist/production/src/SnapshotMigrationResolver.cjs.map +1 -1
  22. package/dist/production/src/SnapshotMigrationResolver.js.map +1 -1
  23. package/dist/production/src/helpers.cjs.map +1 -1
  24. package/dist/production/src/helpers.js.map +1 -1
  25. package/dist/production/src/runner.cjs +2 -4
  26. package/dist/production/src/runner.cjs.map +1 -1
  27. package/dist/production/src/runner.js +2 -4
  28. package/dist/production/src/runner.js.map +1 -1
  29. package/dist/types/Migration.d.ts.map +1 -1
  30. package/dist/types/SnapshotMigrationResolver.d.ts.map +1 -1
  31. package/dist/types/runner.d.ts.map +1 -1
  32. package/dist/types/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +10 -5
  34. package/src/Migration.ts +0 -1
  35. package/src/SnapshotMigrationResolver.ts +0 -1
  36. package/src/runner.ts +6 -13
  37. package/tests/cases/unit/groupMigrationResolver.test.ts +0 -1
  38. package/tests/cases/unit/snapshotMigrationResolver.test.ts +14 -10
  39. package/tsconfig.settings.json +0 -1
package/src/runner.ts CHANGED
@@ -26,9 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
26
  SOFTWARE.
27
27
  */
28
28
 
29
- import {
30
- createMigrationBuilder,
31
- } from './helpers'
29
+ import { createMigrationBuilder } from './helpers'
32
30
  import { Connection, withDatabaseAdvisoryLock, wrapIdentifier } from '@contember/database'
33
31
  import { Migration, RunMigration } from './Migration'
34
32
  import { MigrationsResolver } from './MigrationsResolver'
@@ -40,7 +38,6 @@ export type RunnerOption<Args = unknown> = {
40
38
  migrationArgs: Args
41
39
  }
42
40
 
43
-
44
41
  // Random but well-known identifier shared by all instances of node-pg-migrate
45
42
  const PG_MIGRATE_LOCK_ID = 7241865325823964
46
43
 
@@ -55,12 +52,11 @@ const ensureMigrationsTable = async (db: Connection.ConnectionLike, options: Run
55
52
  id INT PRIMARY KEY,
56
53
  name varchar(255) NOT NULL,
57
54
  run_on timestamp NOT NULL
58
- )`,
59
- )
55
+ )`)
60
56
  await db.query(`ALTER TABLE ${fullTableName} ADD COLUMN IF NOT EXISTS "group" TEXT DEFAULT NULL`)
61
57
 
62
58
  await db.query(`ALTER TABLE ${fullTableName} ALTER id DROP DEFAULT`)
63
- const seqName = (await db.query<{seq_name: string}>(`
59
+ const seqName = (await db.query<{ seq_name: string }>(`
64
60
  SELECT pg_get_serial_sequence('${fullTableName}', 'id') as seq_name
65
61
  `)).rows[0].seq_name
66
62
  if (seqName) {
@@ -76,7 +72,7 @@ const ensureMigrationsTable = async (db: Connection.ConnectionLike, options: Run
76
72
 
77
73
  const getRunMigrations = async (db: Connection.ConnectionLike, options: RunnerOption<unknown>) => {
78
74
  const fullTableName = getMigrationsTableName(options)
79
- return (await db.query<{name: string; group: string | null}>(`SELECT name, "group" FROM ${fullTableName} ORDER BY run_on, id`)).rows
75
+ return (await db.query<{ name: string; group: string | null }>(`SELECT name, "group" FROM ${fullTableName} ORDER BY run_on, id`)).rows
80
76
  }
81
77
 
82
78
  const getMigrationsToRun = <Args>(options: RunnerOption, runNames: string[], migrations: Migration<Args>[]): Migration<Args>[] => {
@@ -95,7 +91,6 @@ export default async <Args>(
95
91
  await db.query(`SET search_path TO ${wrapIdentifier(options.schema)}`)
96
92
  await ensureMigrationsTable(db, options)
97
93
 
98
-
99
94
  const runMigrations = await getRunMigrations(db, options)
100
95
  const migrations = await migrationsResolver.resolveMigrations({
101
96
  runMigrations,
@@ -120,7 +115,7 @@ export default async <Args>(
120
115
  for (const sql of steps) {
121
116
  await trx.query(sql)
122
117
  }
123
- const maxId = await trx.query<{id: number}>(`SELECT MAX(id) as id FROM ${getMigrationsTableName(options)}`)
118
+ const maxId = await trx.query<{ id: number }>(`SELECT MAX(id) as id FROM ${getMigrationsTableName(options)}`)
124
119
  const nextId = (maxId.rows[0]?.id ?? 0) + 1
125
120
  await trx.query(
126
121
  `INSERT INTO ${getMigrationsTableName(options)} (id, name, run_on, "group") VALUES (?, ?, NOW(), ?);`,
@@ -140,9 +135,7 @@ export default async <Args>(
140
135
  return toRun.map(m => ({
141
136
  name: m.name,
142
137
  }))
143
-
144
138
  })
145
- }),
139
+ })
146
140
  )
147
-
148
141
  }
@@ -2,7 +2,6 @@ import { describe, expect, test } from 'bun:test'
2
2
  import { GroupMigrationsResolver, Migration } from '../../../src'
3
3
 
4
4
  describe('group migration resolver', () => {
5
-
6
5
  test('merges migrations', () => {
7
6
  const runner = () => null
8
7
  const resolver = new GroupMigrationsResolver({
@@ -1,5 +1,5 @@
1
- import { expect, describe, test } from 'bun:test'
2
- import { SnapshotMigrationResolver, Migration } from '../../../src'
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { Migration, SnapshotMigrationResolver } from '../../../src'
3
3
 
4
4
  describe('snapshot migration resolver', () => {
5
5
  test('use snapshot with latest migration timestamp', () => {
@@ -16,13 +16,18 @@ describe('snapshot migration resolver', () => {
16
16
 
17
17
  test('use snapshot with latest base migration timestamp', () => {
18
18
  const snapshotRunner = () => null
19
- const resolver = new SnapshotMigrationResolver(snapshotRunner, {
20
- '2023-07-26-105000-xx': () => null,
21
- '2023-07-26-105500-yy': () => null,
22
- }, 'snapshot', {
23
- '2023-07-26-105000-xx': () => null,
24
- '2023-07-26-105700-yy': () => null,
25
- })
19
+ const resolver = new SnapshotMigrationResolver(
20
+ snapshotRunner,
21
+ {
22
+ '2023-07-26-105000-xx': () => null,
23
+ '2023-07-26-105500-yy': () => null,
24
+ },
25
+ 'snapshot',
26
+ {
27
+ '2023-07-26-105000-xx': () => null,
28
+ '2023-07-26-105700-yy': () => null,
29
+ },
30
+ )
26
31
 
27
32
  expect(resolver.resolveMigrations({ runMigrations: [] })).toStrictEqual([
28
33
  new Migration('2023-07-26-105700-snapshot', snapshotRunner),
@@ -44,7 +49,6 @@ describe('snapshot migration resolver', () => {
44
49
  ])
45
50
  })
46
51
 
47
-
48
52
  test('merge snapshot with new migrations', () => {
49
53
  const snapshotRunner = () => null
50
54
  const yyRunner = () => null
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "extends": "../../tsconfig.settings.json",
3
3
  "compilerOptions": {
4
- "downlevelIteration": true,
5
4
  "esModuleInterop": true
6
5
  }
7
6
  }