pipework 0.279.0 → 0.280.0
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/CHANGELOG.md +4 -0
- package/dist/cli/commands/migrate.d.ts +4 -0
- package/dist/cli/commands/migrate.d.ts.map +1 -1
- package/dist/cli/commands/migrate.js +17 -2
- package/dist/cli/commands/migrate.js.map +1 -1
- package/dist/data/migrate/apply.d.ts +13 -0
- package/dist/data/migrate/apply.d.ts.map +1 -1
- package/dist/data/migrate/apply.js +28 -3
- package/dist/data/migrate/apply.js.map +1 -1
- package/dist/data/migrate/run.d.ts +12 -1
- package/dist/data/migrate/run.d.ts.map +1 -1
- package/dist/data/migrate/run.js +8 -1
- package/dist/data/migrate/run.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/migrate.ts +18 -3
- package/src/data/migrate/apply.ts +38 -3
- package/src/data/migrate/run.ts +22 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.280.0
|
|
4
|
+
|
|
5
|
+
- **Added: `pipework migrate` prints the NOTICEs and WARNINGs a migration raises** (#970). The migrator's connection discarded them, so a migration that repaired state (e.g. rebuilt an invalid index) could only say so in the server log. Each notice a migration file's own statement raises is now printed as it arrives, under its database, as `NOTICE <tag> (statement n/m): <message>` with `DETAIL`/`HINT` lines when present (WARNING in yellow), so a notice before a failing statement still shows. The runner's own bookkeeping notices ("already exists, skipping") are dropped. Programmatic callers get them in `MigrateResult.notices` and live through `MigrateOptions.onNotice`. Test database provisioning stays silent. No migration needs changing.
|
|
6
|
+
|
|
3
7
|
## 0.279.0
|
|
4
8
|
|
|
5
9
|
- **Changed: `pipework run` gives the script only its own arguments** (#967). The script ran in-process with pipework's whole argv (`[node, bin/pipework.js, 'run', 'script.ts', '--', ...]`). While it runs, `process.argv` is now `[node, <absolute script path>, ...args]`, as `node script.ts ...args` gives, so `process.argv.slice(2)` and `util.parseArgs()` see only the script's arguments; the `--` is consumed. `--tenant` and `--job-type` before `--` stay pipework's. A script flag given without `--` now fails with a message naming the fix instead of `ERR_PARSE_ARGS_UNKNOWN_OPTION`. **Breaking for scripts that index argv by position** (e.g. `process.argv.slice(3)` or skipping `--`): use `process.argv.slice(2)`.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MigrateNotice } from '../../data/migrate/run.js';
|
|
1
2
|
export interface MigrateCommandOptions {
|
|
2
3
|
db: string | undefined;
|
|
3
4
|
cwd: string;
|
|
@@ -22,4 +23,7 @@ export declare function rejectRetiredFlags(options: {
|
|
|
22
23
|
allowDestructive: boolean | undefined;
|
|
23
24
|
acknowledgeLock: boolean | undefined;
|
|
24
25
|
}): string | null;
|
|
26
|
+
/** One notice or warning a migration statement raised, indented under its database. Issue #970. */
|
|
27
|
+
export declare function formatNotice(n: MigrateNotice): string;
|
|
28
|
+
export declare function printNotice(n: MigrateNotice): void;
|
|
25
29
|
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/migrate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/migrate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAG7E,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;IACtB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,OAAO,GAAG,SAAS,CAAA;IAC5B,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAA;IACrC,eAAe,EAAE,OAAO,GAAG,SAAS,CAAA;CACrC;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8D3E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAA;IACrC,eAAe,EAAE,OAAO,GAAG,SAAS,CAAA;CACrC,GAAG,MAAM,GAAG,IAAI,CAmBhB;AAuBD,mGAAmG;AACnG,wBAAgB,YAAY,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,CAQrD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,aAAa,GAAG,IAAI,CAElD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { info, success, error as logError, warn } from '../output.js';
|
|
1
|
+
import { info, success, error as logError, warn, yellow, cyan } from '../output.js';
|
|
2
2
|
import { frameworkTablesChanged } from '../../data/migrate/provision-framework.js';
|
|
3
3
|
export async function migrate(options) {
|
|
4
4
|
const { discoverInstance, findConfig } = await import('../../core/config/discover.js');
|
|
@@ -24,7 +24,7 @@ export async function migrate(options) {
|
|
|
24
24
|
if (instance.config.environment === 'production') {
|
|
25
25
|
warn('Running migrations against PRODUCTION database.');
|
|
26
26
|
}
|
|
27
|
-
const migrateOptions = {};
|
|
27
|
+
const migrateOptions = { onNotice: printNotice };
|
|
28
28
|
try {
|
|
29
29
|
if (options.db !== undefined) {
|
|
30
30
|
info(`Migrating database: ${options.db}`);
|
|
@@ -100,4 +100,19 @@ function reportFrameworkTables(result) {
|
|
|
100
100
|
`columns added ${f.columnsAdded.length === 0 ? 'none' : f.columnsAdded.join(', ')}; ` +
|
|
101
101
|
`${f.partitionsCreated.length} day partitions created`);
|
|
102
102
|
}
|
|
103
|
+
/** One notice or warning a migration statement raised, indented under its database. Issue #970. */
|
|
104
|
+
export function formatNotice(n) {
|
|
105
|
+
const label = n.severity === 'NOTICE' || n.severity === 'INFO' || n.severity === 'LOG' || n.severity === 'DEBUG'
|
|
106
|
+
? cyan(n.severity)
|
|
107
|
+
: yellow(n.severity);
|
|
108
|
+
let out = ` ${label} ${n.tag} (statement ${n.statement}/${n.statements}): ${n.message}\n`;
|
|
109
|
+
if (n.detail !== undefined)
|
|
110
|
+
out += ` DETAIL: ${n.detail}\n`;
|
|
111
|
+
if (n.hint !== undefined)
|
|
112
|
+
out += ` HINT: ${n.hint}\n`;
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
export function printNotice(n) {
|
|
116
|
+
process.stderr.write(formatNotice(n));
|
|
117
|
+
}
|
|
103
118
|
//# sourceMappingURL=migrate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../../src/cli/commands/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../../src/cli/commands/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAA;AAUlF,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAA8B;IAC1D,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAA;IACtF,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAA;IAClG,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAA;IAEzE,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;QACrC,QAAQ,CACN,2DAA2D;YAC3D,wCAAwC,CACzC,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAA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AC,CAAC,QAAQ,CAAC;QAClB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;IACtB,IAAI,GAAG,GAAG,KAAK,KAAK,KAAK,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,UAAU,MAAM,CAAC,CAAC,OAAO,IAAI,CAAA;IAC3F,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS;QAAE,GAAG,IAAI,eAAe,CAAC,CAAC,MAAM,IAAI,CAAA;IAC9D,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS;QAAE,GAAG,IAAI,aAAa,CAAC,CAAC,IAAI,IAAI,CAAA;IACxD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAgB;IAC1C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/** A NOTICE or WARNING (or other non-error message) a migration statement raised. */
|
|
2
|
+
export interface MigrationNotice {
|
|
3
|
+
severity: string;
|
|
4
|
+
message: string;
|
|
5
|
+
detail?: string;
|
|
6
|
+
hint?: string;
|
|
7
|
+
}
|
|
1
8
|
export interface ApplyOptions {
|
|
2
9
|
migrationsFolder: string;
|
|
3
10
|
migrationsTable: string;
|
|
@@ -35,6 +42,12 @@ export interface ApplyOptions {
|
|
|
35
42
|
* Issue #378.
|
|
36
43
|
*/
|
|
37
44
|
onResume?: (tag: string, fromStatement: number, total: number) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Called for each notice or warning a migration file's own statement raises,
|
|
47
|
+
* with the file's tag, the 1-based statement and the file's statement count.
|
|
48
|
+
* The runner's own bookkeeping statements never reach it. Issue #970.
|
|
49
|
+
*/
|
|
50
|
+
onNotice?: (tag: string, statement: number, statements: number, notice: MigrationNotice) => void;
|
|
38
51
|
}
|
|
39
52
|
export interface Migration {
|
|
40
53
|
tag: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../src/data/migrate/apply.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,MAAM,CAAA;IACxB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjE;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACxG;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../src/data/migrate/apply.ts"],"names":[],"mappings":"AASA,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,MAAM,CAAA;IACxB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,i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D;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,EACpD,eAAe,EAAE,MAAM,GACtB,MAAM,CAiBR;AAMD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtD"}
|
|
@@ -9,7 +9,32 @@ export async function applyMigrations(options) {
|
|
|
9
9
|
const migrations = readMigrations(options);
|
|
10
10
|
if (migrations.length === 0)
|
|
11
11
|
return 0;
|
|
12
|
-
|
|
12
|
+
// Set only while a statement from a migration file runs; the runner's own
|
|
13
|
+
// bookkeeping raises "already exists, skipping" notices that are not the
|
|
14
|
+
// migration's and are dropped.
|
|
15
|
+
let current;
|
|
16
|
+
const client = postgres(options.connectionUrl, {
|
|
17
|
+
max: 1,
|
|
18
|
+
onnotice: (n) => {
|
|
19
|
+
if (current === undefined || options.onNotice === undefined)
|
|
20
|
+
return;
|
|
21
|
+
const notice = { severity: String(n['severity']), message: String(n['message']) };
|
|
22
|
+
if (typeof n['detail'] === 'string')
|
|
23
|
+
notice.detail = n['detail'];
|
|
24
|
+
if (typeof n['hint'] === 'string')
|
|
25
|
+
notice.hint = n['hint'];
|
|
26
|
+
options.onNotice(current.tag, current.statement, current.statements, notice);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const inStatement = async (tag, statement, statements, run) => {
|
|
30
|
+
current = { tag, statement, statements };
|
|
31
|
+
try {
|
|
32
|
+
return await run();
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
current = undefined;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
13
38
|
try {
|
|
14
39
|
const table = quoteIdent(options.migrationsTable);
|
|
15
40
|
const prepared = (detail) => options.onPrepare?.(detail);
|
|
@@ -89,7 +114,7 @@ export async function applyMigrations(options) {
|
|
|
89
114
|
if (from > 0)
|
|
90
115
|
options.onResume?.(migration.tag, from + 1, migration.statements.length);
|
|
91
116
|
for (let i = from; i < migration.statements.length; i++) {
|
|
92
|
-
await client.unsafe(migration.statements[i]);
|
|
117
|
+
await inStatement(migration.tag, i + 1, migration.statements.length, () => client.unsafe(migration.statements[i]));
|
|
93
118
|
// Recorded AFTER the statement it describes: marking first would let
|
|
94
119
|
// a death between the mark and the statement skip work silently,
|
|
95
120
|
// which is worse than replaying one statement. The window that
|
|
@@ -105,7 +130,7 @@ export async function applyMigrations(options) {
|
|
|
105
130
|
else {
|
|
106
131
|
await client.begin(async (tx) => {
|
|
107
132
|
for (const [i, stmt] of migration.statements.entries()) {
|
|
108
|
-
await tx.unsafe(stmt);
|
|
133
|
+
await inStatement(migration.tag, i + 1, migration.statements.length, () => tx.unsafe(stmt));
|
|
109
134
|
options.onStatement?.(migration.tag, i + 1, migration.statements.length, applied + 1, migrations.length);
|
|
110
135
|
}
|
|
111
136
|
await tx.unsafe(`INSERT INTO ${table} ("hash", "created_at", "tag") VALUES ($1, $2, $3)`, [migration.hash, migration.folderMillis, migration.tag]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/data/migrate/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,MAAM,qBAAqB,GAAG,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"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QAC3C,MAAM,IAAI,KAAK,CACb,cAAc,SAAS,CAAC,GAAG,uBAAuB,QAAQ,CAAC,IAAI,oCAAoC;YACjG,+BAA+B,iBAAiB,CAAC,eAAe,CAAC,8BAA8B;YAC/F,kCAAkC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB;YAC7E,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,gEAAgE;YAC9F,gGAAgG;YAChG,gGAAgG;YAChG,oCAAoC,SAAS,CAAC,GAAG,aAAa;YAC9D,GAAG,iBAAiB,CAAC,eAAe,CAAC,0BAA0B,CAClE,CAAA;IACH,CAAC;IACD,6EAA6E;IAC7E,kEAAkE;IAClE,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;AAC7D,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAA;AACxC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,uBAAuB,CAAC,CAAA;AACrE,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Manifold } from '../../core/pipework.js';
|
|
2
2
|
import type { ResolvedDatabase } from '../../core/config/index.js';
|
|
3
3
|
import { type MigrationCheckResult } from './check.js';
|
|
4
|
+
import { type MigrationNotice } from './apply.js';
|
|
4
5
|
import { type FrameworkTablesResult } from './provision-framework.js';
|
|
5
6
|
export interface MigrateOptions {
|
|
7
|
+
/** Called as each notice or warning a migration statement raises arrives. Issue #970. */
|
|
8
|
+
onNotice?: (notice: MigrateNotice) => void;
|
|
6
9
|
}
|
|
7
10
|
export interface MigrateResult {
|
|
8
11
|
database: string;
|
|
@@ -11,6 +14,8 @@ export interface MigrateResult {
|
|
|
11
14
|
safetyCheck: MigrationCheckResult;
|
|
12
15
|
/** No-transaction files picked up half applied and finished. Issue #378. */
|
|
13
16
|
resumed: ResumedMigration[];
|
|
17
|
+
/** Notices and warnings raised by migration statements, in arrival order. Issue #970. */
|
|
18
|
+
notices: MigrateNotice[];
|
|
14
19
|
/** Trace/audit tables, columns and day partitions this run provisioned. */
|
|
15
20
|
frameworkTables: FrameworkTablesResult;
|
|
16
21
|
}
|
|
@@ -20,11 +25,17 @@ export interface ResumedMigration {
|
|
|
20
25
|
fromStatement: number;
|
|
21
26
|
totalStatements: number;
|
|
22
27
|
}
|
|
28
|
+
export interface MigrateNotice extends MigrationNotice {
|
|
29
|
+
tag: string;
|
|
30
|
+
/** 1-based statement within the file. */
|
|
31
|
+
statement: number;
|
|
32
|
+
statements: number;
|
|
33
|
+
}
|
|
23
34
|
export declare class UnsafeMigrationError extends Error {
|
|
24
35
|
readonly check: MigrationCheckResult;
|
|
25
36
|
readonly name = "UnsafeMigrationError";
|
|
26
37
|
constructor(check: MigrationCheckResult, message: string);
|
|
27
38
|
}
|
|
28
39
|
export declare function migrateAll(instance: Manifold, options?: MigrateOptions): Promise<MigrateResult[]>;
|
|
29
|
-
export declare function migrateOne(instance: Manifold, dbConfig: ResolvedDatabase,
|
|
40
|
+
export declare function migrateOne(instance: Manifold, dbConfig: ResolvedDatabase, options?: MigrateOptions): Promise<MigrateResult>;
|
|
30
41
|
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/data/migrate/run.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAGlE,OAAO,EAAmB,KAAK,oBAAoB,EAAE,MAAM,YAAY,C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M;CAIlB;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAU3G;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CAsErI"}
|
package/dist/data/migrate/run.js
CHANGED
|
@@ -23,7 +23,7 @@ export async function migrateAll(instance, options = {}) {
|
|
|
23
23
|
}
|
|
24
24
|
return results;
|
|
25
25
|
}
|
|
26
|
-
export async function migrateOne(instance, dbConfig,
|
|
26
|
+
export async function migrateOne(instance, dbConfig, options = {}) {
|
|
27
27
|
const conn = instance.pool.getOrCreate(dbConfig, 'owner', OWNER_LABEL_MIGRATE);
|
|
28
28
|
// Scope the safety gate to pending migrations only — hazards in already-applied
|
|
29
29
|
// migrations are history, not a decision the operator still gets to make.
|
|
@@ -48,11 +48,17 @@ export async function migrateOne(instance, dbConfig, _options = {}) {
|
|
|
48
48
|
extensionsCreated = [...dbConfig.extensions];
|
|
49
49
|
}
|
|
50
50
|
const resumed = [];
|
|
51
|
+
const notices = [];
|
|
51
52
|
const migrationsRun = await applyMigrations({
|
|
52
53
|
migrationsFolder: dbConfig.migrations,
|
|
53
54
|
migrationsTable: dbConfig.migrationTable,
|
|
54
55
|
connectionUrl: dbConfig.url,
|
|
55
56
|
onResume: (tag, fromStatement, totalStatements) => resumed.push({ tag, fromStatement, totalStatements }),
|
|
57
|
+
onNotice: (tag, statement, statements, notice) => {
|
|
58
|
+
const full = { tag, statement, statements, ...notice };
|
|
59
|
+
notices.push(full);
|
|
60
|
+
options.onNotice?.(full);
|
|
61
|
+
},
|
|
56
62
|
});
|
|
57
63
|
// Trace and audit storage rides the default database; their partitioned
|
|
58
64
|
// tables are kept out of generated migrations (#313), so migrate provisions them.
|
|
@@ -68,6 +74,7 @@ export async function migrateOne(instance, dbConfig, _options = {}) {
|
|
|
68
74
|
extensions: extensionsCreated,
|
|
69
75
|
safetyCheck,
|
|
70
76
|
resumed,
|
|
77
|
+
notices,
|
|
71
78
|
frameworkTables,
|
|
72
79
|
};
|
|
73
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/data/migrate/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAGvC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAA6B,MAAM,YAAY,CAAA;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/data/migrate/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAGvC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAA6B,MAAM,YAAY,CAAA;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAwB,MAAM,YAAY,CAAA;AAClE,OAAO,EAAE,wBAAwB,EAA8B,MAAM,0BAA0B,CAAA;AAsC/F,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAG3B;IAFA,IAAI,GAAG,sBAAsB,CAAA;IAC/C,YACkB,KAA2B,EAC3C,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QAHE,UAAK,GAAL,KAAK,CAAsB;IAI7C,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAkB,EAAE,UAA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, warn } from '../output.js'
|
|
2
|
-
import type { MigrateResult } from '../../data/migrate/run.js'
|
|
1
|
+
import { info, success, error as logError, warn, yellow, cyan } from '../output.js'
|
|
2
|
+
import type { MigrateResult, MigrateNotice } from '../../data/migrate/run.js'
|
|
3
3
|
import { frameworkTablesChanged } from '../../data/migrate/provision-framework.js'
|
|
4
4
|
|
|
5
5
|
export interface MigrateCommandOptions {
|
|
@@ -44,7 +44,7 @@ export async function migrate(options: MigrateCommandOptions): Promise<void> {
|
|
|
44
44
|
warn('Running migrations against PRODUCTION database.')
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const migrateOptions = {}
|
|
47
|
+
const migrateOptions = { onNotice: printNotice }
|
|
48
48
|
|
|
49
49
|
try {
|
|
50
50
|
if (options.db !== undefined) {
|
|
@@ -130,3 +130,18 @@ function reportFrameworkTables(result: MigrateResult): void {
|
|
|
130
130
|
`${f.partitionsCreated.length} day partitions created`,
|
|
131
131
|
)
|
|
132
132
|
}
|
|
133
|
+
|
|
134
|
+
/** One notice or warning a migration statement raised, indented under its database. Issue #970. */
|
|
135
|
+
export function formatNotice(n: MigrateNotice): string {
|
|
136
|
+
const label = n.severity === 'NOTICE' || n.severity === 'INFO' || n.severity === 'LOG' || n.severity === 'DEBUG'
|
|
137
|
+
? cyan(n.severity)
|
|
138
|
+
: yellow(n.severity)
|
|
139
|
+
let out = ` ${label} ${n.tag} (statement ${n.statement}/${n.statements}): ${n.message}\n`
|
|
140
|
+
if (n.detail !== undefined) out += ` DETAIL: ${n.detail}\n`
|
|
141
|
+
if (n.hint !== undefined) out += ` HINT: ${n.hint}\n`
|
|
142
|
+
return out
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function printNotice(n: MigrateNotice): void {
|
|
146
|
+
process.stderr.write(formatNotice(n))
|
|
147
|
+
}
|
|
@@ -7,6 +7,14 @@ import { listMigrations } from './history.js'
|
|
|
7
7
|
|
|
8
8
|
const NO_TRANSACTION_PRAGMA = '-- pipework:no-transaction'
|
|
9
9
|
|
|
10
|
+
/** A NOTICE or WARNING (or other non-error message) a migration statement raised. */
|
|
11
|
+
export interface MigrationNotice {
|
|
12
|
+
severity: string
|
|
13
|
+
message: string
|
|
14
|
+
detail?: string
|
|
15
|
+
hint?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
export interface ApplyOptions {
|
|
11
19
|
migrationsFolder: string
|
|
12
20
|
migrationsTable: string
|
|
@@ -44,6 +52,12 @@ export interface ApplyOptions {
|
|
|
44
52
|
* Issue #378.
|
|
45
53
|
*/
|
|
46
54
|
onResume?: (tag: string, fromStatement: number, total: number) => void
|
|
55
|
+
/**
|
|
56
|
+
* Called for each notice or warning a migration file's own statement raises,
|
|
57
|
+
* with the file's tag, the 1-based statement and the file's statement count.
|
|
58
|
+
* The runner's own bookkeeping statements never reach it. Issue #970.
|
|
59
|
+
*/
|
|
60
|
+
onNotice?: (tag: string, statement: number, statements: number, notice: MigrationNotice) => void
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
export interface Migration {
|
|
@@ -60,7 +74,28 @@ export async function applyMigrations(options: ApplyOptions): Promise<number> {
|
|
|
60
74
|
const migrations = readMigrations(options)
|
|
61
75
|
if (migrations.length === 0) return 0
|
|
62
76
|
|
|
63
|
-
|
|
77
|
+
// Set only while a statement from a migration file runs; the runner's own
|
|
78
|
+
// bookkeeping raises "already exists, skipping" notices that are not the
|
|
79
|
+
// migration's and are dropped.
|
|
80
|
+
let current: { tag: string; statement: number; statements: number } | undefined
|
|
81
|
+
const client = postgres(options.connectionUrl, {
|
|
82
|
+
max: 1,
|
|
83
|
+
onnotice: (n) => {
|
|
84
|
+
if (current === undefined || options.onNotice === undefined) return
|
|
85
|
+
const notice: MigrationNotice = { severity: String(n['severity']), message: String(n['message']) }
|
|
86
|
+
if (typeof n['detail'] === 'string') notice.detail = n['detail']
|
|
87
|
+
if (typeof n['hint'] === 'string') notice.hint = n['hint']
|
|
88
|
+
options.onNotice(current.tag, current.statement, current.statements, notice)
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
const inStatement = async <T>(tag: string, statement: number, statements: number, run: () => Promise<T>): Promise<T> => {
|
|
92
|
+
current = { tag, statement, statements }
|
|
93
|
+
try {
|
|
94
|
+
return await run()
|
|
95
|
+
} finally {
|
|
96
|
+
current = undefined
|
|
97
|
+
}
|
|
98
|
+
}
|
|
64
99
|
|
|
65
100
|
try {
|
|
66
101
|
const table = quoteIdent(options.migrationsTable)
|
|
@@ -158,7 +193,7 @@ export async function applyMigrations(options: ApplyOptions): Promise<number> {
|
|
|
158
193
|
if (from > 0) options.onResume?.(migration.tag, from + 1, migration.statements.length)
|
|
159
194
|
|
|
160
195
|
for (let i = from; i < migration.statements.length; i++) {
|
|
161
|
-
await client.unsafe(migration.statements[i]!)
|
|
196
|
+
await inStatement(migration.tag, i + 1, migration.statements.length, () => client.unsafe(migration.statements[i]!))
|
|
162
197
|
// Recorded AFTER the statement it describes: marking first would let
|
|
163
198
|
// a death between the mark and the statement skip work silently,
|
|
164
199
|
// which is worse than replaying one statement. The window that
|
|
@@ -179,7 +214,7 @@ export async function applyMigrations(options: ApplyOptions): Promise<number> {
|
|
|
179
214
|
} else {
|
|
180
215
|
await client.begin(async (tx) => {
|
|
181
216
|
for (const [i, stmt] of migration.statements.entries()) {
|
|
182
|
-
await tx.unsafe(stmt)
|
|
217
|
+
await inStatement(migration.tag, i + 1, migration.statements.length, () => tx.unsafe(stmt))
|
|
183
218
|
options.onStatement?.(migration.tag, i + 1, migration.statements.length, applied + 1, migrations.length)
|
|
184
219
|
}
|
|
185
220
|
await tx.unsafe(
|
package/src/data/migrate/run.ts
CHANGED
|
@@ -5,14 +5,17 @@ import { quoteIdentifier } from '../db/identifiers.js'
|
|
|
5
5
|
import { OWNER_LABEL_MIGRATE } from '../db/owner-labels.js'
|
|
6
6
|
import { checkMigrations, type MigrationCheckResult } from './check.js'
|
|
7
7
|
import { readAppliedState } from './applied.js'
|
|
8
|
-
import { applyMigrations } from './apply.js'
|
|
8
|
+
import { applyMigrations, type MigrationNotice } from './apply.js'
|
|
9
9
|
import { provisionFrameworkTables, type FrameworkTablesResult } from './provision-framework.js'
|
|
10
10
|
|
|
11
11
|
// Deliberately empty of hazard switches. Authorization for a hazardous
|
|
12
12
|
// migration is declared in that migration's own file (see pragma.ts) — an
|
|
13
13
|
// option here would be an invocation-level approval, which is exactly the
|
|
14
14
|
// thing that gets written into a deploy workflow once and never revisited.
|
|
15
|
-
export interface MigrateOptions {
|
|
15
|
+
export interface MigrateOptions {
|
|
16
|
+
/** Called as each notice or warning a migration statement raises arrives. Issue #970. */
|
|
17
|
+
onNotice?: (notice: MigrateNotice) => void
|
|
18
|
+
}
|
|
16
19
|
|
|
17
20
|
export interface MigrateResult {
|
|
18
21
|
database: string
|
|
@@ -21,6 +24,8 @@ export interface MigrateResult {
|
|
|
21
24
|
safetyCheck: MigrationCheckResult
|
|
22
25
|
/** No-transaction files picked up half applied and finished. Issue #378. */
|
|
23
26
|
resumed: ResumedMigration[]
|
|
27
|
+
/** Notices and warnings raised by migration statements, in arrival order. Issue #970. */
|
|
28
|
+
notices: MigrateNotice[]
|
|
24
29
|
/** Trace/audit tables, columns and day partitions this run provisioned. */
|
|
25
30
|
frameworkTables: FrameworkTablesResult
|
|
26
31
|
}
|
|
@@ -32,6 +37,13 @@ export interface ResumedMigration {
|
|
|
32
37
|
totalStatements: number
|
|
33
38
|
}
|
|
34
39
|
|
|
40
|
+
export interface MigrateNotice extends MigrationNotice {
|
|
41
|
+
tag: string
|
|
42
|
+
/** 1-based statement within the file. */
|
|
43
|
+
statement: number
|
|
44
|
+
statements: number
|
|
45
|
+
}
|
|
46
|
+
|
|
35
47
|
export class UnsafeMigrationError extends Error {
|
|
36
48
|
override readonly name = 'UnsafeMigrationError'
|
|
37
49
|
constructor(
|
|
@@ -54,7 +66,7 @@ export async function migrateAll(instance: Manifold, options: MigrateOptions = {
|
|
|
54
66
|
return results
|
|
55
67
|
}
|
|
56
68
|
|
|
57
|
-
export async function migrateOne(instance: Manifold, dbConfig: ResolvedDatabase,
|
|
69
|
+
export async function migrateOne(instance: Manifold, dbConfig: ResolvedDatabase, options: MigrateOptions = {}): Promise<MigrateResult> {
|
|
58
70
|
const conn = instance.pool.getOrCreate(dbConfig, 'owner', OWNER_LABEL_MIGRATE)
|
|
59
71
|
|
|
60
72
|
// Scope the safety gate to pending migrations only — hazards in already-applied
|
|
@@ -87,11 +99,17 @@ export async function migrateOne(instance: Manifold, dbConfig: ResolvedDatabase,
|
|
|
87
99
|
}
|
|
88
100
|
|
|
89
101
|
const resumed: ResumedMigration[] = []
|
|
102
|
+
const notices: MigrateNotice[] = []
|
|
90
103
|
const migrationsRun = await applyMigrations({
|
|
91
104
|
migrationsFolder: dbConfig.migrations!,
|
|
92
105
|
migrationsTable: dbConfig.migrationTable,
|
|
93
106
|
connectionUrl: dbConfig.url,
|
|
94
107
|
onResume: (tag, fromStatement, totalStatements) => resumed.push({ tag, fromStatement, totalStatements }),
|
|
108
|
+
onNotice: (tag, statement, statements, notice) => {
|
|
109
|
+
const full: MigrateNotice = { tag, statement, statements, ...notice }
|
|
110
|
+
notices.push(full)
|
|
111
|
+
options.onNotice?.(full)
|
|
112
|
+
},
|
|
95
113
|
})
|
|
96
114
|
|
|
97
115
|
// Trace and audit storage rides the default database; their partitioned
|
|
@@ -115,6 +133,7 @@ export async function migrateOne(instance: Manifold, dbConfig: ResolvedDatabase,
|
|
|
115
133
|
extensions: extensionsCreated,
|
|
116
134
|
safetyCheck,
|
|
117
135
|
resumed,
|
|
136
|
+
notices,
|
|
118
137
|
frameworkTables,
|
|
119
138
|
}
|
|
120
139
|
}
|