@happyvertical/smrt-core 0.47.1 → 0.48.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/AGENTS.md +1 -0
- package/agents/generators.md +12 -0
- package/agents/registry-snapshot.md +28 -0
- package/agents/schema-paths.md +57 -0
- package/agents/system-diagnostics.md +6 -1
- package/dist/browser.js +3 -2
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +3 -1
- package/dist/collection.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/manifest/static-manifest.js +1 -1
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.js +1 -1
- package/dist/manifest.json +1 -1
- package/dist/migrations/differ.d.ts +88 -4
- package/dist/migrations/differ.d.ts.map +1 -1
- package/dist/migrations/differ.js +363 -5
- package/dist/migrations/differ.js.map +1 -1
- package/dist/migrations/generator.d.ts.map +1 -1
- package/dist/migrations/generator.js +2 -1
- package/dist/migrations/generator.js.map +1 -1
- package/dist/prebuild/index.d.ts.map +1 -1
- package/dist/prebuild/index.js +4 -3
- package/dist/prebuild/index.js.map +1 -1
- package/dist/registry/class-registration.d.ts.map +1 -1
- package/dist/registry/class-registration.js +3 -1
- package/dist/registry/class-registration.js.map +1 -1
- package/dist/registry/schema-builder.js +1 -1
- package/dist/registry.js +1 -1
- package/dist/scanner/manifest-generator.d.ts.map +1 -1
- package/dist/scanner/manifest-generator.js +22 -1
- package/dist/scanner/manifest-generator.js.map +1 -1
- package/dist/schema/foreign-key-ddl.d.ts +26 -0
- package/dist/schema/foreign-key-ddl.d.ts.map +1 -1
- package/dist/schema/foreign-key-ddl.js +26 -2
- package/dist/schema/foreign-key-ddl.js.map +1 -1
- package/dist/schema/foreign-key-orphan-report.d.ts +57 -0
- package/dist/schema/foreign-key-orphan-report.d.ts.map +1 -0
- package/dist/schema/foreign-key-orphan-report.js +159 -0
- package/dist/schema/foreign-key-orphan-report.js.map +1 -0
- package/dist/schema/index.d.ts +2 -1
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +3 -2
- package/dist/schema/live-parity.d.ts +8 -1
- package/dist/schema/live-parity.d.ts.map +1 -1
- package/dist/schema/live-parity.js +172 -2
- package/dist/schema/live-parity.js.map +1 -1
- package/dist/schema/text-cast-probe.d.ts +66 -0
- package/dist/schema/text-cast-probe.d.ts.map +1 -0
- package/dist/schema/text-cast-probe.js +142 -0
- package/dist/schema/text-cast-probe.js.map +1 -0
- package/dist/schema/types.d.ts +39 -1
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema.js +3 -2
- package/dist/smrt-knowledge.json +17 -11
- package/dist/system/diagnostics.d.ts +22 -0
- package/dist/system/diagnostics.d.ts.map +1 -1
- package/dist/system/diagnostics.js +88 -31
- package/dist/system/diagnostics.js.map +1 -1
- package/dist/system/index.d.ts +1 -0
- package/dist/system/index.d.ts.map +1 -1
- package/dist/system/index.js +2 -1
- package/dist/system/registry-snapshot.d.ts +112 -0
- package/dist/system/registry-snapshot.d.ts.map +1 -0
- package/dist/system/registry-snapshot.js +171 -0
- package/dist/system/registry-snapshot.js.map +1 -0
- package/dist/testing/database.d.ts.map +1 -1
- package/dist/testing/database.js +10 -2
- package/dist/testing/database.js.map +1 -1
- package/dist/vite-plugin/dev-plane-route.d.ts +5 -0
- package/dist/vite-plugin/dev-plane-route.d.ts.map +1 -0
- package/dist/vite-plugin/dev-plane-route.js +91 -0
- package/dist/vite-plugin/dev-plane-route.js.map +1 -0
- package/dist/vite-plugin/index.d.ts.map +1 -1
- package/dist/vite-plugin/index.js +4 -3
- package/dist/vite-plugin/index.js.map +1 -1
- package/dist/vite-plugin/sveltekit-generator.d.ts +8 -0
- package/dist/vite-plugin/sveltekit-generator.d.ts.map +1 -1
- package/dist/vite-plugin/sveltekit-generator.js +2 -0
- package/dist/vite-plugin/sveltekit-generator.js.map +1 -1
- package/dist/vite-plugin/web-collections.d.ts +6 -0
- package/dist/vite-plugin/web-collections.d.ts.map +1 -1
- package/dist/vite-plugin/web-collections.js +9 -4
- package/dist/vite-plugin/web-collections.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { formatDefaultValue, quoteIdentifier } from "./sql-identifiers.js";
|
|
2
|
+
//#region src/schema/text-cast-probe.ts
|
|
3
|
+
/**
|
|
4
|
+
* Mask a probed sample value for display in a diagnostic message: keep just
|
|
5
|
+
* enough of the value to recognize it without echoing a full record verbatim
|
|
6
|
+
* into logs/CI output (`created_at`/`_meta_data` values are user data).
|
|
7
|
+
*/
|
|
8
|
+
function maskSampleValue(value) {
|
|
9
|
+
if (value.length === 0) return "(empty)";
|
|
10
|
+
if (value.length <= 6) return `${"•".repeat(value.length)} (length ${value.length})`;
|
|
11
|
+
return `${value.slice(0, 3)}…${value.slice(-3)} (length ${value.length})`;
|
|
12
|
+
}
|
|
13
|
+
/** Session-scoped helper function name; `pg_temp` keeps it off the real schema. */
|
|
14
|
+
var PROBE_FUNCTION = "pg_temp.smrt_probe_cast_ok";
|
|
15
|
+
/**
|
|
16
|
+
* PostgreSQL's "special" date/time input values (see the "Special Values"
|
|
17
|
+
* table in the PostgreSQL docs). Every one of these parses successfully to
|
|
18
|
+
* `timestamptz` — `probeCastSafety`'s real-cast test alone would call a text
|
|
19
|
+
* column literally holding the string `now` or `infinity` "clean" — but
|
|
20
|
+
* casting them evaluates to the *migration's* execution time or an infinite
|
|
21
|
+
* sentinel, silently destroying the original value with no error and no
|
|
22
|
+
* advisory. They must never be treated as safe, regardless of what a bare
|
|
23
|
+
* cast attempt reports.
|
|
24
|
+
*/
|
|
25
|
+
var TIMESTAMPTZ_SPECIAL_VALUES = /* @__PURE__ */ new Set([
|
|
26
|
+
"epoch",
|
|
27
|
+
"infinity",
|
|
28
|
+
"-infinity",
|
|
29
|
+
"now",
|
|
30
|
+
"today",
|
|
31
|
+
"tomorrow",
|
|
32
|
+
"yesterday",
|
|
33
|
+
"allballs"
|
|
34
|
+
]);
|
|
35
|
+
/**
|
|
36
|
+
* A `timestamptz` cast is only safe to apply unattended when the source text
|
|
37
|
+
* already carries an explicit UTC offset (`Z` or `+HH[:MM]`/`-HH[:MM]`) —
|
|
38
|
+
* without one, PostgreSQL interprets the value under the *migrating
|
|
39
|
+
* session's* `TimeZone` setting, so the exact same text can cast to a
|
|
40
|
+
* different instant on a different run/server. That ambiguity is exactly
|
|
41
|
+
* what `--legacy-timezone=UTC` exists to resolve explicitly; the probe must
|
|
42
|
+
* fail closed (not silently guess UTC) so naive values route to that opt-in
|
|
43
|
+
* path instead of being auto-converged.
|
|
44
|
+
*/
|
|
45
|
+
var TIMESTAMPTZ_EXPLICIT_OFFSET_SQL_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}([ T][0-9]{2}:[0-9]{2}(:[0-9]{2}(\\.[0-9]+)?)?)?[[:space:]]*(Z|[+-][0-9]{2}(:?[0-9]{2})?)$";
|
|
46
|
+
/**
|
|
47
|
+
* `target` is one of this module's own literal type names — never data —
|
|
48
|
+
* so building the DDL by interpolation is safe; there is no column, table,
|
|
49
|
+
* or row value in this string.
|
|
50
|
+
*/
|
|
51
|
+
function renderCreateProbeFunctionSql() {
|
|
52
|
+
return `CREATE OR REPLACE FUNCTION ${PROBE_FUNCTION}(value text, target_type text) RETURNS boolean LANGUAGE plpgsql AS \$\$ BEGIN IF value IS NULL THEN RETURN true; END IF; IF target_type = 'timestamptz' THEN IF lower(trim(value)) = ANY (ARRAY[${[...TIMESTAMPTZ_SPECIAL_VALUES].map((value) => `'${value}'`).join(",")}]) THEN RETURN false; END IF; IF trim(value) !~* '${TIMESTAMPTZ_EXPLICIT_OFFSET_SQL_PATTERN}' THEN RETURN false; END IF; END IF; EXECUTE format('SELECT %L::%s', value, target_type); RETURN true; EXCEPTION WHEN OTHERS THEN RETURN false; END; \$\$`;
|
|
53
|
+
}
|
|
54
|
+
function renderProbeQuerySql(tableName, columnName, targetType) {
|
|
55
|
+
const column = quoteIdentifier(columnName);
|
|
56
|
+
const table = quoteIdentifier(tableName);
|
|
57
|
+
const isValid = `${PROBE_FUNCTION}(${column}::text, '${targetType}')`;
|
|
58
|
+
return `SELECT count(*) AS invalid_count, min(CASE WHEN NOT ${isValid} THEN ${column}::text END) AS sample_value FROM ${table} WHERE ${column} IS NOT NULL AND NOT ${isValid}`;
|
|
59
|
+
}
|
|
60
|
+
function classifyProbeRows(rows) {
|
|
61
|
+
const count = Number(rows[0]?.invalid_count);
|
|
62
|
+
if (!Number.isFinite(count)) return {
|
|
63
|
+
status: "unavailable",
|
|
64
|
+
reason: "probe returned a non-numeric count"
|
|
65
|
+
};
|
|
66
|
+
if (count === 0) return { status: "clean" };
|
|
67
|
+
const sample = rows[0]?.sample_value;
|
|
68
|
+
return {
|
|
69
|
+
status: "dirty",
|
|
70
|
+
count,
|
|
71
|
+
...typeof sample === "string" ? { sample } : {}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Probe every non-null value of a candidate `text` column for whether it can
|
|
76
|
+
* cast losslessly to `timestamptz` or `jsonb`, using a real, exception-safe
|
|
77
|
+
* cast attempt (not a shape heuristic) so an invalid-calendar timestamp or a
|
|
78
|
+
* structurally-malformed-but-bracket-balanced JSON document is caught the
|
|
79
|
+
* same as an obviously wrong value. Any failure to run the probe (adapter
|
|
80
|
+
* without transaction support, a missing table mid-run, a test double
|
|
81
|
+
* without a realistic response) resolves to `unavailable` — callers must not
|
|
82
|
+
* treat that as "clean"; SMRT never coerces or discards data on an unproven
|
|
83
|
+
* assumption.
|
|
84
|
+
*/
|
|
85
|
+
async function probeCastSafety(db, tableName, columnName, targetType) {
|
|
86
|
+
if (!db.transaction) return {
|
|
87
|
+
status: "unavailable",
|
|
88
|
+
reason: "adapter does not support transactions"
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
return await db.transaction(async (tx) => {
|
|
92
|
+
await tx.query(renderCreateProbeFunctionSql());
|
|
93
|
+
const result = await tx.query(renderProbeQuerySql(tableName, columnName, targetType));
|
|
94
|
+
return classifyProbeRows(Array.isArray(result) ? result : result?.rows ?? []);
|
|
95
|
+
});
|
|
96
|
+
} catch (error) {
|
|
97
|
+
return {
|
|
98
|
+
status: "unavailable",
|
|
99
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Render the one-time PostgreSQL conversion of a legacy `text` column to
|
|
105
|
+
* native `timestamptz`, once {@link probeCastSafety} has confirmed every
|
|
106
|
+
* non-null value casts safely.
|
|
107
|
+
*/
|
|
108
|
+
function renderTimestamptzColumnConversion(tableName, columnName, options = {}) {
|
|
109
|
+
const table = quoteIdentifier(tableName);
|
|
110
|
+
const column = quoteIdentifier(columnName);
|
|
111
|
+
const hasManifestDefault = options.manifestDefaultValue !== void 0;
|
|
112
|
+
const statements = [];
|
|
113
|
+
if (options.hasLiveDefault || hasManifestDefault) statements.push(`ALTER TABLE ${table} ALTER COLUMN ${column} DROP DEFAULT`);
|
|
114
|
+
statements.push(`ALTER TABLE ${table} ALTER COLUMN ${column} TYPE timestamptz USING ${column}::timestamptz`);
|
|
115
|
+
if (hasManifestDefault) {
|
|
116
|
+
const formattedDefault = formatDefaultValue(options.manifestDefaultValue, "TIMESTAMP");
|
|
117
|
+
statements.push(`ALTER TABLE ${table} ALTER COLUMN ${column} SET DEFAULT ${formattedDefault}`);
|
|
118
|
+
}
|
|
119
|
+
return statements;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Render the one-time PostgreSQL conversion of a legacy `text` column to
|
|
123
|
+
* native `jsonb`, once {@link probeCastSafety} has confirmed every non-null
|
|
124
|
+
* value casts safely.
|
|
125
|
+
*/
|
|
126
|
+
function renderJsonbColumnConversion(tableName, columnName, options = {}) {
|
|
127
|
+
const table = quoteIdentifier(tableName);
|
|
128
|
+
const column = quoteIdentifier(columnName);
|
|
129
|
+
const hasManifestDefault = options.manifestDefaultValue !== void 0;
|
|
130
|
+
const statements = [];
|
|
131
|
+
if (options.hasLiveDefault || hasManifestDefault) statements.push(`ALTER TABLE ${table} ALTER COLUMN ${column} DROP DEFAULT`);
|
|
132
|
+
statements.push(`ALTER TABLE ${table} ALTER COLUMN ${column} TYPE jsonb USING ${column}::jsonb`);
|
|
133
|
+
if (hasManifestDefault) {
|
|
134
|
+
const formattedDefault = formatDefaultValue(options.manifestDefaultValue, "JSON");
|
|
135
|
+
statements.push(`ALTER TABLE ${table} ALTER COLUMN ${column} SET DEFAULT ${formattedDefault}::jsonb`);
|
|
136
|
+
}
|
|
137
|
+
return statements;
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { maskSampleValue, probeCastSafety, renderJsonbColumnConversion, renderTimestamptzColumnConversion };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=text-cast-probe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-cast-probe.js","names":[],"sources":["../../src/schema/text-cast-probe.ts"],"sourcesContent":["/**\n * Shared \"probe, then cast\" helpers for text-column type convergence (#2771,\n * #2772).\n *\n * Two drift shapes on a table SMRT itself creates share one problem: a live\n * `text` column holds values that would parse losslessly into the manifest's\n * declared PostgreSQL type (`timestamptz` or `jsonb`), but the differ cannot\n * know that without looking at the data. `probeCastSafety()` answers that with\n * a genuine, exception-safe cast attempt — not a shape heuristic — over every\n * non-null value, and returns one sample so a fail-closed diagnostic can name\n * the offending value without dumping the whole column into JS.\n *\n * PostgreSQL has no `TRY_CAST`/safe-cast builtin before 17 (`pg_input_is_valid`),\n * and this fleet targets 16 (see `.github/workflows/postgres-tests.yml`), so a\n * real per-row safe cast needs PL/pgSQL's exception handling. That handler is\n * created as a session-scoped (`pg_temp`) function, which is why the create\n * statement and the probe query run inside one `db.transaction()` — the two\n * must land on the same physical connection, and a pooled adapter only\n * guarantees that within one transaction. `target_type` is never derived from\n * column data (always the literal `'jsonb'`/`'timestamptz'` this module\n * passes), so the dynamic `EXECUTE format(...)` it builds cannot be steered by\n * a row value; `%L` quotes the probed value as a literal.\n */\n\nimport type { DatabaseInterface } from '@happyvertical/sql';\nimport { formatDefaultValue, quoteIdentifier } from './sql-identifiers.js';\n\n/** Outcome of a server-side cast-safety probe over one column's non-null values. */\nexport type ShapeProbeResult =\n | { status: 'clean' }\n | { status: 'dirty'; count: number; sample?: string }\n | { status: 'unavailable'; reason: string };\n\n/**\n * Mask a probed sample value for display in a diagnostic message: keep just\n * enough of the value to recognize it without echoing a full record verbatim\n * into logs/CI output (`created_at`/`_meta_data` values are user data).\n */\nexport function maskSampleValue(value: string): string {\n if (value.length === 0) return '(empty)';\n if (value.length <= 6)\n return `${'•'.repeat(value.length)} (length ${value.length})`;\n return `${value.slice(0, 3)}…${value.slice(-3)} (length ${value.length})`;\n}\n\n/** Session-scoped helper function name; `pg_temp` keeps it off the real schema. */\nconst PROBE_FUNCTION = 'pg_temp.smrt_probe_cast_ok';\n\n/**\n * PostgreSQL's \"special\" date/time input values (see the \"Special Values\"\n * table in the PostgreSQL docs). Every one of these parses successfully to\n * `timestamptz` — `probeCastSafety`'s real-cast test alone would call a text\n * column literally holding the string `now` or `infinity` \"clean\" — but\n * casting them evaluates to the *migration's* execution time or an infinite\n * sentinel, silently destroying the original value with no error and no\n * advisory. They must never be treated as safe, regardless of what a bare\n * cast attempt reports.\n */\nconst TIMESTAMPTZ_SPECIAL_VALUES = new Set([\n 'epoch',\n 'infinity',\n '-infinity',\n 'now',\n 'today',\n 'tomorrow',\n 'yesterday',\n 'allballs',\n]);\n\n/**\n * A `timestamptz` cast is only safe to apply unattended when the source text\n * already carries an explicit UTC offset (`Z` or `+HH[:MM]`/`-HH[:MM]`) —\n * without one, PostgreSQL interprets the value under the *migrating\n * session's* `TimeZone` setting, so the exact same text can cast to a\n * different instant on a different run/server. That ambiguity is exactly\n * what `--legacy-timezone=UTC` exists to resolve explicitly; the probe must\n * fail closed (not silently guess UTC) so naive values route to that opt-in\n * path instead of being auto-converged.\n */\n// PostgreSQL's ARE (\"advanced regular expression\") dialect, matched with the\n// case-insensitive `~*` operator server-side — not a JS RegExp, and not\n// derived from one, since the two dialects diverge on escaping/anchoring.\nconst TIMESTAMPTZ_EXPLICIT_OFFSET_SQL_PATTERN =\n '^[0-9]{4}-[0-9]{2}-[0-9]{2}([ T][0-9]{2}:[0-9]{2}(:[0-9]{2}(\\\\.[0-9]+)?)?)?[[:space:]]*(Z|[+-][0-9]{2}(:?[0-9]{2})?)$';\n\n/**\n * `target` is one of this module's own literal type names — never data —\n * so building the DDL by interpolation is safe; there is no column, table,\n * or row value in this string.\n */\nfunction renderCreateProbeFunctionSql(): string {\n const specialValuesArray = [...TIMESTAMPTZ_SPECIAL_VALUES]\n .map((value) => `'${value}'`)\n .join(',');\n return (\n `CREATE OR REPLACE FUNCTION ${PROBE_FUNCTION}(value text, target_type text) ` +\n 'RETURNS boolean LANGUAGE plpgsql AS $$ ' +\n 'BEGIN ' +\n 'IF value IS NULL THEN RETURN true; END IF; ' +\n \"IF target_type = 'timestamptz' THEN \" +\n `IF lower(trim(value)) = ANY (ARRAY[${specialValuesArray}]) THEN RETURN false; END IF; ` +\n `IF trim(value) !~* '${TIMESTAMPTZ_EXPLICIT_OFFSET_SQL_PATTERN}' THEN RETURN false; END IF; ` +\n 'END IF; ' +\n \"EXECUTE format('SELECT %L::%s', value, target_type); \" +\n 'RETURN true; ' +\n 'EXCEPTION WHEN OTHERS THEN RETURN false; ' +\n 'END; $$'\n );\n}\n\nfunction renderProbeQuerySql(\n tableName: string,\n columnName: string,\n targetType: 'timestamptz' | 'jsonb',\n): string {\n const column = quoteIdentifier(columnName);\n const table = quoteIdentifier(tableName);\n const isValid = `${PROBE_FUNCTION}(${column}::text, '${targetType}')`;\n return (\n `SELECT count(*) AS invalid_count, ` +\n `min(CASE WHEN NOT ${isValid} THEN ${column}::text END) AS sample_value ` +\n `FROM ${table} WHERE ${column} IS NOT NULL AND NOT ${isValid}`\n );\n}\n\nfunction classifyProbeRows(\n rows: { invalid_count?: unknown; sample_value?: unknown }[],\n): ShapeProbeResult {\n const count = Number(rows[0]?.invalid_count);\n if (!Number.isFinite(count)) {\n return {\n status: 'unavailable',\n reason: 'probe returned a non-numeric count',\n };\n }\n if (count === 0) return { status: 'clean' };\n const sample = rows[0]?.sample_value;\n return {\n status: 'dirty',\n count,\n ...(typeof sample === 'string' ? { sample } : {}),\n };\n}\n\n/**\n * Probe every non-null value of a candidate `text` column for whether it can\n * cast losslessly to `timestamptz` or `jsonb`, using a real, exception-safe\n * cast attempt (not a shape heuristic) so an invalid-calendar timestamp or a\n * structurally-malformed-but-bracket-balanced JSON document is caught the\n * same as an obviously wrong value. Any failure to run the probe (adapter\n * without transaction support, a missing table mid-run, a test double\n * without a realistic response) resolves to `unavailable` — callers must not\n * treat that as \"clean\"; SMRT never coerces or discards data on an unproven\n * assumption.\n */\nexport async function probeCastSafety(\n db: DatabaseInterface,\n tableName: string,\n columnName: string,\n targetType: 'timestamptz' | 'jsonb',\n): Promise<ShapeProbeResult> {\n if (!db.transaction) {\n return {\n status: 'unavailable',\n reason: 'adapter does not support transactions',\n };\n }\n try {\n return await db.transaction(async (tx) => {\n await tx.query(renderCreateProbeFunctionSql());\n const result = await tx.query(\n renderProbeQuerySql(tableName, columnName, targetType),\n );\n const rows = (Array.isArray(result) ? result : (result?.rows ?? [])) as {\n invalid_count?: unknown;\n sample_value?: unknown;\n }[];\n return classifyProbeRows(rows);\n });\n } catch (error) {\n return {\n status: 'unavailable',\n reason: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\n/**\n * Column-conversion options shared by {@link renderTimestamptzColumnConversion}\n * and {@link renderJsonbColumnConversion}.\n *\n * `hasLiveDefault` and `manifestDefaultValue` are independent: PostgreSQL\n * rejects `ALTER COLUMN ... TYPE` outright whenever the column has *any*\n * existing default that cannot be auto-cast to the target type — this is\n * true whether or not the manifest itself declares a default (a legacy\n * `text` column with `DEFAULT ''` blocks the ALTER exactly the same as one\n * the manifest also wants a default on), so `DROP DEFAULT` must be gated on\n * the *live* default. `SET DEFAULT` afterward must be gated on the\n * *manifest* default instead: re-establishing a live-only default the\n * manifest no longer declares would silently resurrect drift\n * `compareColumnConstraints` is supposed to report and let an operator\n * choose to drop (see #2771/#2772 review findings: DROP/TYPE/SET DEFAULT\n * mirrors the pre-existing `generateTypeUpgradeSQL` path, and the DROP gate\n * must key off live state PostgreSQL itself enforces, not manifest intent).\n */\ninterface ColumnConversionOptions {\n hasLiveDefault?: boolean;\n manifestDefaultValue?: unknown;\n}\n\n/**\n * Render the one-time PostgreSQL conversion of a legacy `text` column to\n * native `timestamptz`, once {@link probeCastSafety} has confirmed every\n * non-null value casts safely.\n */\nexport function renderTimestamptzColumnConversion(\n tableName: string,\n columnName: string,\n options: ColumnConversionOptions = {},\n): string[] {\n const table = quoteIdentifier(tableName);\n const column = quoteIdentifier(columnName);\n const hasManifestDefault = options.manifestDefaultValue !== undefined;\n const statements: string[] = [];\n if (options.hasLiveDefault || hasManifestDefault) {\n statements.push(`ALTER TABLE ${table} ALTER COLUMN ${column} DROP DEFAULT`);\n }\n statements.push(\n `ALTER TABLE ${table} ALTER COLUMN ${column} TYPE timestamptz USING ${column}::timestamptz`,\n );\n if (hasManifestDefault) {\n const formattedDefault = formatDefaultValue(\n options.manifestDefaultValue,\n 'TIMESTAMP',\n );\n statements.push(\n `ALTER TABLE ${table} ALTER COLUMN ${column} SET DEFAULT ${formattedDefault}`,\n );\n }\n return statements;\n}\n\n/**\n * Render the one-time PostgreSQL conversion of a legacy `text` column to\n * native `jsonb`, once {@link probeCastSafety} has confirmed every non-null\n * value casts safely.\n */\nexport function renderJsonbColumnConversion(\n tableName: string,\n columnName: string,\n options: ColumnConversionOptions = {},\n): string[] {\n const table = quoteIdentifier(tableName);\n const column = quoteIdentifier(columnName);\n const hasManifestDefault = options.manifestDefaultValue !== undefined;\n const statements: string[] = [];\n if (options.hasLiveDefault || hasManifestDefault) {\n statements.push(`ALTER TABLE ${table} ALTER COLUMN ${column} DROP DEFAULT`);\n }\n statements.push(\n `ALTER TABLE ${table} ALTER COLUMN ${column} TYPE jsonb USING ${column}::jsonb`,\n );\n if (hasManifestDefault) {\n const formattedDefault = formatDefaultValue(\n options.manifestDefaultValue,\n 'JSON',\n );\n statements.push(\n `ALTER TABLE ${table} ALTER COLUMN ${column} SET DEFAULT ${formattedDefault}::jsonb`,\n );\n }\n return statements;\n}\n"],"mappings":";;;;;;;AAsCA,SAAgB,gBAAgB,OAAuB;CACrD,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,IAAI,MAAM,UAAU,GAClB,OAAO,GAAG,IAAI,OAAO,MAAM,MAAM,EAAE,WAAW,MAAM,OAAO;CAC7D,OAAO,GAAG,MAAM,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,MAAM,EAAE,EAAE,WAAW,MAAM,OAAO;AACzE;;AAGA,IAAM,iBAAiB;;;;;;;;;;;AAYvB,IAAM,6CAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;;AAeD,IAAM,0CACJ;;;;;;AAOF,SAAS,+BAAuC;CAI9C,OACE,8BAA8B,eAAe,kMAJpB,CAAC,GAAG,0BAA0B,CAAC,CACvD,KAAK,UAAU,IAAI,MAAM,EAAE,CAAC,CAC5B,KAAK,GAOgC,EAAmB,oDAClC,wCAAwC;AAOnE;AAEA,SAAS,oBACP,WACA,YACA,YACQ;CACR,MAAM,SAAS,gBAAgB,UAAU;CACzC,MAAM,QAAQ,gBAAgB,SAAS;CACvC,MAAM,UAAU,GAAG,eAAe,GAAG,OAAO,WAAW,WAAW;CAClE,OACE,uDACqB,QAAQ,QAAQ,OAAO,mCACpC,MAAM,SAAS,OAAO,uBAAuB;AAEzD;AAEA,SAAS,kBACP,MACkB;CAClB,MAAM,QAAQ,OAAO,KAAK,EAAE,EAAE,aAAa;CAC3C,IAAI,CAAC,OAAO,S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mC,CAAC,GAC1B;CACV,MAAM,QAAQ,gBAAgB,SAAS;CACvC,MAAM,SAAS,gBAAgB,UAAU;CACzC,MAAM,qBAAqB,QAAQ,yBAAyB,KAAA;CAC5D,MAAM,aAAuB,CAAC;CAC9B,IAAI,QAAQ,kBAAkB,oBAC5B,WAAW,KAAK,eAAe,MAAM,gBAAgB,OAAO,cAAc;CAE5E,WAAW,KACT,eAAe,MAAM,gBAAgB,OAAO,oBAAoB,OAAO,QACzE;CACA,IAAI,oBAAoB;EACtB,MAAM,mBAAmB,mBACvB,QAAQ,sBACR,MACF;EACA,WAAW,KACT,eAAe,MAAM,gBAAgB,OAAO,eAAe,iBAAiB,QAC9E;CACF;CACA,OAAO;AACT"}
|
package/dist/schema/types.d.ts
CHANGED
|
@@ -289,7 +289,17 @@ export interface SchemaChangeAdvisory {
|
|
|
289
289
|
*/
|
|
290
290
|
export interface SchemaChange {
|
|
291
291
|
/** Type of change */
|
|
292
|
-
type: 'add_table' | 'drop_table' | 'add_column' | 'drop_column' | 'alter_column' | 'orphan_column' | 'add_index' | 'add_foreign_key' | 'drop_foreign_key' | 'drop_index' | 'orphan_index' | 'type_mismatch' | 'type_upgrade'
|
|
292
|
+
type: 'add_table' | 'drop_table' | 'add_column' | 'drop_column' | 'alter_column' | 'orphan_column' | 'add_index' | 'add_foreign_key' | 'drop_foreign_key' | 'drop_index' | 'orphan_index' | 'type_mismatch' | 'type_upgrade'
|
|
293
|
+
/**
|
|
294
|
+
* A declared column exists live and holds no data while an undeclared
|
|
295
|
+
* column of a compatible type does (#2752) — advisory only, printed by
|
|
296
|
+
* `db:diff`/`db:migrate`, never executed. See `mismatch` and
|
|
297
|
+
* `advisory.suggestedSql` for the copy-then-drop repair: it is
|
|
298
|
+
* genuinely idempotent SQL on PostgreSQL, but on SQLite (no
|
|
299
|
+
* conditional-DDL construct) it is operator-mediated — a guard query
|
|
300
|
+
* plus instructions, not a statement safe to blind-rerun.
|
|
301
|
+
*/
|
|
302
|
+
| 'rename_data_pending';
|
|
293
303
|
/** Affected table name */
|
|
294
304
|
table: string;
|
|
295
305
|
/** Column or index name (if applicable) */
|
|
@@ -329,6 +339,34 @@ export interface SchemaChange {
|
|
|
329
339
|
* carrying an advisory and no `sql`/`sqlStatements` is never executed.
|
|
330
340
|
*/
|
|
331
341
|
advisory?: SchemaChangeAdvisory;
|
|
342
|
+
/**
|
|
343
|
+
* True on an advisory-only `add_foreign_key` change specifically blocked
|
|
344
|
+
* by live orphan child rows (#2748) — as opposed to a type mismatch, a
|
|
345
|
+
* conflicting existing constraint, or an engine that cannot add a foreign
|
|
346
|
+
* key to an existing table. Lets a caller (`db:migrate --null-orphans`)
|
|
347
|
+
* distinguish "repair the data and retry" from every other manual-repair
|
|
348
|
+
* reason without parsing `advisory.message`.
|
|
349
|
+
*/
|
|
350
|
+
orphanBlocked?: boolean;
|
|
351
|
+
/**
|
|
352
|
+
* Present alongside `orphanBlocked: true`: whether the child column
|
|
353
|
+
* allows NULL, matching `renderForeignKeyOrphanRepair()`'s own
|
|
354
|
+
* nullable/not-nullable branch. `false` means the differ's suggested
|
|
355
|
+
* repair SQL is the "Manual repair required" comment, never an
|
|
356
|
+
* executable `UPDATE`.
|
|
357
|
+
*/
|
|
358
|
+
orphanNullable?: boolean;
|
|
359
|
+
/**
|
|
360
|
+
* True on an advisory-only `add_foreign_key` change specifically blocked
|
|
361
|
+
* because this engine cannot express the constraint at all (SQLite
|
|
362
|
+
* requires a table rebuild; DuckDB has no `ALTER TABLE ADD CONSTRAINT`)
|
|
363
|
+
* (#2748). Unlike `orphanBlocked` or a type-conflict advisory, this
|
|
364
|
+
* reason says nothing about the column's own state — a caller (`db:migrate
|
|
365
|
+
* --apply-unblocked`) must not treat the child column as a dependency
|
|
366
|
+
* blocker for it, since no rerun on this engine ever resolves it and doing
|
|
367
|
+
* so would withhold unrelated DDL on that column permanently.
|
|
368
|
+
*/
|
|
369
|
+
engineUnsupported?: boolean;
|
|
332
370
|
/** Generated SQL statement */
|
|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;IACvB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,qBAAqB;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,kDAAkD;IAClD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,wCAAwC;IACxC,eAAe,EAAE,MAAM,CAAC;IACxB,6BAA6B;IAC7B,UAAU,EACN,eAAe,GACf,aAAa,GACb,eAAe,GACf,eAAe,CAAC;IACpB,4CAA4C;IAC5C,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,gBAAgB,GACxB,cAAc,GACd,eAAe,GACf,aAAa,GACb,cAAc,CAAC;AAEnB;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,gFAAgF;IAChF,QAAQ,EAAE,SAAS,GAAG,MAAM,CAAC;IAC7B,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qBAAqB;IACrB,IAAI,EACA,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,cAAc,GACd,eAAe,GACf,WAAW,GACX,iBAAiB,GACjB,kBAAkB,GAClB,YAAY,GACZ,cAAc,GACd,eAAe,GACf,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,SAAS,GACT,MAAM,GACN,MAAM,GACN,SAAS,GACT,MAAM,GACN,WAAW,GAKX,MAAM,CAAC;AAEX,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,aAAa,CAAC,EAA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5B,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,2BAA2B;IAC3B,YAAY,EAAE,gBAAgB,EAAE,CAAC;IACjC,oDAAoD;IACpD,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,iCAAiC;IACjC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC;CACtB"}
|
package/dist/schema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizeForeignKeyAction, resolveForeignKeyDeleteAction } from "./schema/foreign-key-policy.js";
|
|
2
|
-
import { foreignKeyConstraintName, renderForeignKeyConstraint, renderForeignKeyConstraintComment, renderForeignKeyConstraintDrop, renderForeignKeyConstraintValidate, schemaForeignKeys, schemaForeignKeysForEngine } from "./schema/foreign-key-ddl.js";
|
|
2
|
+
import { foreignKeyConstraintName, renderForeignKeyAddStatements, renderForeignKeyConstraint, renderForeignKeyConstraintComment, renderForeignKeyConstraintDrop, renderForeignKeyConstraintValidate, schemaForeignKeys, schemaForeignKeysForEngine } from "./schema/foreign-key-ddl.js";
|
|
3
3
|
import { BaseDDLStrategy } from "./schema/ddl/base-strategy.js";
|
|
4
4
|
import { DuckDBStrategy } from "./schema/ddl/duckdb-strategy.js";
|
|
5
5
|
import { JsonDuckDBStrategy } from "./schema/ddl/json-duckdb-strategy.js";
|
|
@@ -11,8 +11,9 @@ import { SchemaGenerator } from "./schema/generator.js";
|
|
|
11
11
|
import { planForeignKeyCreation } from "./schema/foreign-key-planner.js";
|
|
12
12
|
import { SchemaManager, createSchemaManager } from "./schema/schema-manager.js";
|
|
13
13
|
import { collectManifestTables, manifestColumnsToDefinitions, manifestIndexesToDefinitions, manifestSchemaToDefinition, mergeSchemaDefinitionInto, renderCollectedManifestTable } from "./schema/manifest-schema.js";
|
|
14
|
+
import { collectForeignKeyOrphanCounts } from "./schema/foreign-key-orphan-report.js";
|
|
14
15
|
import { LiveSchemaParityError, checkLiveSchemaParity, normalizeSqlType, parseIndexDefColumns } from "./schema/live-parity.js";
|
|
15
16
|
import { SchemaCodeGenerator } from "./schema/code-generator.js";
|
|
16
17
|
import { SchemaAggregator } from "./schema/schema-aggregator.js";
|
|
17
18
|
import "./schema/index.js";
|
|
18
|
-
export { BaseDDLStrategy, DuckDBStrategy, JsonDuckDBStrategy, LiveSchemaParityError, PostgresStrategy, SQLiteStrategy, SYSTEM_TABLE_NAMES, SchemaAggregator, SchemaCodeGenerator, SchemaGenerator, SchemaManager, checkLiveSchemaParity, collectManifestTables, createSchemaManager, detectEngine, foreignKeyConstraintName, generateDDLForEngine, generateMultiEngineDDL, getAllStrategies, getDDLStrategy, getSystemTableShapes, manifestColumnsToDefinitions, manifestIndexesToDefinitions, manifestSchemaToDefinition, mergeSchemaDefinitionInto, normalizeForeignKeyAction, normalizeSqlType, parseIndexDefColumns, parseTableShapes, planForeignKeyCreation, renderCollectedManifestTable, renderForeignKeyConstraint, renderForeignKeyConstraintComment, renderForeignKeyConstraintDrop, renderForeignKeyConstraintValidate, resolveForeignKeyDeleteAction, schemaForeignKeys, schemaForeignKeysForEngine };
|
|
19
|
+
export { BaseDDLStrategy, DuckDBStrategy, JsonDuckDBStrategy, LiveSchemaParityError, PostgresStrategy, SQLiteStrategy, SYSTEM_TABLE_NAMES, SchemaAggregator, SchemaCodeGenerator, SchemaGenerator, SchemaManager, checkLiveSchemaParity, collectForeignKeyOrphanCounts, collectManifestTables, createSchemaManager, detectEngine, foreignKeyConstraintName, generateDDLForEngine, generateMultiEngineDDL, getAllStrategies, getDDLStrategy, getSystemTableShapes, manifestColumnsToDefinitions, manifestIndexesToDefinitions, manifestSchemaToDefinition, mergeSchemaDefinitionInto, normalizeForeignKeyAction, normalizeSqlType, parseIndexDefColumns, parseTableShapes, planForeignKeyCreation, renderCollectedManifestTable, renderForeignKeyAddStatements, renderForeignKeyConstraint, renderForeignKeyConstraintComment, renderForeignKeyConstraintDrop, renderForeignKeyConstraintValidate, resolveForeignKeyDeleteAction, schemaForeignKeys, schemaForeignKeysForEngine };
|