@zmdb/migrations 1.0.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.
- package/LICENSE +674 -0
- package/README.md +36 -0
- package/dist/declarations/emit.d.ts +23 -0
- package/dist/declarations/emit.d.ts.map +1 -0
- package/dist/declarations/emit.js +581 -0
- package/dist/declarations/emit.js.map +1 -0
- package/dist/declarations/index.d.ts +3 -0
- package/dist/declarations/index.d.ts.map +1 -0
- package/dist/declarations/index.js +3 -0
- package/dist/declarations/index.js.map +1 -0
- package/dist/declarations/tagged-property.d.ts +33 -0
- package/dist/declarations/tagged-property.d.ts.map +1 -0
- package/dist/declarations/tagged-property.js +148 -0
- package/dist/declarations/tagged-property.js.map +1 -0
- package/dist/embedded.d.ts +25 -0
- package/dist/embedded.d.ts.map +1 -0
- package/dist/embedded.js +133 -0
- package/dist/embedded.js.map +1 -0
- package/dist/file-io.d.ts +15 -0
- package/dist/file-io.d.ts.map +1 -0
- package/dist/file-io.js +92 -0
- package/dist/file-io.js.map +1 -0
- package/dist/files.d.ts +11 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +10 -0
- package/dist/files.js.map +1 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +350 -0
- package/dist/index.js.map +1 -0
- package/dist/introspect/common.d.ts +26 -0
- package/dist/introspect/common.d.ts.map +1 -0
- package/dist/introspect/common.js +155 -0
- package/dist/introspect/common.js.map +1 -0
- package/dist/introspect/drift.d.ts +45 -0
- package/dist/introspect/drift.d.ts.map +1 -0
- package/dist/introspect/drift.js +84 -0
- package/dist/introspect/drift.js.map +1 -0
- package/dist/introspect/index.d.ts +8 -0
- package/dist/introspect/index.d.ts.map +1 -0
- package/dist/introspect/index.js +10 -0
- package/dist/introspect/index.js.map +1 -0
- package/dist/operations/check.d.ts +16 -0
- package/dist/operations/check.d.ts.map +1 -0
- package/dist/operations/check.js +236 -0
- package/dist/operations/check.js.map +1 -0
- package/dist/operations/embed.d.ts +23 -0
- package/dist/operations/embed.d.ts.map +1 -0
- package/dist/operations/embed.js +52 -0
- package/dist/operations/embed.js.map +1 -0
- package/dist/operations/export.d.ts +9 -0
- package/dist/operations/export.d.ts.map +1 -0
- package/dist/operations/export.js +15 -0
- package/dist/operations/export.js.map +1 -0
- package/dist/operations/generate.d.ts +17 -0
- package/dist/operations/generate.d.ts.map +1 -0
- package/dist/operations/generate.js +115 -0
- package/dist/operations/generate.js.map +1 -0
- package/dist/operations/migrate.d.ts +23 -0
- package/dist/operations/migrate.d.ts.map +1 -0
- package/dist/operations/migrate.js +67 -0
- package/dist/operations/migrate.js.map +1 -0
- package/dist/operations/pull.d.ts +40 -0
- package/dist/operations/pull.d.ts.map +1 -0
- package/dist/operations/pull.js +100 -0
- package/dist/operations/pull.js.map +1 -0
- package/dist/operations/push.d.ts +20 -0
- package/dist/operations/push.d.ts.map +1 -0
- package/dist/operations/push.js +82 -0
- package/dist/operations/push.js.map +1 -0
- package/dist/operations/upgrade.d.ts +10 -0
- package/dist/operations/upgrade.d.ts.map +1 -0
- package/dist/operations/upgrade.js +38 -0
- package/dist/operations/upgrade.js.map +1 -0
- package/dist/project.d.ts +46 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +42 -0
- package/dist/project.js.map +1 -0
- package/dist/runner.d.ts +59 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +163 -0
- package/dist/runner.js.map +1 -0
- package/dist/testing/official-dialects.fixture.d.ts +16 -0
- package/dist/testing/official-dialects.fixture.d.ts.map +1 -0
- package/dist/testing/official-dialects.fixture.js +21 -0
- package/dist/testing/official-dialects.fixture.js.map +1 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/package.json +81 -0
- package/src/declarations/emit.ts +705 -0
- package/src/declarations/index.ts +13 -0
- package/src/declarations/tagged-property.ts +163 -0
- package/src/embedded.ts +192 -0
- package/src/file-io.ts +114 -0
- package/src/files.ts +34 -0
- package/src/index.ts +502 -0
- package/src/introspect/__fixtures__/mysql-8.4.11.json +371 -0
- package/src/introspect/common.ts +203 -0
- package/src/introspect/drift.ts +157 -0
- package/src/introspect/index.ts +33 -0
- package/src/operations/check.ts +309 -0
- package/src/operations/embed.ts +87 -0
- package/src/operations/export.ts +21 -0
- package/src/operations/generate.ts +144 -0
- package/src/operations/migrate.ts +110 -0
- package/src/operations/pull.ts +160 -0
- package/src/operations/push.ts +98 -0
- package/src/operations/upgrade.ts +56 -0
- package/src/project.ts +93 -0
- package/src/runner.ts +260 -0
- package/src/testing/official-dialects.fixture.ts +24 -0
- package/src/testing.ts +32 -0
package/dist/project.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { dialectName, } from '@zmdb/sql';
|
|
2
|
+
export class MigrationProjectError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = 'MigrationProjectError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function requiredDriver(project) {
|
|
9
|
+
const driver = project.driver;
|
|
10
|
+
if (driver === undefined) {
|
|
11
|
+
throw new MigrationProjectError(`config ${project.configPath} needs a driver for this operation`);
|
|
12
|
+
}
|
|
13
|
+
if (dialectName(driver.dialect) !== dialectName(project.dialect)) {
|
|
14
|
+
throw new MigrationProjectError(`config ${project.configPath} declares ${dialectName(project.dialect)} but its driver declares ${dialectName(driver.dialect)}`);
|
|
15
|
+
}
|
|
16
|
+
return driver;
|
|
17
|
+
}
|
|
18
|
+
export function migrationTarget(project) {
|
|
19
|
+
return project.dialect;
|
|
20
|
+
}
|
|
21
|
+
export function requiredDeclarationEmitter(project) {
|
|
22
|
+
const emitDeclarations = project.emitDeclarations;
|
|
23
|
+
if (emitDeclarations === undefined) {
|
|
24
|
+
throw new MigrationProjectError(`config ${project.configPath} needs a declaration emitter for this operation`);
|
|
25
|
+
}
|
|
26
|
+
return emitDeclarations;
|
|
27
|
+
}
|
|
28
|
+
export function requiredIntrospector(project) {
|
|
29
|
+
const introspector = project.introspector;
|
|
30
|
+
if (introspector === undefined) {
|
|
31
|
+
throw new MigrationProjectError(`config ${project.configPath} needs an introspector for this operation`);
|
|
32
|
+
}
|
|
33
|
+
return introspector;
|
|
34
|
+
}
|
|
35
|
+
export function requiredSourceFormatter(project) {
|
|
36
|
+
const formatSource = project.formatSource;
|
|
37
|
+
if (formatSource === undefined) {
|
|
38
|
+
throw new MigrationProjectError(`config ${project.configPath} needs a source formatter for this operation`);
|
|
39
|
+
}
|
|
40
|
+
return formatSource;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GAKZ,MAAM,WAAW,CAAC;AAsCnB,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAC,OAAyB;IACtD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,qBAAqB,CAAC,UAAU,OAAO,CAAC,UAAU,oCAAoC,CAAC,CAAC;IACpG,CAAC;IACD,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,qBAAqB,CAC7B,UAAU,OAAO,CAAC,UAAU,aAAa,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,4BAA4B,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAC/H,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAyB;IACvD,OAAO,OAAO,CAAC,OAAO,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,OAAyB;IAEzB,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAClD,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,IAAI,qBAAqB,CAAC,UAAU,OAAO,CAAC,UAAU,iDAAiD,CAAC,CAAC;IACjH,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAyB;IAC5D,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC1C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,qBAAqB,CAAC,UAAU,OAAO,CAAC,UAAU,2CAA2C,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAyB;IAC/D,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC1C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,qBAAqB,CAAC,UAAU,OAAO,CAAC,UAAU,8CAA8C,CAAC,CAAC;IAC9G,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/dist/runner.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type CompiledQuery, type SqlDialect } from '@zmdb/sql';
|
|
2
|
+
export interface Migration {
|
|
3
|
+
readonly version: number;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly up: string;
|
|
6
|
+
readonly down: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AppliedMigration {
|
|
9
|
+
readonly version: number;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** `null` identifies a ledger row written before checksums were introduced. */
|
|
12
|
+
readonly checksum: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface MigrationConnection {
|
|
15
|
+
readonly dialect?: string | SqlDialect;
|
|
16
|
+
/** False when DDL commits independently of BEGIN/ROLLBACK, as it does on MySQL. */
|
|
17
|
+
readonly transactionalDdl?: boolean;
|
|
18
|
+
exec(sql: string): Promise<void> | void;
|
|
19
|
+
appliedVersions(): Promise<readonly number[]> | readonly number[];
|
|
20
|
+
appliedMigrations?(): Promise<readonly AppliedMigration[]> | readonly AppliedMigration[];
|
|
21
|
+
recordApplied(version: number, name: string, checksum?: string): Promise<void> | void;
|
|
22
|
+
recordReverted(version: number): Promise<void> | void;
|
|
23
|
+
ensureVersionTable?(): Promise<void> | void;
|
|
24
|
+
checksum?(sql: string): Promise<string> | string;
|
|
25
|
+
transaction?<T>(run: (connection?: MigrationConnection) => Promise<T>): Promise<T>;
|
|
26
|
+
}
|
|
27
|
+
export interface MigrationDriver {
|
|
28
|
+
readonly dialect: SqlDialect;
|
|
29
|
+
execute(query: CompiledQuery): Promise<readonly Record<string, unknown>[]>;
|
|
30
|
+
transaction?<T>(run: (driver: MigrationDriver) => Promise<T>): Promise<T>;
|
|
31
|
+
}
|
|
32
|
+
export interface MigrationTableOptions {
|
|
33
|
+
readonly table?: string;
|
|
34
|
+
readonly schema?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface MigrationRunOptions {
|
|
37
|
+
readonly onWarning?: (message: string) => void;
|
|
38
|
+
}
|
|
39
|
+
export interface MigrationStatus {
|
|
40
|
+
readonly version: number;
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly applied: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Adapt any runtime database driver instance (e.g. PostgreSQL, SQLite)
|
|
46
|
+
* into an asynchronous MigrationConnection.
|
|
47
|
+
*/
|
|
48
|
+
export declare function driverMigrationConnection(driver: MigrationDriver, dialect?: SqlDialect, options?: MigrationTableOptions): MigrationConnection;
|
|
49
|
+
export declare function ensureVersionTable(conn: MigrationConnection): Promise<void>;
|
|
50
|
+
/** Apply all pending migrations in ascending version order. */
|
|
51
|
+
export declare function up(conn: MigrationConnection, migrations: readonly Migration[], options?: MigrationRunOptions): Promise<number[]>;
|
|
52
|
+
/** Roll back the single most-recently applied migration. */
|
|
53
|
+
export declare function down(conn: MigrationConnection, migrations: readonly Migration[]): Promise<number | undefined>;
|
|
54
|
+
/** Roll back every applied migration newer than `target`, newest first. */
|
|
55
|
+
export declare function downTo(conn: MigrationConnection, migrations: readonly Migration[], target: number): Promise<number[]>;
|
|
56
|
+
/** Public lifecycle name for reverting every applied migration above a target version. */
|
|
57
|
+
export declare const rollbackTo: typeof downTo;
|
|
58
|
+
export declare function status(conn: MigrationConnection, migrations: readonly Migration[]): Promise<MigrationStatus[]>;
|
|
59
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,aAAa,EAElB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+EAA+E;IAC/E,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAGD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IACvC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CAAC,CAOpH"}
|
package/dist/runner.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// #44 — async migration runner + version tracking + driver adapter.
|
|
2
|
+
// Applies/rolls back ordered migrations against an async connection or
|
|
3
|
+
// adapted database driver, recording applied versions in _zmdb_migrations.
|
|
4
|
+
import { dialectName, } from '@zmdb/sql';
|
|
5
|
+
const DEFAULT_VERSION_TABLE = `CREATE TABLE IF NOT EXISTS _zmdb_migrations (
|
|
6
|
+
version INTEGER PRIMARY KEY,
|
|
7
|
+
name TEXT NOT NULL,
|
|
8
|
+
applied_at INTEGER NOT NULL,
|
|
9
|
+
checksum TEXT
|
|
10
|
+
)`;
|
|
11
|
+
function nonTransactionalDdlWarning(dialect) {
|
|
12
|
+
const database = dialect === undefined ? 'the configured database' : typeof dialect === 'string' ? dialect : dialectName(dialect);
|
|
13
|
+
return `${database} does not support transactional DDL; a failed migration may leave its schema changes partially applied even though its ledger row is absent`;
|
|
14
|
+
}
|
|
15
|
+
function dialectMigrationDriver(dialect, driver) {
|
|
16
|
+
const transaction = driver.transaction;
|
|
17
|
+
return {
|
|
18
|
+
dialect,
|
|
19
|
+
execute: query => driver.execute(query),
|
|
20
|
+
...(transaction === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: {
|
|
23
|
+
transaction: (run) => transaction(nested => run(dialectMigrationDriver(dialect, nested))),
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Adapt any runtime database driver instance (e.g. PostgreSQL, SQLite)
|
|
29
|
+
* into an asynchronous MigrationConnection.
|
|
30
|
+
*/
|
|
31
|
+
export function driverMigrationConnection(driver, dialect = driver.dialect, options = {}) {
|
|
32
|
+
return dialect.migrations.connection(dialectMigrationDriver(dialect, driver), options);
|
|
33
|
+
}
|
|
34
|
+
export async function ensureVersionTable(conn) {
|
|
35
|
+
if (conn.ensureVersionTable !== undefined) {
|
|
36
|
+
await conn.ensureVersionTable();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
await conn.exec(DEFAULT_VERSION_TABLE);
|
|
40
|
+
}
|
|
41
|
+
/** Apply all pending migrations in ascending version order. */
|
|
42
|
+
export async function up(conn, migrations, options = {}) {
|
|
43
|
+
assertUniqueVersions(migrations);
|
|
44
|
+
await ensureVersionTable(conn);
|
|
45
|
+
const ledger = await verifiedLedger(conn, migrations);
|
|
46
|
+
const applied = new Set(ledger.map(row => row.version));
|
|
47
|
+
const pending = [...migrations].filter(migration => !applied.has(migration.version)).toSorted(byVersion);
|
|
48
|
+
if (pending.length > 0 && conn.transactionalDdl === false) {
|
|
49
|
+
options.onWarning?.(nonTransactionalDdlWarning(conn.dialect));
|
|
50
|
+
}
|
|
51
|
+
const done = [];
|
|
52
|
+
for (const migration of pending) {
|
|
53
|
+
const checksum = conn.checksum === undefined ? undefined : await conn.checksum(migration.up);
|
|
54
|
+
try {
|
|
55
|
+
await inTransaction(conn, async (transaction) => {
|
|
56
|
+
await transaction.exec(migration.up);
|
|
57
|
+
await transaction.recordApplied(migration.version, migration.name, checksum);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw migrationFailure('apply', migration, error);
|
|
62
|
+
}
|
|
63
|
+
done.push(migration.version);
|
|
64
|
+
}
|
|
65
|
+
return done;
|
|
66
|
+
}
|
|
67
|
+
/** Roll back the single most-recently applied migration. */
|
|
68
|
+
export async function down(conn, migrations) {
|
|
69
|
+
assertUniqueVersions(migrations);
|
|
70
|
+
await ensureVersionTable(conn);
|
|
71
|
+
const applied = [...(await verifiedLedger(conn, migrations))].toSorted((left, right) => right.version - left.version);
|
|
72
|
+
const latest = applied[0];
|
|
73
|
+
if (latest === undefined)
|
|
74
|
+
return undefined;
|
|
75
|
+
const migration = migrations.find(candidate => candidate.version === latest.version);
|
|
76
|
+
if (migration === undefined)
|
|
77
|
+
throw new Error(`no migration definition for applied version ${String(latest.version)}`);
|
|
78
|
+
if (migration.down.trim().length === 0) {
|
|
79
|
+
throw new Error(`migration ${String(migration.version)} ${migration.name} has no -- zmdb:down section`);
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
await inTransaction(conn, async (transaction) => {
|
|
83
|
+
await transaction.exec(migration.down);
|
|
84
|
+
await transaction.recordReverted(latest.version);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw migrationFailure('revert', migration, error);
|
|
89
|
+
}
|
|
90
|
+
return latest.version;
|
|
91
|
+
}
|
|
92
|
+
/** Roll back every applied migration newer than `target`, newest first. */
|
|
93
|
+
export async function downTo(conn, migrations, target) {
|
|
94
|
+
const reverted = [];
|
|
95
|
+
while (true) {
|
|
96
|
+
const applied = (await status(conn, migrations)).filter(item => item.applied).map(item => item.version);
|
|
97
|
+
const latest = applied.at(-1);
|
|
98
|
+
if (latest === undefined || latest <= target)
|
|
99
|
+
return reverted;
|
|
100
|
+
const version = await down(conn, migrations);
|
|
101
|
+
if (version === undefined)
|
|
102
|
+
return reverted;
|
|
103
|
+
reverted.push(version);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Public lifecycle name for reverting every applied migration above a target version. */
|
|
107
|
+
export const rollbackTo = downTo;
|
|
108
|
+
export async function status(conn, migrations) {
|
|
109
|
+
assertUniqueVersions(migrations);
|
|
110
|
+
await ensureVersionTable(conn);
|
|
111
|
+
const applied = new Set((await verifiedLedger(conn, migrations)).map(row => row.version));
|
|
112
|
+
return [...migrations]
|
|
113
|
+
.toSorted(byVersion)
|
|
114
|
+
.map(migration => ({ version: migration.version, name: migration.name, applied: applied.has(migration.version) }));
|
|
115
|
+
}
|
|
116
|
+
async function verifiedLedger(conn, migrations) {
|
|
117
|
+
const rows = conn.appliedMigrations === undefined
|
|
118
|
+
? (await conn.appliedVersions()).map(version => ({ version, name: '', checksum: null }))
|
|
119
|
+
: await conn.appliedMigrations();
|
|
120
|
+
const byMigrationVersion = new Map(migrations.map(migration => [migration.version, migration]));
|
|
121
|
+
for (const row of rows) {
|
|
122
|
+
if (row.checksum === null)
|
|
123
|
+
continue;
|
|
124
|
+
const migration = byMigrationVersion.get(row.version);
|
|
125
|
+
if (migration === undefined)
|
|
126
|
+
continue;
|
|
127
|
+
if (conn.checksum === undefined) {
|
|
128
|
+
throw new Error(`migration ${String(row.version)} ${migration.name} has a checksum, but this connection cannot verify it`);
|
|
129
|
+
}
|
|
130
|
+
const actual = await conn.checksum(migration.up);
|
|
131
|
+
if (actual !== row.checksum) {
|
|
132
|
+
throw new Error(`migration ${String(row.version)} ${migration.name} was edited after it was applied: ` +
|
|
133
|
+
`ledger has ${row.checksum}, file has ${actual}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return rows;
|
|
137
|
+
}
|
|
138
|
+
function assertUniqueVersions(migrations) {
|
|
139
|
+
const seen = new Set();
|
|
140
|
+
for (const migration of migrations) {
|
|
141
|
+
if (!Number.isSafeInteger(migration.version)) {
|
|
142
|
+
throw new TypeError(`migration ${migration.name} version ${String(migration.version)} is not a safe integer`);
|
|
143
|
+
}
|
|
144
|
+
if (seen.has(migration.version)) {
|
|
145
|
+
throw new Error(`duplicate migration version ${String(migration.version)}`);
|
|
146
|
+
}
|
|
147
|
+
seen.add(migration.version);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function inTransaction(conn, run) {
|
|
151
|
+
if (conn.transaction === undefined)
|
|
152
|
+
return run(conn);
|
|
153
|
+
return conn.transaction(transaction => run(transaction ?? conn));
|
|
154
|
+
}
|
|
155
|
+
function byVersion(left, right) {
|
|
156
|
+
return left.version - right.version;
|
|
157
|
+
}
|
|
158
|
+
function migrationFailure(action, migration, error) {
|
|
159
|
+
const sql = action === 'apply' ? migration.up : migration.down;
|
|
160
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
161
|
+
return new Error(`failed to ${action} migration ${String(migration.version)} ${migration.name}: ${reason}\nSQL:\n${sql}`, { cause: error });
|
|
162
|
+
}
|
|
163
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db/sql").SqlDialect<"mssql">;
|
|
3
|
+
export declare const mysqlDialect: import("@zmdb/sql").SqlDialect<"mysql">;
|
|
4
|
+
export declare const postgresDialect: import("@zmdb/sql").SqlDialect<"postgres">;
|
|
5
|
+
export declare const singlestoreDialect: import("@zmdb/sql").SqlDialect<"singlestore">;
|
|
6
|
+
export declare const sqliteDialect: import("@zmdb/sql").SqlDialect<"sqlite">;
|
|
7
|
+
export declare const officialDialects: Readonly<{
|
|
8
|
+
cockroach: import("@zmdb/sql").SqlDialect<"cockroach">;
|
|
9
|
+
mssql: import("@zmdb/sql").SqlDialect<"mssql">;
|
|
10
|
+
mysql: import("@zmdb/sql").SqlDialect<"mysql">;
|
|
11
|
+
postgres: import("@zmdb/sql").SqlDialect<"postgres">;
|
|
12
|
+
singlestore: import("@zmdb/sql").SqlDialect<"singlestore">;
|
|
13
|
+
sqlite: import("@zmdb/sql").SqlDialect<"sqlite">;
|
|
14
|
+
}>;
|
|
15
|
+
export type OfficialDialectName = keyof typeof officialDialects;
|
|
16
|
+
//# sourceMappingURL=official-dialects.fixture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"official-dialects.fixture.d.ts","sourceRoot":"","sources":["../../src/testing/official-dialects.fixture.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,gBAAgB,6CAAY,CAAC;AAC1C,eAAO,MAAM,YAAY,yCAAQ,CAAC;AAClC,eAAO,MAAM,YAAY,yCAAQ,CAAC;AAClC,eAAO,MAAM,eAAe,4CAAW,CAAC;AACxC,eAAO,MAAM,kBAAkB,+CAAc,CAAC;AAC9C,eAAO,MAAM,aAAa,0CAAS,CAAC;AAEpC,eAAO,MAAM,gBAAgB;;;;;;;EAO3B,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { cockroach } from '@zmdb/cockroach';
|
|
2
|
+
import { mssql } from '@zmdb/mssql';
|
|
3
|
+
import { mysql } from '@zmdb/mysql';
|
|
4
|
+
import { postgres } from '@zmdb/postgres';
|
|
5
|
+
import { singlestore } from '@zmdb/singlestore';
|
|
6
|
+
import { sqlite } from '@zmdb/sqlite';
|
|
7
|
+
export const cockroachDialect = cockroach;
|
|
8
|
+
export const mssqlDialect = mssql;
|
|
9
|
+
export const mysqlDialect = mysql;
|
|
10
|
+
export const postgresDialect = postgres;
|
|
11
|
+
export const singlestoreDialect = singlestore;
|
|
12
|
+
export const sqliteDialect = sqlite;
|
|
13
|
+
export const officialDialects = Object.freeze({
|
|
14
|
+
cockroach: cockroachDialect,
|
|
15
|
+
mssql: mssqlDialect,
|
|
16
|
+
mysql: mysqlDialect,
|
|
17
|
+
postgres: postgresDialect,
|
|
18
|
+
singlestore: singlestoreDialect,
|
|
19
|
+
sqlite: sqliteDialect,
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=official-dialects.fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"official-dialects.fixture.js","sourceRoot":"","sources":["../../src/testing/official-dialects.fixture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAC1C,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAClC,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAClC,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC;AACxC,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AAEpC,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,SAAS,EAAE,gBAAgB;IAC3B,KAAK,EAAE,YAAY;IACnB,KAAK,EAAE,YAAY;IACnB,QAAQ,EAAE,eAAe;IACzB,WAAW,EAAE,kBAAkB;IAC/B,MAAM,EAAE,aAAa;CACtB,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AppliedMigration, MigrationConnection } from './runner.js';
|
|
2
|
+
export interface MemoryMigrationConnection extends MigrationConnection {
|
|
3
|
+
readonly executed: readonly string[];
|
|
4
|
+
readonly ledger: readonly AppliedMigration[];
|
|
5
|
+
}
|
|
6
|
+
/** Deterministic in-memory protocol for package consumers and dialect conformance suites. */
|
|
7
|
+
export declare function memoryMigrationConnection(): MemoryMigrationConnection;
|
|
8
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEzE,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACpE,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CAAC;CAC9C;AAED,6FAA6F;AAC7F,wBAAgB,yBAAyB,IAAI,yBAAyB,CAuBrE"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Deterministic in-memory protocol for package consumers and dialect conformance suites. */
|
|
2
|
+
export function memoryMigrationConnection() {
|
|
3
|
+
const executed = [];
|
|
4
|
+
const ledger = [];
|
|
5
|
+
return {
|
|
6
|
+
executed,
|
|
7
|
+
ledger,
|
|
8
|
+
exec(sql) {
|
|
9
|
+
executed.push(sql);
|
|
10
|
+
},
|
|
11
|
+
appliedVersions() {
|
|
12
|
+
return ledger.map(row => row.version);
|
|
13
|
+
},
|
|
14
|
+
appliedMigrations() {
|
|
15
|
+
return ledger;
|
|
16
|
+
},
|
|
17
|
+
recordApplied(version, name, checksum) {
|
|
18
|
+
ledger.push({ version, name, checksum: checksum ?? null });
|
|
19
|
+
},
|
|
20
|
+
recordReverted(version) {
|
|
21
|
+
const index = ledger.findIndex(row => row.version === version);
|
|
22
|
+
if (index >= 0)
|
|
23
|
+
ledger.splice(index, 1);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAOA,6FAA6F;AAC7F,MAAM,UAAU,yBAAyB;IACvC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,MAAM,GAAuB,EAAE,CAAC;IACtC,OAAO;QACL,QAAQ;QACR,MAAM;QACN,IAAI,CAAC,GAAG;YACN,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QACD,eAAe;YACb,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC;QACD,iBAAiB;YACf,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ;YACnC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;QAC7D,CAAC;QACD,cAAc,CAAC,OAAO;YACpB,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;YAC/D,IAAI,KAAK,IAAI,CAAC;gBAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zmdb/migrations",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "Schema snapshots, deterministic migration plans, ledger runners, embedded execution, catalog introspection, and declaration emission for zmdb.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"database",
|
|
7
|
+
"introspection",
|
|
8
|
+
"migrations",
|
|
9
|
+
"schema",
|
|
10
|
+
"sql",
|
|
11
|
+
"typescript",
|
|
12
|
+
"zmdb"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/ambasta/zmdb#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/ambasta/zmdb/issues"
|
|
17
|
+
},
|
|
18
|
+
"license": "GPL-3.0-or-later",
|
|
19
|
+
"author": "zmdb contributors",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ambasta/zmdb.git",
|
|
23
|
+
"directory": "packages/migrations"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./declarations": {
|
|
33
|
+
"types": "./dist/declarations/index.d.ts",
|
|
34
|
+
"import": "./dist/declarations/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./embedded": {
|
|
37
|
+
"types": "./dist/embedded.d.ts",
|
|
38
|
+
"import": "./dist/embedded.js"
|
|
39
|
+
},
|
|
40
|
+
"./files": {
|
|
41
|
+
"types": "./dist/files.d.ts",
|
|
42
|
+
"import": "./dist/files.js"
|
|
43
|
+
},
|
|
44
|
+
"./introspect": {
|
|
45
|
+
"types": "./dist/introspect/index.d.ts",
|
|
46
|
+
"import": "./dist/introspect/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./introspect/runtime": {
|
|
49
|
+
"types": "./dist/introspect/common.d.ts",
|
|
50
|
+
"import": "./dist/introspect/common.js"
|
|
51
|
+
},
|
|
52
|
+
"./runner": {
|
|
53
|
+
"types": "./dist/runner.d.ts",
|
|
54
|
+
"import": "./dist/runner.js"
|
|
55
|
+
},
|
|
56
|
+
"./testing": {
|
|
57
|
+
"types": "./dist/testing.d.ts",
|
|
58
|
+
"import": "./dist/testing.js"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public",
|
|
63
|
+
"tag": "beta"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "node ../../scripts/build-package.mjs",
|
|
67
|
+
"test": "vitest run"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"oxfmt": "0.66.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"@zmdb/schema": "1.0.0-beta.1",
|
|
74
|
+
"@zmdb/sql": "1.0.0-beta.1"
|
|
75
|
+
},
|
|
76
|
+
"engines": {
|
|
77
|
+
"node": ">=26"
|
|
78
|
+
},
|
|
79
|
+
"main": "./dist/index.js",
|
|
80
|
+
"types": "./dist/index.d.ts"
|
|
81
|
+
}
|