@contember/database-migrations 2.1.0-alpha.3 → 2.1.0-alpha.35
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/package.json +11 -6
- package/src/Migration.ts +0 -1
- package/src/SnapshotMigrationResolver.ts +0 -1
- package/src/runner.ts +6 -13
- package/tests/cases/unit/groupMigrationResolver.test.ts +0 -1
- package/tests/cases/unit/snapshotMigrationResolver.test.ts +14 -10
- package/tsconfig.settings.json +0 -1
- package/dist/development/index.cjs +0 -17
- package/dist/development/index.cjs.map +0 -1
- package/dist/development/index.js +0 -17
- package/dist/development/index.js.map +0 -1
- package/dist/development/src/GroupMigrationsResolver.cjs +0 -38
- package/dist/development/src/GroupMigrationsResolver.cjs.map +0 -1
- package/dist/development/src/GroupMigrationsResolver.js +0 -38
- package/dist/development/src/GroupMigrationsResolver.js.map +0 -1
- package/dist/development/src/Migration.cjs +0 -18
- package/dist/development/src/Migration.cjs.map +0 -1
- package/dist/development/src/Migration.js +0 -18
- package/dist/development/src/Migration.js.map +0 -1
- package/dist/development/src/MigrationsRunner.cjs +0 -21
- package/dist/development/src/MigrationsRunner.cjs.map +0 -1
- package/dist/development/src/MigrationsRunner.js +0 -20
- package/dist/development/src/MigrationsRunner.js.map +0 -1
- package/dist/development/src/SnapshotMigrationResolver.cjs +0 -49
- package/dist/development/src/SnapshotMigrationResolver.cjs.map +0 -1
- package/dist/development/src/SnapshotMigrationResolver.js +0 -49
- package/dist/development/src/SnapshotMigrationResolver.js.map +0 -1
- package/dist/development/src/helpers.cjs +0 -38
- package/dist/development/src/helpers.cjs.map +0 -1
- package/dist/development/src/helpers.js +0 -38
- package/dist/development/src/helpers.js.map +0 -1
- package/dist/development/src/runner.cjs +0 -94
- package/dist/development/src/runner.cjs.map +0 -1
- package/dist/development/src/runner.js +0 -95
- package/dist/development/src/runner.js.map +0 -1
- package/dist/production/index.cjs +0 -17
- package/dist/production/index.cjs.map +0 -1
- package/dist/production/index.js +0 -17
- package/dist/production/index.js.map +0 -1
- package/dist/production/src/GroupMigrationsResolver.cjs +0 -38
- package/dist/production/src/GroupMigrationsResolver.cjs.map +0 -1
- package/dist/production/src/GroupMigrationsResolver.js +0 -38
- package/dist/production/src/GroupMigrationsResolver.js.map +0 -1
- package/dist/production/src/Migration.cjs +0 -18
- package/dist/production/src/Migration.cjs.map +0 -1
- package/dist/production/src/Migration.js +0 -18
- package/dist/production/src/Migration.js.map +0 -1
- package/dist/production/src/MigrationsRunner.cjs +0 -21
- package/dist/production/src/MigrationsRunner.cjs.map +0 -1
- package/dist/production/src/MigrationsRunner.js +0 -20
- package/dist/production/src/MigrationsRunner.js.map +0 -1
- package/dist/production/src/SnapshotMigrationResolver.cjs +0 -49
- package/dist/production/src/SnapshotMigrationResolver.cjs.map +0 -1
- package/dist/production/src/SnapshotMigrationResolver.js +0 -49
- package/dist/production/src/SnapshotMigrationResolver.js.map +0 -1
- package/dist/production/src/helpers.cjs +0 -38
- package/dist/production/src/helpers.cjs.map +0 -1
- package/dist/production/src/helpers.js +0 -38
- package/dist/production/src/helpers.js.map +0 -1
- package/dist/production/src/runner.cjs +0 -94
- package/dist/production/src/runner.cjs.map +0 -1
- package/dist/production/src/runner.js +0 -95
- package/dist/production/src/runner.js.map +0 -1
- package/dist/types/GroupMigrationsResolver.d.ts +0 -9
- package/dist/types/GroupMigrationsResolver.d.ts.map +0 -1
- package/dist/types/Migration.d.ts +0 -22
- package/dist/types/Migration.d.ts.map +0 -1
- package/dist/types/MigrationsResolver.d.ts +0 -8
- package/dist/types/MigrationsResolver.d.ts.map +0 -1
- package/dist/types/MigrationsRunner.d.ts +0 -12
- package/dist/types/MigrationsRunner.d.ts.map +0 -1
- package/dist/types/SnapshotMigrationResolver.d.ts +0 -14
- package/dist/types/SnapshotMigrationResolver.d.ts.map +0 -1
- package/dist/types/helpers.d.ts +0 -10
- package/dist/types/helpers.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -9
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/runner.d.ts +0 -13
- package/dist/types/runner.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","sources":["../../../../packages/database-migrations/src/helpers.ts"],"sourcesContent":["import { MigrationBuilder } from 'node-pg-migrate'\nimport { Migration, RunMigration } from './Migration'\nimport MigrationBuilderImpl from 'node-pg-migrate/dist/migration-builder.js'\nimport { escapeValue as pgEscape } from 'node-pg-migrate/dist/utils.js'\n\nexport function createMigrationBuilder(): MigrationBuilder & { getSql: () => string; getSqlSteps: () => string[] } {\n\tconst impl = 'default' in MigrationBuilderImpl ? (MigrationBuilderImpl as any).default : MigrationBuilderImpl\n\treturn new impl(\n\t\t{\n\t\t\tquery: null,\n\t\t\tselect: null,\n\t\t} as any,\n\t\t{},\n\t\tfalse,\n\t\t{} as any,\n\t)\n}\n\nexport function escapeValue(value: any): string | number {\n\treturn pgEscape(value)\n}\n\nexport const timePrefixLength = 'YYYY-MM-DD-XXXXXX'.length\n\nexport const checkOrder = (runMigrations: RunMigration[], migrations: Migration<any>[]) => {\n\tconst len = Math.min(runMigrations.length, migrations.length)\n\tfor (let i = 0; i < len; i++) {\n\t\tconst run = runMigrations[i]\n\t\tconst migrationName = migrations[i].name\n\t\tif (migrationName > run.name) {\n\t\t\tthrow new Error(`Previously executed migration ${run} is missing`)\n\t\t}\n\t\tif (run.name > migrationName) {\n\t\t\tthrow new Error(`Not executed migration ${migrationName} is preceding already run migration ${run.name}`)\n\t\t}\n\t}\n}\n"],"names":["pgEscape"],"mappings":";;;;AAKO,SAAS,yBAAmG;AAClH,QAAM,OAAO,aAAa,uBAAwB,qBAA6B,UAAU;AACzF,SAAO,IAAI;AAAA,IACV;AAAA,MACC,OAAO;AAAA,MACP,QAAQ;AAAA,IACT;AAAA,IACA,CAAC;AAAA,IACD;AAAA,IACA,CAAA;AAAA,EACD;AACD;AAEO,SAAS,YAAY,OAA6B;AACxD,SAAOA,SAAAA,YAAS,KAAK;AACtB;AAEO,MAAM,mBAAmB,oBAAoB;AAEvC,MAAA,aAAa,CAAC,eAA+B,eAAiC;AAC1F,QAAM,MAAM,KAAK,IAAI,cAAc,QAAQ,WAAW,MAAM;AAC5D,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AACvB,UAAA,MAAM,cAAc,CAAC;AACrB,UAAA,gBAAgB,WAAW,CAAC,EAAE;AAChC,QAAA,gBAAgB,IAAI,MAAM;AAC7B,YAAM,IAAI,MAAM,iCAAiC,GAAG,aAAa;AAAA,IAAA;AAE9D,QAAA,IAAI,OAAO,eAAe;AAC7B,YAAM,IAAI,MAAM,0BAA0B,aAAa,uCAAuC,IAAI,IAAI,EAAE;AAAA,IAAA;AAAA,EACzG;AAEF;;;;;"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import MigrationBuilderImpl from "node-pg-migrate/dist/migration-builder.js";
|
|
2
|
-
import { escapeValue as escapeValue$1 } from "node-pg-migrate/dist/utils.js";
|
|
3
|
-
function createMigrationBuilder() {
|
|
4
|
-
const impl = "default" in MigrationBuilderImpl ? MigrationBuilderImpl.default : MigrationBuilderImpl;
|
|
5
|
-
return new impl(
|
|
6
|
-
{
|
|
7
|
-
query: null,
|
|
8
|
-
select: null
|
|
9
|
-
},
|
|
10
|
-
{},
|
|
11
|
-
false,
|
|
12
|
-
{}
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
function escapeValue(value) {
|
|
16
|
-
return escapeValue$1(value);
|
|
17
|
-
}
|
|
18
|
-
const timePrefixLength = "YYYY-MM-DD-XXXXXX".length;
|
|
19
|
-
const checkOrder = (runMigrations, migrations) => {
|
|
20
|
-
const len = Math.min(runMigrations.length, migrations.length);
|
|
21
|
-
for (let i = 0; i < len; i++) {
|
|
22
|
-
const run = runMigrations[i];
|
|
23
|
-
const migrationName = migrations[i].name;
|
|
24
|
-
if (migrationName > run.name) {
|
|
25
|
-
throw new Error(`Previously executed migration ${run} is missing`);
|
|
26
|
-
}
|
|
27
|
-
if (run.name > migrationName) {
|
|
28
|
-
throw new Error(`Not executed migration ${migrationName} is preceding already run migration ${run.name}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
export {
|
|
33
|
-
checkOrder,
|
|
34
|
-
createMigrationBuilder,
|
|
35
|
-
escapeValue,
|
|
36
|
-
timePrefixLength
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":["../../../../packages/database-migrations/src/helpers.ts"],"sourcesContent":["import { MigrationBuilder } from 'node-pg-migrate'\nimport { Migration, RunMigration } from './Migration'\nimport MigrationBuilderImpl from 'node-pg-migrate/dist/migration-builder.js'\nimport { escapeValue as pgEscape } from 'node-pg-migrate/dist/utils.js'\n\nexport function createMigrationBuilder(): MigrationBuilder & { getSql: () => string; getSqlSteps: () => string[] } {\n\tconst impl = 'default' in MigrationBuilderImpl ? (MigrationBuilderImpl as any).default : MigrationBuilderImpl\n\treturn new impl(\n\t\t{\n\t\t\tquery: null,\n\t\t\tselect: null,\n\t\t} as any,\n\t\t{},\n\t\tfalse,\n\t\t{} as any,\n\t)\n}\n\nexport function escapeValue(value: any): string | number {\n\treturn pgEscape(value)\n}\n\nexport const timePrefixLength = 'YYYY-MM-DD-XXXXXX'.length\n\nexport const checkOrder = (runMigrations: RunMigration[], migrations: Migration<any>[]) => {\n\tconst len = Math.min(runMigrations.length, migrations.length)\n\tfor (let i = 0; i < len; i++) {\n\t\tconst run = runMigrations[i]\n\t\tconst migrationName = migrations[i].name\n\t\tif (migrationName > run.name) {\n\t\t\tthrow new Error(`Previously executed migration ${run} is missing`)\n\t\t}\n\t\tif (run.name > migrationName) {\n\t\t\tthrow new Error(`Not executed migration ${migrationName} is preceding already run migration ${run.name}`)\n\t\t}\n\t}\n}\n"],"names":["pgEscape"],"mappings":";;AAKO,SAAS,yBAAmG;AAClH,QAAM,OAAO,aAAa,uBAAwB,qBAA6B,UAAU;AACzF,SAAO,IAAI;AAAA,IACV;AAAA,MACC,OAAO;AAAA,MACP,QAAQ;AAAA,IACT;AAAA,IACA,CAAC;AAAA,IACD;AAAA,IACA,CAAA;AAAA,EACD;AACD;AAEO,SAAS,YAAY,OAA6B;AACxD,SAAOA,cAAS,KAAK;AACtB;AAEO,MAAM,mBAAmB,oBAAoB;AAEvC,MAAA,aAAa,CAAC,eAA+B,eAAiC;AAC1F,QAAM,MAAM,KAAK,IAAI,cAAc,QAAQ,WAAW,MAAM;AAC5D,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AACvB,UAAA,MAAM,cAAc,CAAC;AACrB,UAAA,gBAAgB,WAAW,CAAC,EAAE;AAChC,QAAA,gBAAgB,IAAI,MAAM;AAC7B,YAAM,IAAI,MAAM,iCAAiC,GAAG,aAAa;AAAA,IAAA;AAE9D,QAAA,IAAI,OAAO,eAAe;AAC7B,YAAM,IAAI,MAAM,0BAA0B,aAAa,uCAAuC,IAAI,IAAI,EAAE;AAAA,IAAA;AAAA,EACzG;AAEF;"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const helpers = require("./helpers.cjs");
|
|
3
|
-
const Database = require("@contember/database");
|
|
4
|
-
const PG_MIGRATE_LOCK_ID = 7241865325823964;
|
|
5
|
-
const getMigrationsTableName = (options) => {
|
|
6
|
-
return `${Database.wrapIdentifier(options.schema)}.${Database.wrapIdentifier(options.migrationsTable)}`;
|
|
7
|
-
};
|
|
8
|
-
const ensureMigrationsTable = async (db, options) => {
|
|
9
|
-
try {
|
|
10
|
-
const fullTableName = getMigrationsTableName(options);
|
|
11
|
-
await db.query(
|
|
12
|
-
`
|
|
13
|
-
CREATE TABLE IF NOT EXISTS ${fullTableName} (
|
|
14
|
-
id INT PRIMARY KEY,
|
|
15
|
-
name varchar(255) NOT NULL,
|
|
16
|
-
run_on timestamp NOT NULL
|
|
17
|
-
)`
|
|
18
|
-
);
|
|
19
|
-
await db.query(`ALTER TABLE ${fullTableName} ADD COLUMN IF NOT EXISTS "group" TEXT DEFAULT NULL`);
|
|
20
|
-
await db.query(`ALTER TABLE ${fullTableName} ALTER id DROP DEFAULT`);
|
|
21
|
-
const seqName = (await db.query(`
|
|
22
|
-
SELECT pg_get_serial_sequence('${fullTableName}', 'id') as seq_name
|
|
23
|
-
`)).rows[0].seq_name;
|
|
24
|
-
if (seqName) {
|
|
25
|
-
await db.query(`DROP SEQUENCE ${seqName}`);
|
|
26
|
-
}
|
|
27
|
-
} catch (err) {
|
|
28
|
-
if (!(err instanceof Error)) {
|
|
29
|
-
throw err;
|
|
30
|
-
}
|
|
31
|
-
throw new Error(`Unable to ensure migrations table: ${err.stack}`);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const getRunMigrations = async (db, options) => {
|
|
35
|
-
const fullTableName = getMigrationsTableName(options);
|
|
36
|
-
return (await db.query(`SELECT name, "group" FROM ${fullTableName} ORDER BY run_on, id`)).rows;
|
|
37
|
-
};
|
|
38
|
-
const getMigrationsToRun = (options, runNames, migrations) => {
|
|
39
|
-
return migrations.filter(({ name }) => runNames.indexOf(name) < 0);
|
|
40
|
-
};
|
|
41
|
-
const runner = async (migrationsResolver, connection, options) => {
|
|
42
|
-
const logger = options.log;
|
|
43
|
-
return await connection.scope(
|
|
44
|
-
(db) => Database.withDatabaseAdvisoryLock(db, PG_MIGRATE_LOCK_ID, async () => {
|
|
45
|
-
await db.query(`CREATE SCHEMA IF NOT EXISTS ${Database.wrapIdentifier(options.schema)}`);
|
|
46
|
-
await db.query(`SET search_path TO ${Database.wrapIdentifier(options.schema)}`);
|
|
47
|
-
await ensureMigrationsTable(db, options);
|
|
48
|
-
const runMigrations = await getRunMigrations(db, options);
|
|
49
|
-
const migrations = await migrationsResolver.resolveMigrations({
|
|
50
|
-
runMigrations
|
|
51
|
-
});
|
|
52
|
-
const runNames = runMigrations.map((it) => it.name);
|
|
53
|
-
const toRun = getMigrationsToRun(options, runNames, migrations);
|
|
54
|
-
if (!toRun.length) {
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
logger(`Migrating ${toRun.length} file(s):`);
|
|
58
|
-
return await db.transaction(async (trx) => {
|
|
59
|
-
try {
|
|
60
|
-
for (const migration of toRun) {
|
|
61
|
-
try {
|
|
62
|
-
logger(` Executing migration ${migration.name}...`);
|
|
63
|
-
const migrationsBuilder = helpers.createMigrationBuilder();
|
|
64
|
-
await migration.migration(migrationsBuilder, { ...options.migrationArgs, connection: trx });
|
|
65
|
-
const steps = migrationsBuilder.getSqlSteps();
|
|
66
|
-
for (const sql of steps) {
|
|
67
|
-
await trx.query(sql);
|
|
68
|
-
}
|
|
69
|
-
const maxId = await trx.query(`SELECT MAX(id) as id FROM ${getMigrationsTableName(options)}`);
|
|
70
|
-
const nextId = (maxId.rows[0]?.id ?? 0) + 1;
|
|
71
|
-
await trx.query(
|
|
72
|
-
`INSERT INTO ${getMigrationsTableName(options)} (id, name, run_on, "group") VALUES (?, ?, NOW(), ?);`,
|
|
73
|
-
[nextId, migration.name, migration.group]
|
|
74
|
-
);
|
|
75
|
-
logger(` Done`);
|
|
76
|
-
} catch (e) {
|
|
77
|
-
logger(` FAILED`);
|
|
78
|
-
throw e;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
} catch (err) {
|
|
82
|
-
logger("Rolling back attempted migration ...");
|
|
83
|
-
await trx.rollback();
|
|
84
|
-
throw err;
|
|
85
|
-
}
|
|
86
|
-
return toRun.map((m) => ({
|
|
87
|
-
name: m.name
|
|
88
|
-
}));
|
|
89
|
-
});
|
|
90
|
-
})
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
module.exports = runner;
|
|
94
|
-
//# sourceMappingURL=runner.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.cjs","sources":["../../../../packages/database-migrations/src/runner.ts"],"sourcesContent":["/*\nThis file is based on migration runner from node-pg-migrate. (https://github.com/salsita/node-pg-migrate)\n\nThe MIT License (MIT)\n\nCopyright (c) 2016-2020 Salsita Software <jando@salsitasoft.com>\n\nCopyright (c) 2014-2016 Theo Ephraim\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\nimport {\n\tcreateMigrationBuilder,\n} from './helpers'\nimport { Connection, withDatabaseAdvisoryLock, wrapIdentifier } from '@contember/database'\nimport { Migration, RunMigration } from './Migration'\nimport { MigrationsResolver } from './MigrationsResolver'\n\nexport type RunnerOption<Args = unknown> = {\n\tmigrationsTable: string\n\tschema: string\n\tlog: (msg: string) => void\n\tmigrationArgs: Args\n}\n\n\n// Random but well-known identifier shared by all instances of node-pg-migrate\nconst PG_MIGRATE_LOCK_ID = 7241865325823964\n\nconst getMigrationsTableName = (options: RunnerOption): string => {\n\treturn `${wrapIdentifier(options.schema)}.${wrapIdentifier(options.migrationsTable)}`\n}\nconst ensureMigrationsTable = async (db: Connection.ConnectionLike, options: RunnerOption): Promise<void> => {\n\ttry {\n\t\tconst fullTableName = getMigrationsTableName(options)\n\t\tawait db.query(`\n\t\t\tCREATE TABLE IF NOT EXISTS ${fullTableName} (\n\t\t\t\tid INT PRIMARY KEY,\n\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\trun_on timestamp NOT NULL\n\t\t\t)`,\n\t\t)\n\t\tawait db.query(`ALTER TABLE ${fullTableName} ADD COLUMN IF NOT EXISTS \"group\" TEXT DEFAULT NULL`)\n\n\t\tawait db.query(`ALTER TABLE ${fullTableName} ALTER id DROP DEFAULT`)\n\t\tconst seqName = (await db.query<{seq_name: string}>(`\n\t\t\tSELECT pg_get_serial_sequence('${fullTableName}', 'id') as seq_name\n\t\t`)).rows[0].seq_name\n\t\tif (seqName) {\n\t\t\tawait db.query(`DROP SEQUENCE ${seqName}`)\n\t\t}\n\t} catch (err) {\n\t\tif (!(err instanceof Error)) {\n\t\t\tthrow err\n\t\t}\n\t\tthrow new Error(`Unable to ensure migrations table: ${err.stack}`)\n\t}\n}\n\nconst getRunMigrations = async (db: Connection.ConnectionLike, options: RunnerOption<unknown>) => {\n\tconst fullTableName = getMigrationsTableName(options)\n\treturn (await db.query<{name: string; group: string | null}>(`SELECT name, \"group\" FROM ${fullTableName} ORDER BY run_on, id`)).rows\n}\n\nconst getMigrationsToRun = <Args>(options: RunnerOption, runNames: string[], migrations: Migration<Args>[]): Migration<Args>[] => {\n\treturn migrations.filter(({ name }) => runNames.indexOf(name) < 0)\n}\n\nexport default async <Args>(\n\tmigrationsResolver: MigrationsResolver<Args>,\n\tconnection: Connection.ConnectionLike,\n\toptions: RunnerOption<Args>,\n): Promise<{ name: string }[]> => {\n\tconst logger = options.log\n\treturn await connection.scope(db =>\n\t\twithDatabaseAdvisoryLock(db, PG_MIGRATE_LOCK_ID, async () => {\n\t\t\tawait db.query(`CREATE SCHEMA IF NOT EXISTS ${wrapIdentifier(options.schema)}`)\n\t\t\tawait db.query(`SET search_path TO ${wrapIdentifier(options.schema)}`)\n\t\t\tawait ensureMigrationsTable(db, options)\n\n\n\t\t\tconst runMigrations = await getRunMigrations(db, options)\n\t\t\tconst migrations = await migrationsResolver.resolveMigrations({\n\t\t\t\trunMigrations,\n\t\t\t})\n\n\t\t\tconst runNames = runMigrations.map(it => it.name)\n\t\t\tconst toRun: Migration<Args>[] = getMigrationsToRun(options, runNames, migrations)\n\n\t\t\tif (!toRun.length) {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tlogger(`Migrating ${toRun.length} file(s):`)\n\t\t\treturn await db.transaction(async trx => {\n\t\t\t\ttry {\n\t\t\t\t\tfor (const migration of toRun) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tlogger(` Executing migration ${migration.name}...`)\n\t\t\t\t\t\t\tconst migrationsBuilder = createMigrationBuilder()\n\t\t\t\t\t\t\tawait migration.migration(migrationsBuilder, { ...options.migrationArgs, connection: trx })\n\t\t\t\t\t\t\tconst steps = migrationsBuilder.getSqlSteps()\n\n\t\t\t\t\t\t\tfor (const sql of steps) {\n\t\t\t\t\t\t\t\tawait trx.query(sql)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst maxId = await trx.query<{id: number}>(`SELECT MAX(id) as id FROM ${getMigrationsTableName(options)}`)\n\t\t\t\t\t\t\tconst nextId = (maxId.rows[0]?.id ?? 0) + 1\n\t\t\t\t\t\t\tawait trx.query(\n\t\t\t\t\t\t\t\t`INSERT INTO ${getMigrationsTableName(options)} (id, name, run_on, \"group\") VALUES (?, ?, NOW(), ?);`,\n\t\t\t\t\t\t\t\t[nextId, migration.name, migration.group],\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tlogger(` Done`)\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\tlogger(` FAILED`)\n\t\t\t\t\t\t\tthrow e\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tlogger('Rolling back attempted migration ...')\n\t\t\t\t\tawait trx.rollback()\n\t\t\t\t\tthrow err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oBAAA;AAAA,YAAA;AAAA,UACP;AAAA,iBAEO,KAAK;AACb,iBAAO,sCAAsC;AAC7C,gBAAM,IAAI,SAAS;AACb,gBAAA;AAAA,QAAA;AAEA,eAAA,MAAM,IAAI,CAAM,OAAA;AAAA,UACtB,MAAM,EAAE;AAAA,QAAA,EACP;AAAA,MAAA,CAEF;AAAA,IACD,CAAA;AAAA,EACF;AAED;;"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { createMigrationBuilder } from "./helpers.js";
|
|
2
|
-
import { withDatabaseAdvisoryLock, wrapIdentifier } from "@contember/database";
|
|
3
|
-
const PG_MIGRATE_LOCK_ID = 7241865325823964;
|
|
4
|
-
const getMigrationsTableName = (options) => {
|
|
5
|
-
return `${wrapIdentifier(options.schema)}.${wrapIdentifier(options.migrationsTable)}`;
|
|
6
|
-
};
|
|
7
|
-
const ensureMigrationsTable = async (db, options) => {
|
|
8
|
-
try {
|
|
9
|
-
const fullTableName = getMigrationsTableName(options);
|
|
10
|
-
await db.query(
|
|
11
|
-
`
|
|
12
|
-
CREATE TABLE IF NOT EXISTS ${fullTableName} (
|
|
13
|
-
id INT PRIMARY KEY,
|
|
14
|
-
name varchar(255) NOT NULL,
|
|
15
|
-
run_on timestamp NOT NULL
|
|
16
|
-
)`
|
|
17
|
-
);
|
|
18
|
-
await db.query(`ALTER TABLE ${fullTableName} ADD COLUMN IF NOT EXISTS "group" TEXT DEFAULT NULL`);
|
|
19
|
-
await db.query(`ALTER TABLE ${fullTableName} ALTER id DROP DEFAULT`);
|
|
20
|
-
const seqName = (await db.query(`
|
|
21
|
-
SELECT pg_get_serial_sequence('${fullTableName}', 'id') as seq_name
|
|
22
|
-
`)).rows[0].seq_name;
|
|
23
|
-
if (seqName) {
|
|
24
|
-
await db.query(`DROP SEQUENCE ${seqName}`);
|
|
25
|
-
}
|
|
26
|
-
} catch (err) {
|
|
27
|
-
if (!(err instanceof Error)) {
|
|
28
|
-
throw err;
|
|
29
|
-
}
|
|
30
|
-
throw new Error(`Unable to ensure migrations table: ${err.stack}`);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const getRunMigrations = async (db, options) => {
|
|
34
|
-
const fullTableName = getMigrationsTableName(options);
|
|
35
|
-
return (await db.query(`SELECT name, "group" FROM ${fullTableName} ORDER BY run_on, id`)).rows;
|
|
36
|
-
};
|
|
37
|
-
const getMigrationsToRun = (options, runNames, migrations) => {
|
|
38
|
-
return migrations.filter(({ name }) => runNames.indexOf(name) < 0);
|
|
39
|
-
};
|
|
40
|
-
const runner = async (migrationsResolver, connection, options) => {
|
|
41
|
-
const logger = options.log;
|
|
42
|
-
return await connection.scope(
|
|
43
|
-
(db) => withDatabaseAdvisoryLock(db, PG_MIGRATE_LOCK_ID, async () => {
|
|
44
|
-
await db.query(`CREATE SCHEMA IF NOT EXISTS ${wrapIdentifier(options.schema)}`);
|
|
45
|
-
await db.query(`SET search_path TO ${wrapIdentifier(options.schema)}`);
|
|
46
|
-
await ensureMigrationsTable(db, options);
|
|
47
|
-
const runMigrations = await getRunMigrations(db, options);
|
|
48
|
-
const migrations = await migrationsResolver.resolveMigrations({
|
|
49
|
-
runMigrations
|
|
50
|
-
});
|
|
51
|
-
const runNames = runMigrations.map((it) => it.name);
|
|
52
|
-
const toRun = getMigrationsToRun(options, runNames, migrations);
|
|
53
|
-
if (!toRun.length) {
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
56
|
-
logger(`Migrating ${toRun.length} file(s):`);
|
|
57
|
-
return await db.transaction(async (trx) => {
|
|
58
|
-
try {
|
|
59
|
-
for (const migration of toRun) {
|
|
60
|
-
try {
|
|
61
|
-
logger(` Executing migration ${migration.name}...`);
|
|
62
|
-
const migrationsBuilder = createMigrationBuilder();
|
|
63
|
-
await migration.migration(migrationsBuilder, { ...options.migrationArgs, connection: trx });
|
|
64
|
-
const steps = migrationsBuilder.getSqlSteps();
|
|
65
|
-
for (const sql of steps) {
|
|
66
|
-
await trx.query(sql);
|
|
67
|
-
}
|
|
68
|
-
const maxId = await trx.query(`SELECT MAX(id) as id FROM ${getMigrationsTableName(options)}`);
|
|
69
|
-
const nextId = (maxId.rows[0]?.id ?? 0) + 1;
|
|
70
|
-
await trx.query(
|
|
71
|
-
`INSERT INTO ${getMigrationsTableName(options)} (id, name, run_on, "group") VALUES (?, ?, NOW(), ?);`,
|
|
72
|
-
[nextId, migration.name, migration.group]
|
|
73
|
-
);
|
|
74
|
-
logger(` Done`);
|
|
75
|
-
} catch (e) {
|
|
76
|
-
logger(` FAILED`);
|
|
77
|
-
throw e;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
} catch (err) {
|
|
81
|
-
logger("Rolling back attempted migration ...");
|
|
82
|
-
await trx.rollback();
|
|
83
|
-
throw err;
|
|
84
|
-
}
|
|
85
|
-
return toRun.map((m) => ({
|
|
86
|
-
name: m.name
|
|
87
|
-
}));
|
|
88
|
-
});
|
|
89
|
-
})
|
|
90
|
-
);
|
|
91
|
-
};
|
|
92
|
-
export {
|
|
93
|
-
runner as default
|
|
94
|
-
};
|
|
95
|
-
//# sourceMappingURL=runner.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sources":["../../../../packages/database-migrations/src/runner.ts"],"sourcesContent":["/*\nThis file is based on migration runner from node-pg-migrate. (https://github.com/salsita/node-pg-migrate)\n\nThe MIT License (MIT)\n\nCopyright (c) 2016-2020 Salsita Software <jando@salsitasoft.com>\n\nCopyright (c) 2014-2016 Theo Ephraim\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\nimport {\n\tcreateMigrationBuilder,\n} from './helpers'\nimport { Connection, withDatabaseAdvisoryLock, wrapIdentifier } from '@contember/database'\nimport { Migration, RunMigration } from './Migration'\nimport { MigrationsResolver } from './MigrationsResolver'\n\nexport type RunnerOption<Args = unknown> = {\n\tmigrationsTable: string\n\tschema: string\n\tlog: (msg: string) => void\n\tmigrationArgs: Args\n}\n\n\n// Random but well-known identifier shared by all instances of node-pg-migrate\nconst PG_MIGRATE_LOCK_ID = 7241865325823964\n\nconst getMigrationsTableName = (options: RunnerOption): string => {\n\treturn `${wrapIdentifier(options.schema)}.${wrapIdentifier(options.migrationsTable)}`\n}\nconst ensureMigrationsTable = async (db: Connection.ConnectionLike, options: RunnerOption): Promise<void> => {\n\ttry {\n\t\tconst fullTableName = getMigrationsTableName(options)\n\t\tawait db.query(`\n\t\t\tCREATE TABLE IF NOT EXISTS ${fullTableName} (\n\t\t\t\tid INT PRIMARY KEY,\n\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\trun_on timestamp NOT NULL\n\t\t\t)`,\n\t\t)\n\t\tawait db.query(`ALTER TABLE ${fullTableName} ADD COLUMN IF NOT EXISTS \"group\" TEXT DEFAULT NULL`)\n\n\t\tawait db.query(`ALTER TABLE ${fullTableName} ALTER id DROP DEFAULT`)\n\t\tconst seqName = (await db.query<{seq_name: string}>(`\n\t\t\tSELECT pg_get_serial_sequence('${fullTableName}', 'id') as seq_name\n\t\t`)).rows[0].seq_name\n\t\tif (seqName) {\n\t\t\tawait db.query(`DROP SEQUENCE ${seqName}`)\n\t\t}\n\t} catch (err) {\n\t\tif (!(err instanceof Error)) {\n\t\t\tthrow err\n\t\t}\n\t\tthrow new Error(`Unable to ensure migrations table: ${err.stack}`)\n\t}\n}\n\nconst getRunMigrations = async (db: Connection.ConnectionLike, options: RunnerOption<unknown>) => {\n\tconst fullTableName = getMigrationsTableName(options)\n\treturn (await db.query<{name: string; group: string | null}>(`SELECT name, \"group\" FROM ${fullTableName} ORDER BY run_on, id`)).rows\n}\n\nconst getMigrationsToRun = <Args>(options: RunnerOption, runNames: string[], migrations: Migration<Args>[]): Migration<Args>[] => {\n\treturn migrations.filter(({ name }) => runNames.indexOf(name) < 0)\n}\n\nexport default async <Args>(\n\tmigrationsResolver: MigrationsResolver<Args>,\n\tconnection: Connection.ConnectionLike,\n\toptions: RunnerOption<Args>,\n): Promise<{ name: string }[]> => {\n\tconst logger = options.log\n\treturn await connection.scope(db =>\n\t\twithDatabaseAdvisoryLock(db, PG_MIGRATE_LOCK_ID, async () => {\n\t\t\tawait db.query(`CREATE SCHEMA IF NOT EXISTS ${wrapIdentifier(options.schema)}`)\n\t\t\tawait db.query(`SET search_path TO ${wrapIdentifier(options.schema)}`)\n\t\t\tawait ensureMigrationsTable(db, options)\n\n\n\t\t\tconst runMigrations = await getRunMigrations(db, options)\n\t\t\tconst migrations = await migrationsResolver.resolveMigrations({\n\t\t\t\trunMigrations,\n\t\t\t})\n\n\t\t\tconst runNames = runMigrations.map(it => it.name)\n\t\t\tconst toRun: Migration<Args>[] = getMigrationsToRun(options, runNames, migrations)\n\n\t\t\tif (!toRun.length) {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tlogger(`Migrating ${toRun.length} file(s):`)\n\t\t\treturn await db.transaction(async trx => {\n\t\t\t\ttry {\n\t\t\t\t\tfor (const migration of toRun) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tlogger(` Executing migration ${migration.name}...`)\n\t\t\t\t\t\t\tconst migrationsBuilder = createMigrationBuilder()\n\t\t\t\t\t\t\tawait migration.migration(migrationsBuilder, { ...options.migrationArgs, connection: trx })\n\t\t\t\t\t\t\tconst steps = migrationsBuilder.getSqlSteps()\n\n\t\t\t\t\t\t\tfor (const sql of steps) {\n\t\t\t\t\t\t\t\tawait trx.query(sql)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst maxId = await trx.query<{id: number}>(`SELECT MAX(id) as id FROM ${getMigrationsTableName(options)}`)\n\t\t\t\t\t\t\tconst nextId = (maxId.rows[0]?.id ?? 0) + 1\n\t\t\t\t\t\t\tawait trx.query(\n\t\t\t\t\t\t\t\t`INSERT INTO ${getMigrationsTableName(options)} (id, name, run_on, \"group\") VALUES (?, ?, NOW(), ?);`,\n\t\t\t\t\t\t\t\t[nextId, migration.name, migration.group],\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tlogger(` Done`)\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\tlogger(` FAILED`)\n\t\t\t\t\t\t\tthrow e\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tlogger('Rolling back attempted migration ...')\n\t\t\t\t\tawait trx.rollback()\n\t\t\t\t\tthrow err\n\t\t\t\t}\n\t\t\t\treturn toRun.map(m => ({\n\t\t\t\t\tname: m.name,\n\t\t\t\t}))\n\n\t\t\t})\n\t\t}),\n\t)\n\n}\n"],"names":[],"mappings":";;AA4CA,MAAM,qBAAqB;AAE3B,MAAM,yBAAyB,CAAC,YAAkC;AAC1D,SAAA,GAAG,eAAe,QAAQ,MAAM,CAAC,IAAI,eAAe,QAAQ,eAAe,CAAC;AACpF;AACA,MAAM,wBAAwB,OAAO,IAA+B,YAAyC;AACxG,MAAA;AACG,UAAA,gBAAgB,uBAAuB,OAAO;AACpD,UAAM,GAAG;AAAA,MAAM;AAAA,gCACe,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,IAK3C;AACA,UA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ClB,eAAO,CAAC;AAAA,MAAA;AAEF,aAAA,aAAa,MAAM,MAAM,WAAW;AAC3C,aAAO,MAAM,GAAG,YAAY,OAAM,QAAO;AACpC,YAAA;AACH,qBAAW,aAAa,OAAO;AAC1B,gBAAA;AACI,qBAAA,yBAAyB,UAAU,IAAI,KAAK;AACnD,oBAAM,oBAAoB,uBAAuB;AAC3C,oBAAA,UAAU,UAAU,mBAAmB,EAAE,GAAG,QAAQ,eAAe,YAAY,KAAK;AACpF,oBAAA,QAAQ,kBAAkB,YAAY;AAE5C,yBAAW,OAAO,OAAO;AAClB,sBAAA,IAAI,MAAM,GAAG;AAAA,cAAA;AAEd,oBAAA,QAAQ,MAAM,IAAI,MAAoB,6BAA6B,uBAAuB,OAAO,CAAC,EAAE;AAC1G,oBAAM,UAAU,MAAM,KAAK,CAAC,GAAG,MAAM,KAAK;AAC1C,oBAAM,IAAI;AAAA,gBACT,eAAe,uBAAuB,OAAO,CAAC;AAAA,gBAC9C,CAAC,QAAQ,UAAU,MAAM,UAAU,KAAK;AAAA,cACzC;AACA,qBAAO,QAAQ;AAAA,qBACP,GAAG;AACX,qBAAO,UAAU;AACX,oBAAA;AAAA,YAAA;AAAA,UACP;AAAA,iBAEO,KAAK;AACb,iBAAO,sCAAsC;AAC7C,gBAAM,IAAI,SAAS;AACb,gBAAA;AAAA,QAAA;AAEA,eAAA,MAAM,IAAI,CAAM,OAAA;AAAA,UACtB,MAAM,EAAE;AAAA,QAAA,EACP;AAAA,MAAA,CAEF;AAAA,IACD,CAAA;AAAA,EACF;AAED;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MigrationsResolver, MigrationsResolverContext } from './MigrationsResolver';
|
|
2
|
-
import { Migration } from './Migration';
|
|
3
|
-
export declare class GroupMigrationsResolver<Args> implements MigrationsResolver<Args> {
|
|
4
|
-
private readonly primaryGroup;
|
|
5
|
-
private readonly groups;
|
|
6
|
-
constructor(primaryGroup: MigrationsResolver<Args>, groups: Record<string, MigrationsResolver<Args>>);
|
|
7
|
-
resolveMigrations({ runMigrations }: MigrationsResolverContext): Migration<Args>[];
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=GroupMigrationsResolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GroupMigrationsResolver.d.ts","sourceRoot":"","sources":["../../src/GroupMigrationsResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,qBAAa,uBAAuB,CAAC,IAAI,CAAE,YAAW,kBAAkB,CAAC,IAAI,CAAC;IAE5E,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,YAAY,EAAE,kBAAkB,CAAC,IAAI,CAAC,EACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAIlE,iBAAiB,CAAC,EAAE,aAAa,EAAE,EAAE,yBAAyB,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE;CA2BlF"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { MigrationBuilder } from 'node-pg-migrate';
|
|
2
|
-
import { Connection } from '@contember/database';
|
|
3
|
-
export type MigrationExecutor<Args = unknown> = (builder: MigrationBuilder, args: MigrationArgs<Args>) => Promise<void> | void;
|
|
4
|
-
export declare class Migration<Args = unknown> {
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly migration: MigrationExecutor<Args>;
|
|
7
|
-
readonly group: string | null;
|
|
8
|
-
constructor(name: string, migration: MigrationExecutor<Args>, group?: string | null);
|
|
9
|
-
}
|
|
10
|
-
export type MigrationArgs<Args> = Args & {
|
|
11
|
-
connection: Connection.ConnectionLike;
|
|
12
|
-
};
|
|
13
|
-
export interface RunMigration {
|
|
14
|
-
name: string;
|
|
15
|
-
group: string | null;
|
|
16
|
-
}
|
|
17
|
-
export declare class MigrationGroup<Args = unknown> {
|
|
18
|
-
readonly snapshot: MigrationExecutor<Args>;
|
|
19
|
-
readonly migrations: Record<string, MigrationExecutor<Args>>;
|
|
20
|
-
constructor(snapshot: MigrationExecutor<Args>, migrations: Record<string, MigrationExecutor<Args>>);
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=Migration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Migration.d.ts","sourceRoot":"","sources":["../../src/Migration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,MAAM,MAAM,iBAAiB,CAAC,IAAI,GAAG,OAAO,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAE9H,qBAAa,SAAS,CAAC,IAAI,GAAG,OAAO;aAEnB,IAAI,EAAE,MAAM;aACZ,SAAS,EAAE,iBAAiB,CAAC,IAAI,CAAC;aAClC,KAAK,EAAE,MAAM,GAAG,IAAI;gBAFpB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,iBAAiB,CAAC,IAAI,CAAC,EAClC,KAAK,GAAE,MAAM,GAAG,IAAW;CAG5C;AAED,MAAM,MAAM,aAAa,CAAC,IAAI,IAC3B,IAAI,GACJ;IACD,UAAU,EAAE,UAAU,CAAC,cAAc,CAAA;CACrC,CAAA;AAGF,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB;AAED,qBAAa,cAAc,CAAC,IAAI,GAAG,OAAO;aAExB,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC;aACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBADnD,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,EACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAGpE"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Migration, RunMigration } from './Migration';
|
|
2
|
-
export interface MigrationsResolverContext {
|
|
3
|
-
runMigrations: RunMigration[];
|
|
4
|
-
}
|
|
5
|
-
export interface MigrationsResolver<Args> {
|
|
6
|
-
resolveMigrations(ctx: MigrationsResolverContext): Migration<Args>[];
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=MigrationsResolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationsResolver.d.ts","sourceRoot":"","sources":["../../src/MigrationsResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,WAAW,yBAAyB;IACzC,aAAa,EAAE,YAAY,EAAE,CAAA;CAC7B;AACD,MAAM,WAAW,kBAAkB,CAAC,IAAI;IACvC,iBAAiB,CAAC,GAAG,EAAE,yBAAyB,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,CAAA;CACpE"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Connection } from '@contember/database';
|
|
2
|
-
import { MigrationsResolver } from './MigrationsResolver';
|
|
3
|
-
export declare class MigrationsRunner<MigrationArgs> {
|
|
4
|
-
private readonly connection;
|
|
5
|
-
private readonly schema;
|
|
6
|
-
private readonly migrationsResolver;
|
|
7
|
-
constructor(connection: Connection.ConnectionLike, schema: string, migrationsResolver: MigrationsResolver<MigrationArgs>);
|
|
8
|
-
migrate(log: (msg: string) => void, migrationArgs: MigrationArgs): Promise<{
|
|
9
|
-
name: string;
|
|
10
|
-
}[]>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=MigrationsRunner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationsRunner.d.ts","sourceRoot":"","sources":["../../src/MigrationsRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,qBAAa,gBAAgB,CAAC,aAAa;IAEzC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,kBAAkB;gBAFlB,UAAU,EAAE,UAAU,CAAC,cAAc,EACrC,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,kBAAkB,CAAC,aAAa,CAAC;IAG1D,OAAO,CACnB,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,EAC1B,aAAa,EAAE,aAAa,GAC1B,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAS9B"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Migration, MigrationExecutor } from './Migration';
|
|
2
|
-
import { MigrationsResolver, MigrationsResolverContext } from './MigrationsResolver';
|
|
3
|
-
export declare class SnapshotMigrationResolver<Args> implements MigrationsResolver<Args> {
|
|
4
|
-
private snapshot;
|
|
5
|
-
private migrations;
|
|
6
|
-
private suffix;
|
|
7
|
-
private baseMigrations?;
|
|
8
|
-
constructor(snapshot: MigrationExecutor<Args>, migrations: Record<string, MigrationExecutor<Args>>, suffix?: string, baseMigrations?: Record<string, MigrationExecutor<Args>> | undefined);
|
|
9
|
-
resolveMigrations({ runMigrations }: MigrationsResolverContext): Migration<Args>[];
|
|
10
|
-
private canUseSnapshot;
|
|
11
|
-
private getSnapshotMigration;
|
|
12
|
-
private getEffectiveMigrations;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=SnapshotMigrationResolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnapshotMigrationResolver.d.ts","sourceRoot":"","sources":["../../src/SnapshotMigrationResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAgB,MAAM,aAAa,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAGpF,qBAAa,yBAAyB,CAAC,IAAI,CAAE,YAAW,kBAAkB,CAAC,IAAI,CAAC;IAE9E,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,cAAc,CAAC;gBAHf,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,EACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC,EACnD,MAAM,GAAE,MAAmB,EAC3B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC,YAAA;IAIjE,iBAAiB,CAChB,EAAE,aAAa,EAAE,EAAE,yBAAyB,GAC1C,SAAS,CAAC,IAAI,CAAC,EAAE;IAapB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,sBAAsB;CAkB9B"}
|
package/dist/types/helpers.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { MigrationBuilder } from 'node-pg-migrate';
|
|
2
|
-
import { Migration, RunMigration } from './Migration';
|
|
3
|
-
export declare function createMigrationBuilder(): MigrationBuilder & {
|
|
4
|
-
getSql: () => string;
|
|
5
|
-
getSqlSteps: () => string[];
|
|
6
|
-
};
|
|
7
|
-
export declare function escapeValue(value: any): string | number;
|
|
8
|
-
export declare const timePrefixLength: number;
|
|
9
|
-
export declare const checkOrder: (runMigrations: RunMigration[], migrations: Migration<any>[]) => void;
|
|
10
|
-
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAIrD,wBAAgB,sBAAsB,IAAI,gBAAgB,GAAG;IAAE,MAAM,EAAE,MAAM,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,MAAM,EAAE,CAAA;CAAE,CAWjH;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,CAEvD;AAED,eAAO,MAAM,gBAAgB,QAA6B,CAAA;AAE1D,eAAO,MAAM,UAAU,GAAI,eAAe,YAAY,EAAE,EAAE,YAAY,SAAS,CAAC,GAAG,CAAC,EAAE,SAYrF,CAAA"}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './MigrationsRunner';
|
|
2
|
-
export * from './GroupMigrationsResolver';
|
|
3
|
-
export * from './SnapshotMigrationResolver';
|
|
4
|
-
export * from './helpers';
|
|
5
|
-
export * from './Migration';
|
|
6
|
-
export * from './MigrationsResolver';
|
|
7
|
-
export type { MigrationBuilder, Name } from 'node-pg-migrate';
|
|
8
|
-
export type { DatabaseConfig } from '@contember/database';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA2B,CAAA;AACzC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA;AACpC,YAAY,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC7D,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/types/runner.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Connection } from '@contember/database';
|
|
2
|
-
import { MigrationsResolver } from './MigrationsResolver';
|
|
3
|
-
export type RunnerOption<Args = unknown> = {
|
|
4
|
-
migrationsTable: string;
|
|
5
|
-
schema: string;
|
|
6
|
-
log: (msg: string) => void;
|
|
7
|
-
migrationArgs: Args;
|
|
8
|
-
};
|
|
9
|
-
declare const _default: <Args>(migrationsResolver: MigrationsResolver<Args>, connection: Connection.ConnectionLike, options: RunnerOption<Args>) => Promise<{
|
|
10
|
-
name: string;
|
|
11
|
-
}[]>;
|
|
12
|
-
export default _default;
|
|
13
|
-
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,UAAU,EAA4C,MAAM,qBAAqB,CAAA;AAE1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,MAAM,YAAY,CAAC,IAAI,GAAG,OAAO,IAAI;IAC1C,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1B,aAAa,EAAE,IAAI,CAAA;CACnB,CAAA;yBA6CqB,IAAI,EACzB,oBAAoB,kBAAkB,CAAC,IAAI,CAAC,EAC5C,YAAY,UAAU,CAAC,cAAc,EACrC,SAAS,YAAY,CAAC,IAAI,CAAC,KACzB,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC;AAJ9B,wBA8DC"}
|