@onreza/sqlx-js 0.4.0 → 0.6.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/README.md +139 -48
- package/ROADMAP.md +1 -3
- package/dist/bin/sqlx-js-diagnostics.d.ts +2 -0
- package/dist/bin/sqlx-js-diagnostics.js +96 -0
- package/dist/bin/sqlx-js.js +337 -89
- package/dist/src/artifacts.d.ts +9 -0
- package/dist/src/artifacts.js +26 -0
- package/dist/src/cache.d.ts +17 -0
- package/dist/src/cache.js +83 -1
- package/dist/src/codegen.js +14 -2
- package/dist/src/commands/doctor.d.ts +16 -0
- package/dist/src/commands/doctor.js +196 -0
- package/dist/src/commands/init.js +93 -13
- package/dist/src/commands/migrate.d.ts +2 -101
- package/dist/src/commands/migrate.js +11 -566
- package/dist/src/commands/pgschema.d.ts +6 -0
- package/dist/src/commands/pgschema.js +30 -0
- package/dist/src/commands/prepare.d.ts +41 -6
- package/dist/src/commands/prepare.js +440 -63
- package/dist/src/commands/schema.js +1 -1
- package/dist/src/commands/watch.d.ts +1 -0
- package/dist/src/commands/watch.js +23 -9
- package/dist/src/config.d.ts +22 -0
- package/dist/src/config.js +149 -11
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.js +2 -1
- package/dist/src/migration-core.d.ts +157 -0
- package/dist/src/migration-core.js +578 -0
- package/dist/src/postgres-runtime.d.ts +3 -0
- package/dist/src/postgres-runtime.js +66 -29
- package/dist/src/runtime.d.ts +36 -3
- package/dist/src/runtime.js +92 -23
- package/dist/src/scan/scanner.d.ts +10 -3
- package/dist/src/scan/scanner.js +83 -32
- package/dist/src/type-inspection.d.ts +1 -0
- package/dist/src/type-inspection.js +20 -0
- package/dist/src/typed.d.ts +10 -0
- package/package.json +11 -6
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { watch as fsWatch } from "node:fs";
|
|
2
2
|
import { basename } from "node:path";
|
|
3
3
|
import { openSession, prepareOnce } from "./prepare.js";
|
|
4
|
+
import { configHash, loadConfig } from "../config.js";
|
|
4
5
|
const EXT_RE = /\.(ts|tsx|mts|cts|sql)$/;
|
|
5
6
|
const SKIP_DIRS = ["node_modules", ".git", ".sqlx-js", "dist", "build", ".next"];
|
|
6
7
|
const DEBOUNCE_MS = 150;
|
|
8
|
+
const CONFIG_FILES = new Set([
|
|
9
|
+
"sqlx-js.config.ts",
|
|
10
|
+
"sqlx-js.config.mts",
|
|
11
|
+
"sqlx-js.config.js",
|
|
12
|
+
"sqlx-js.config.mjs",
|
|
13
|
+
]);
|
|
14
|
+
export function shouldWatchFile(filename) {
|
|
15
|
+
const file = filename.replace(/\\/g, "/");
|
|
16
|
+
if (SKIP_DIRS.some((dir) => file === dir || file.startsWith(`${dir}/`) || file.includes(`/${dir}/`))) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const base = basename(file);
|
|
20
|
+
if (base === "sqlx-js-env.d.ts" || base === "sqlx-js.d.ts")
|
|
21
|
+
return false;
|
|
22
|
+
if (CONFIG_FILES.has(base) || /^tsconfig(?:\.[^.]+)*\.json$/.test(base))
|
|
23
|
+
return true;
|
|
24
|
+
return EXT_RE.test(file);
|
|
25
|
+
}
|
|
7
26
|
const DEFAULT_DEPS = { openSession, prepareOnce };
|
|
8
27
|
async function closeSession(session) {
|
|
9
28
|
if (!session)
|
|
@@ -15,7 +34,9 @@ async function closeSession(session) {
|
|
|
15
34
|
}
|
|
16
35
|
export async function prepareWatchedOnce(opts, state, log, err, deps = DEFAULT_DEPS) {
|
|
17
36
|
const hookResult = await opts.beforePrepare?.();
|
|
18
|
-
|
|
37
|
+
const currentConfig = await loadConfig(opts.root);
|
|
38
|
+
if (hookResult?.resetSession === true ||
|
|
39
|
+
(state.session !== null && configHash(state.session.userCfg) !== configHash(currentConfig))) {
|
|
19
40
|
await closeSession(state.session);
|
|
20
41
|
state.session = null;
|
|
21
42
|
}
|
|
@@ -70,14 +91,7 @@ export async function runWatch(opts) {
|
|
|
70
91
|
const watcher = fsWatch(opts.root, { recursive: true }, (_event, filename) => {
|
|
71
92
|
if (!filename)
|
|
72
93
|
return;
|
|
73
|
-
|
|
74
|
-
const f = raw.replace(/\\/g, "/");
|
|
75
|
-
if (SKIP_DIRS.some((d) => f === d || f.startsWith(`${d}/`) || f.includes(`/${d}/`)))
|
|
76
|
-
return;
|
|
77
|
-
const base = basename(f);
|
|
78
|
-
if (base === "sqlx-js-env.d.ts" || base === "sqlx-js.d.ts")
|
|
79
|
-
return;
|
|
80
|
-
if (!EXT_RE.test(f))
|
|
94
|
+
if (!shouldWatchFile(filename.toString()))
|
|
81
95
|
return;
|
|
82
96
|
trigger();
|
|
83
97
|
});
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
export type ScanConfig = {
|
|
2
|
+
include?: string[];
|
|
3
|
+
exclude?: string[];
|
|
4
|
+
modules?: string[];
|
|
5
|
+
};
|
|
1
6
|
export type SqlxJsConfig = {
|
|
2
7
|
jsonbTypes?: Record<string, string>;
|
|
3
8
|
customTypes?: Record<string, string>;
|
|
9
|
+
scan?: ScanConfig;
|
|
4
10
|
schema?: {
|
|
5
11
|
provider?: "builtin" | "pgschema";
|
|
6
12
|
file?: string;
|
|
@@ -8,5 +14,21 @@ export type SqlxJsConfig = {
|
|
|
8
14
|
command?: string;
|
|
9
15
|
};
|
|
10
16
|
};
|
|
17
|
+
export declare function defineConfig<T extends SqlxJsConfig>(config: T): T;
|
|
18
|
+
export declare function loadRootEnv(root: string): string | undefined;
|
|
19
|
+
export declare function configPath(root: string): string | undefined;
|
|
11
20
|
export declare function loadConfig(root: string): Promise<SqlxJsConfig>;
|
|
21
|
+
export declare function prepareConfigHash(cfg: SqlxJsConfig): string;
|
|
22
|
+
export declare function configHash(cfg: SqlxJsConfig): string;
|
|
23
|
+
export declare function loadConfigInfo(root: string): Promise<{
|
|
24
|
+
config: SqlxJsConfig;
|
|
25
|
+
path?: string;
|
|
26
|
+
}>;
|
|
27
|
+
export declare function assertSupportedRuntime(): void;
|
|
28
|
+
export declare function runtimeVersion(): {
|
|
29
|
+
runtime: "node" | "bun";
|
|
30
|
+
version: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function nativeTypeScriptEnabled(): boolean | string;
|
|
33
|
+
export declare function envFilePath(root: string): string;
|
|
12
34
|
export declare function lookupJsonbType(cfg: SqlxJsConfig, schema: string, table: string, column: string): string | undefined;
|
package/dist/src/config.js
CHANGED
|
@@ -1,18 +1,156 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
3
|
import { join } from "node:path";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { parseEnv } from "node:util";
|
|
6
|
+
export function defineConfig(config) {
|
|
7
|
+
return config;
|
|
8
|
+
}
|
|
9
|
+
export function loadRootEnv(root) {
|
|
10
|
+
const path = join(root, ".env");
|
|
11
|
+
if (!existsSync(path))
|
|
12
|
+
return undefined;
|
|
13
|
+
const parsed = parseEnv(readFileSync(path, "utf8"));
|
|
14
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
15
|
+
if (process.env[key] === undefined)
|
|
16
|
+
process.env[key] = value;
|
|
17
|
+
}
|
|
18
|
+
return path;
|
|
19
|
+
}
|
|
20
|
+
export function configPath(root) {
|
|
21
|
+
for (const name of ["sqlx-js.config.mts", "sqlx-js.config.ts", "sqlx-js.config.mjs", "sqlx-js.config.js"]) {
|
|
5
22
|
const p = join(root, name);
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
if (existsSync(p))
|
|
24
|
+
return p;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
export async function loadConfig(root) {
|
|
29
|
+
const path = configPath(root);
|
|
30
|
+
if (!path)
|
|
31
|
+
return {};
|
|
32
|
+
const url = pathToFileURL(path);
|
|
33
|
+
url.searchParams.set("mtime", String(statSync(path).mtimeMs));
|
|
34
|
+
const mod = await import(url.href);
|
|
35
|
+
if (!("default" in mod)) {
|
|
36
|
+
throw new Error(`sqlx-js: ${path} must default-export a config object`);
|
|
37
|
+
}
|
|
38
|
+
return validateConfig(mod.default, path);
|
|
39
|
+
}
|
|
40
|
+
function validateStringRecord(value, name, path) {
|
|
41
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
42
|
+
throw new Error(`sqlx-js: ${path} ${name} must be an object of string values`);
|
|
43
|
+
}
|
|
44
|
+
for (const [key, item] of Object.entries(value)) {
|
|
45
|
+
if (typeof item !== "string") {
|
|
46
|
+
throw new Error(`sqlx-js: ${path} ${name}.${key} must be a string`);
|
|
12
47
|
}
|
|
13
|
-
return cfg;
|
|
14
48
|
}
|
|
15
|
-
|
|
49
|
+
}
|
|
50
|
+
function validateStringArray(value, name, path) {
|
|
51
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
52
|
+
throw new Error(`sqlx-js: ${path} ${name} must be an array of strings`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function validateModuleArray(value, path) {
|
|
56
|
+
validateStringArray(value, "scan.modules", path);
|
|
57
|
+
if (value.length === 0 || value.some((item) => item.trim() === "")) {
|
|
58
|
+
throw new Error(`sqlx-js: ${path} scan.modules must contain at least one non-empty module name`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function validateConfig(value, path) {
|
|
62
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
63
|
+
throw new Error(`sqlx-js: ${path} must default-export a config object`);
|
|
64
|
+
}
|
|
65
|
+
const config = value;
|
|
66
|
+
if (config.jsonbTypes !== undefined)
|
|
67
|
+
validateStringRecord(config.jsonbTypes, "jsonbTypes", path);
|
|
68
|
+
if (config.customTypes !== undefined)
|
|
69
|
+
validateStringRecord(config.customTypes, "customTypes", path);
|
|
70
|
+
if (config.scan !== undefined) {
|
|
71
|
+
if (!config.scan || typeof config.scan !== "object" || Array.isArray(config.scan)) {
|
|
72
|
+
throw new Error(`sqlx-js: ${path} scan must be an object`);
|
|
73
|
+
}
|
|
74
|
+
const scan = config.scan;
|
|
75
|
+
if (scan.include !== undefined)
|
|
76
|
+
validateStringArray(scan.include, "scan.include", path);
|
|
77
|
+
if (scan.exclude !== undefined)
|
|
78
|
+
validateStringArray(scan.exclude, "scan.exclude", path);
|
|
79
|
+
if (scan.modules !== undefined)
|
|
80
|
+
validateModuleArray(scan.modules, path);
|
|
81
|
+
}
|
|
82
|
+
if (config.schema !== undefined) {
|
|
83
|
+
if (!config.schema || typeof config.schema !== "object" || Array.isArray(config.schema)) {
|
|
84
|
+
throw new Error(`sqlx-js: ${path} schema must be an object`);
|
|
85
|
+
}
|
|
86
|
+
const schema = config.schema;
|
|
87
|
+
if (schema.provider !== undefined && schema.provider !== "builtin" && schema.provider !== "pgschema") {
|
|
88
|
+
throw new Error(`sqlx-js: ${path} schema.provider must be builtin or pgschema`);
|
|
89
|
+
}
|
|
90
|
+
for (const key of ["file", "command"]) {
|
|
91
|
+
if (schema[key] !== undefined && typeof schema[key] !== "string") {
|
|
92
|
+
throw new Error(`sqlx-js: ${path} schema.${key} must be a string`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (schema.schemas !== undefined)
|
|
96
|
+
validateStringArray(schema.schemas, "schema.schemas", path);
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
export function prepareConfigHash(cfg) {
|
|
101
|
+
const value = stableValue({
|
|
102
|
+
jsonbTypes: cfg.jsonbTypes ?? {},
|
|
103
|
+
customTypes: cfg.customTypes ?? {},
|
|
104
|
+
});
|
|
105
|
+
return createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 16);
|
|
106
|
+
}
|
|
107
|
+
export function configHash(cfg) {
|
|
108
|
+
return createHash("sha256").update(JSON.stringify(stableValue(cfg))).digest("hex").slice(0, 16);
|
|
109
|
+
}
|
|
110
|
+
function stableValue(value) {
|
|
111
|
+
if (Array.isArray(value))
|
|
112
|
+
return value.map(stableValue);
|
|
113
|
+
if (!value || typeof value !== "object")
|
|
114
|
+
return value;
|
|
115
|
+
return Object.fromEntries(Object.entries(value)
|
|
116
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
117
|
+
.map(([key, item]) => [key, stableValue(item)]));
|
|
118
|
+
}
|
|
119
|
+
export async function loadConfigInfo(root) {
|
|
120
|
+
const path = configPath(root);
|
|
121
|
+
if (!path)
|
|
122
|
+
return { config: {} };
|
|
123
|
+
return { config: await loadConfig(root), path };
|
|
124
|
+
}
|
|
125
|
+
export function assertSupportedRuntime() {
|
|
126
|
+
const bun = process.versions.bun;
|
|
127
|
+
if (bun) {
|
|
128
|
+
if (majorMinorLessThan(bun, 1, 3)) {
|
|
129
|
+
throw new Error(`sqlx-js requires Bun >=1.3, current ${bun}`);
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const node = process.versions.node;
|
|
134
|
+
if (majorMinorLessThan(node, 24, 0)) {
|
|
135
|
+
throw new Error(`sqlx-js requires Node.js >=24, current ${node}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function majorMinorLessThan(version, minMajor, minMinor) {
|
|
139
|
+
const [major = 0, minor = 0] = version.split(".").map(Number);
|
|
140
|
+
return major < minMajor || (major === minMajor && minor < minMinor);
|
|
141
|
+
}
|
|
142
|
+
export function runtimeVersion() {
|
|
143
|
+
if (process.versions.bun)
|
|
144
|
+
return { runtime: "bun", version: process.versions.bun };
|
|
145
|
+
return { runtime: "node", version: process.versions.node };
|
|
146
|
+
}
|
|
147
|
+
export function nativeTypeScriptEnabled() {
|
|
148
|
+
if (process.versions.bun)
|
|
149
|
+
return true;
|
|
150
|
+
return process.features.typescript;
|
|
151
|
+
}
|
|
152
|
+
export function envFilePath(root) {
|
|
153
|
+
return join(root, ".env");
|
|
16
154
|
}
|
|
17
155
|
export function lookupJsonbType(cfg, schema, table, column) {
|
|
18
156
|
const types = cfg.jsonbTypes;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -18,11 +18,13 @@ export type JsonInputObject = {
|
|
|
18
18
|
readonly [key: string]: JsonInputValue | undefined;
|
|
19
19
|
};
|
|
20
20
|
export type JsonInputArray = readonly JsonInputValue[];
|
|
21
|
-
export
|
|
21
|
+
export { defineConfig } from "./config.js";
|
|
22
|
+
export type { ScanConfig, SqlxJsConfig } from "./config.js";
|
|
22
23
|
export type { SslMode, ConnConfig } from "./pg/wire.js";
|
|
23
24
|
export { PgError, ConnectionLostError } from "./pg/wire.js";
|
|
24
25
|
export { NoRowsError, TooManyRowsError } from "./runtime.js";
|
|
25
26
|
export type { TransactionOptions, MigrateOptions, OnQueryEvent, OnQueryHook } from "./runtime.js";
|
|
27
|
+
export type { ExecuteResult, JsonParameter, PgArrayParameter } from "./runtime.js";
|
|
26
28
|
export type { PostgresClient, PostgresOptions, CreateClientOptions } from "./postgres-runtime.js";
|
|
27
29
|
export type TypedFile = TypedFileFor<KnownFileQueries>;
|
|
28
30
|
export type TypedSql = TypedSqlFor<KnownQueries, KnownFileQueries>;
|
|
@@ -34,4 +36,4 @@ export declare const getClient: typeof rt.getClient;
|
|
|
34
36
|
export declare const setClient: typeof rt.setClient;
|
|
35
37
|
export declare const createClient: typeof rt.createClient;
|
|
36
38
|
export declare const close: typeof rt.close;
|
|
37
|
-
export { migrate, clearSqlFileCache, encodePgArrayLiteral, id } from "./runtime.js";
|
|
39
|
+
export { migrate, clearSqlFileCache, encodePgArrayLiteral, id, json, array } from "./runtime.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as rt from "./postgres-runtime.js";
|
|
2
|
+
export { defineConfig } from "./config.js";
|
|
2
3
|
export { PgError, ConnectionLostError } from "./pg/wire.js";
|
|
3
4
|
export { NoRowsError, TooManyRowsError } from "./runtime.js";
|
|
4
5
|
export const sql = rt.sql;
|
|
@@ -7,4 +8,4 @@ export const getClient = rt.getClient;
|
|
|
7
8
|
export const setClient = rt.setClient;
|
|
8
9
|
export const createClient = rt.createClient;
|
|
9
10
|
export const close = rt.close;
|
|
10
|
-
export { migrate, clearSqlFileCache, encodePgArrayLiteral, id } from "./runtime.js";
|
|
11
|
+
export { migrate, clearSqlFileCache, encodePgArrayLiteral, id, json, array } from "./runtime.js";
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { PgClient } from "./pg/wire.js";
|
|
2
|
+
export type MigrationFile = {
|
|
3
|
+
version: number;
|
|
4
|
+
name: string;
|
|
5
|
+
upPath: string;
|
|
6
|
+
downPath: string | null;
|
|
7
|
+
upSql: string;
|
|
8
|
+
upHash: string;
|
|
9
|
+
squash: SquashMetadata | null;
|
|
10
|
+
};
|
|
11
|
+
export type SquashReplacement = {
|
|
12
|
+
version: number;
|
|
13
|
+
name: string;
|
|
14
|
+
upHash: string;
|
|
15
|
+
};
|
|
16
|
+
export type SquashMetadata = {
|
|
17
|
+
format: 1;
|
|
18
|
+
replaces: SquashReplacement[];
|
|
19
|
+
};
|
|
20
|
+
export type MigrationStore = {
|
|
21
|
+
table: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const SQUASH_PREFIX = "-- sqlx-js-squash:";
|
|
24
|
+
export declare const DEFAULT_MIGRATE_LOCK_KEY = 18750938867203960n;
|
|
25
|
+
export declare function readMigrations(dir: string): MigrationFile[];
|
|
26
|
+
export declare function parseSquashMetadata(sql: string): SquashMetadata | null;
|
|
27
|
+
export declare function ensureTable(client: PgClient): Promise<MigrationStore>;
|
|
28
|
+
export declare function listApplied(client: PgClient, store?: MigrationStore): Promise<Map<number, {
|
|
29
|
+
name: string;
|
|
30
|
+
hash: string;
|
|
31
|
+
}>>;
|
|
32
|
+
export type ApplyOutcome = {
|
|
33
|
+
kind: "applied";
|
|
34
|
+
version: number;
|
|
35
|
+
name: string;
|
|
36
|
+
} | {
|
|
37
|
+
kind: "adopted";
|
|
38
|
+
version: number;
|
|
39
|
+
name: string;
|
|
40
|
+
replaced: number;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "tampered";
|
|
43
|
+
version: number;
|
|
44
|
+
name: string;
|
|
45
|
+
applied: string;
|
|
46
|
+
current: string;
|
|
47
|
+
} | {
|
|
48
|
+
kind: "failed";
|
|
49
|
+
version: number;
|
|
50
|
+
name: string;
|
|
51
|
+
error: string;
|
|
52
|
+
};
|
|
53
|
+
export type PlanOutcome = {
|
|
54
|
+
kind: "pending";
|
|
55
|
+
version: number;
|
|
56
|
+
name: string;
|
|
57
|
+
} | {
|
|
58
|
+
kind: "adoptable";
|
|
59
|
+
version: number;
|
|
60
|
+
name: string;
|
|
61
|
+
replaced: number;
|
|
62
|
+
} | {
|
|
63
|
+
kind: "tampered";
|
|
64
|
+
version: number;
|
|
65
|
+
name: string;
|
|
66
|
+
applied: string;
|
|
67
|
+
current: string;
|
|
68
|
+
} | {
|
|
69
|
+
kind: "failed";
|
|
70
|
+
version: number;
|
|
71
|
+
name: string;
|
|
72
|
+
error: string;
|
|
73
|
+
};
|
|
74
|
+
export type MigrationPlanItem = {
|
|
75
|
+
kind: "apply";
|
|
76
|
+
version: number;
|
|
77
|
+
name: string;
|
|
78
|
+
} | {
|
|
79
|
+
kind: "adopt";
|
|
80
|
+
version: number;
|
|
81
|
+
name: string;
|
|
82
|
+
replaced: number;
|
|
83
|
+
};
|
|
84
|
+
export type MigrationPlanDiagnostic = Extract<PlanOutcome, {
|
|
85
|
+
kind: "tampered" | "failed";
|
|
86
|
+
}>;
|
|
87
|
+
export type MigrationPlanSnapshot = {
|
|
88
|
+
ok: boolean;
|
|
89
|
+
pending: number;
|
|
90
|
+
adoptable: number;
|
|
91
|
+
tampered: number;
|
|
92
|
+
failed: number;
|
|
93
|
+
steps: MigrationPlanItem[];
|
|
94
|
+
diagnostics: MigrationPlanDiagnostic[];
|
|
95
|
+
};
|
|
96
|
+
export type MigrationInfoStatus = "applied" | "pending" | "adoptable" | "superseded" | "tampered" | "failed";
|
|
97
|
+
export type MigrationInfoItem = {
|
|
98
|
+
version: number;
|
|
99
|
+
name: string;
|
|
100
|
+
status: MigrationInfoStatus;
|
|
101
|
+
detail?: string;
|
|
102
|
+
};
|
|
103
|
+
export type MigrationInfoSnapshot = {
|
|
104
|
+
historyTable: string | null;
|
|
105
|
+
summary: Record<MigrationInfoStatus, number>;
|
|
106
|
+
items: MigrationInfoItem[];
|
|
107
|
+
};
|
|
108
|
+
type InternalMigrationPlanItem = {
|
|
109
|
+
kind: "apply";
|
|
110
|
+
migration: MigrationFile;
|
|
111
|
+
} | {
|
|
112
|
+
kind: "adopt";
|
|
113
|
+
migration: MigrationFile;
|
|
114
|
+
replaced: number;
|
|
115
|
+
};
|
|
116
|
+
export type MigrationValidationOutcome = {
|
|
117
|
+
kind: "tampered";
|
|
118
|
+
version: number;
|
|
119
|
+
name: string;
|
|
120
|
+
applied: string;
|
|
121
|
+
current: string;
|
|
122
|
+
} | {
|
|
123
|
+
kind: "failed";
|
|
124
|
+
version: number;
|
|
125
|
+
name: string;
|
|
126
|
+
error: string;
|
|
127
|
+
};
|
|
128
|
+
export declare function effectiveSquashReplacements(all: MigrationFile[]): SquashReplacement[];
|
|
129
|
+
export declare function buildMigrationPlan(all: MigrationFile[], applied: Map<number, {
|
|
130
|
+
name: string;
|
|
131
|
+
hash: string;
|
|
132
|
+
}>, onEvent?: (event: MigrationValidationOutcome) => void): {
|
|
133
|
+
kind: "ok";
|
|
134
|
+
steps: InternalMigrationPlanItem[];
|
|
135
|
+
} | {
|
|
136
|
+
kind: "failed";
|
|
137
|
+
} | {
|
|
138
|
+
kind: "tampered";
|
|
139
|
+
};
|
|
140
|
+
export declare function resetMigrationSession(client: PgClient): Promise<void>;
|
|
141
|
+
export declare function planPending(client: PgClient, migrationsDir: string, onEvent?: (event: PlanOutcome) => void): Promise<{
|
|
142
|
+
pending: number;
|
|
143
|
+
adoptable: number;
|
|
144
|
+
tampered: number;
|
|
145
|
+
failed: number;
|
|
146
|
+
steps: MigrationPlanItem[];
|
|
147
|
+
}>;
|
|
148
|
+
export declare function inspectMigrationPlan(client: PgClient, migrationsDir: string): Promise<MigrationPlanSnapshot>;
|
|
149
|
+
export declare function inspectMigrations(client: PgClient, migrationsDir: string): Promise<MigrationInfoSnapshot>;
|
|
150
|
+
export declare function applyPending(client: PgClient, migrationsDir: string, onEvent?: (event: ApplyOutcome) => void): Promise<{
|
|
151
|
+
applied: number;
|
|
152
|
+
tampered: number;
|
|
153
|
+
failed: number;
|
|
154
|
+
}>;
|
|
155
|
+
export declare function acquireMigrateLock(client: PgClient, lockKey?: number | bigint, timeoutMs?: number): Promise<void>;
|
|
156
|
+
export declare function releaseMigrateLock(client: PgClient, lockKey?: number | bigint): Promise<void>;
|
|
157
|
+
export {};
|