symmetria-kit 3.4.0 → 3.5.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 +16 -11
- package/dist/cli/query-inspect.js +1 -1
- package/dist/cli.js +17 -17
- package/dist/cli.js.map +1 -1
- package/dist/{diff-DA7huWi5.js → diff-f8tZSWq5.js} +953 -160
- package/dist/diff-f8tZSWq5.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -3
- package/dist/{query-inspector-C-7K9wtB.js → query-inspector-DGaa-bK6.js} +9 -8
- package/dist/query-inspector-DGaa-bK6.js.map +1 -0
- package/dist/{src-J1Nn7Wca.js → src-D9uetYbU.js} +187 -32
- package/dist/src-D9uetYbU.js.map +1 -0
- package/dist/testing.js +26 -32
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
- package/dist/ddl-CtdVeD9m.js +0 -352
- package/dist/ddl-CtdVeD9m.js.map +0 -1
- package/dist/diff-DA7huWi5.js.map +0 -1
- package/dist/query-inspector-C-7K9wtB.js.map +0 -1
- package/dist/src-J1Nn7Wca.js.map +0 -1
package/README.md
CHANGED
|
@@ -172,9 +172,10 @@ names (`oneOf(...).typeName("Role")`, shared by several columns too), foreign
|
|
|
172
172
|
keys as relations (including `ON UPDATE CASCADE`, keys to unique columns and
|
|
173
173
|
columns not named `*_id`, through `.by()` and `.column()`), junction tables,
|
|
174
174
|
primary keys, unique columns, indexes (including expression, partial, ordered,
|
|
175
|
-
`INCLUDE`, collated, `WITH (…)` and non-btree indexes)
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
`INCLUDE`, collated, `WITH (…)` and non-btree indexes), CHECK constraints and
|
|
176
|
+
full-text searches (`.search()` with `fullText()`, for the column and index it
|
|
177
|
+
creates). Conditions are predicates where the DSL can write them as PostgreSQL
|
|
178
|
+
stored them (`users.score.between(1, 10)`,
|
|
178
179
|
`and(users.status.is("active"), users.deletedAt.is(null))`), and `sql` text
|
|
179
180
|
otherwise. A schema written with the DSL, migrated and pulled back needs no
|
|
180
181
|
migration: `diff` and `generate` compare conditions in a normalized form, so
|
|
@@ -200,10 +201,11 @@ manage. Things that exist only in the database are listed too, so nothing
|
|
|
200
201
|
disappears without a word: table inheritance (`inheritance`), row-level security
|
|
201
202
|
and policies (`row-security`), functions and procedures (`function`), sequences
|
|
202
203
|
no column owns or several columns share (`sequence`, without the identity fix,
|
|
203
|
-
which would drop the shared sequence)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
which would drop the shared sequence), identity columns whose sequence starts or
|
|
205
|
+
steps differently (`sequence`), `UNLOGGED` tables (`unlogged`) and the number of
|
|
206
|
+
tables in other schemas, which `pull` does not read (`other-schema`). The same
|
|
207
|
+
list is in `--json` output under `warnings`, each with a `code` and, when one
|
|
208
|
+
exists, a `fix`. The file is never overwritten without `--force`.
|
|
207
209
|
|
|
208
210
|
Then point `symmetria.config.ts` at the module, run `drift` until the remaining
|
|
209
211
|
findings are intended, generate the first migration with `generate initial` and
|
|
@@ -223,10 +225,13 @@ can stay until Prisma no longer deploys.
|
|
|
223
225
|
|
|
224
226
|
- `generate` requires explicit rename hints or `--allow-destructive` for dropped
|
|
225
227
|
tables/columns and for type changes that narrow existing values (a shorter
|
|
226
|
-
`varchar`, fewer decimal places, a smaller integer type
|
|
227
|
-
`boolean`). A
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
`varchar`, fewer decimal places, a smaller integer type or fewer digits before
|
|
229
|
+
the decimal point, an integer to `boolean`). A type change PostgreSQL has no
|
|
230
|
+
cast for in either direction is refused until `using` gives both conversions,
|
|
231
|
+
and conversions that would read the migrating session's time zone convert at
|
|
232
|
+
UTC. A shorter string type is altered without a truncating cast, so PostgreSQL
|
|
233
|
+
refuses values that do not fit instead of cutting them. Declared column order
|
|
234
|
+
is preserved; snapshot hashes are order-independent.
|
|
230
235
|
- `lint` checks actual `up.sql` even after generation and fails for destructive
|
|
231
236
|
or blocking findings, reviewing every action of an `ALTER TABLE` and ignoring
|
|
232
237
|
comments and strings. `CHECK` and foreign keys added without `NOT VALID` are
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as terminalText, a as wrapExplainLines } from "../query-inspector-
|
|
1
|
+
export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as terminalText, a as wrapExplainLines } from "../query-inspector-DGaa-bK6.js";
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { c as
|
|
4
|
-
import { a as
|
|
5
|
-
import { A as terminalWidth, C as view, D as formatError, E as fitLine, M as wrapLines, O as numberedLines, S as choose, T as withSpinner, _ as formatHelp, a as wrapExplainLines, b as formatStatus, c as inspectTableSQL, d as matchesTableName, f as matchingTables, g as formatExecution, h as formatDiff, i as terminalText, j as theme, k as supportsColor, l as inspectTabs, m as formatDashboard, o as highlightSQL, p as formatCreated, s as inspectEntries, t as explainLines, u as matchesEntry, v as formatPullWarnings, w as withScreen, x as ask, y as formatSchema } from "./query-inspector-C-7K9wtB.js";
|
|
2
|
+
import { F as parseMigrationSnapshot, I as snapshotHash, N as migrationSnapshot, a as renameMaps, b as formatDriftFindings, d as parseMigrationSQL, i as diffSchemas, l as lintMigrationSQL, y as detectDrift } from "./diff-f8tZSWq5.js";
|
|
3
|
+
import { a as boundaryDifferences, c as MigrationExecutionError, d as loadMigrationState, g as lintMigration, h as formatLintFindings, l as discardMigration, m as recoverMigrationFiles, n as schemaGraph, o as verifyMigrations, p as squashMigrations, r as pullSchema, s as migrator, t as renderMermaid, u as generateMigration } from "./src-D9uetYbU.js";
|
|
4
|
+
import { A as terminalWidth, C as view, D as formatError, E as fitLine, M as wrapLines, O as numberedLines, S as choose, T as withSpinner, _ as formatHelp, a as wrapExplainLines, b as formatStatus, c as inspectTableSQL, d as matchesTableName, f as matchingTables, g as formatExecution, h as formatDiff, i as terminalText, j as theme, k as supportsColor, l as inspectTabs, m as formatDashboard, o as highlightSQL, p as formatCreated, s as inspectEntries, t as explainLines, u as matchesEntry, v as formatPullWarnings, w as withScreen, x as ask, y as formatSchema } from "./query-inspector-DGaa-bK6.js";
|
|
6
5
|
import * as nodeModule from "node:module";
|
|
7
6
|
import { access, lstat, mkdir, open, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
8
7
|
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
@@ -1222,38 +1221,39 @@ const pull = async (context, name) => {
|
|
|
1222
1221
|
//#region src/cli/screens/rename-prompt.ts
|
|
1223
1222
|
/** Suggestions are decisions, never guessed renames; persisted SQL records the result. */
|
|
1224
1223
|
const resolveRenames = async (before, after, select, options = {}) => {
|
|
1225
|
-
const
|
|
1226
|
-
const
|
|
1224
|
+
const given = renameMaps(options.renames);
|
|
1225
|
+
const tables = new Map(given.tables);
|
|
1226
|
+
const columns = new Map([...given.columns].map(([name, entries]) => [name, new Map(entries)]));
|
|
1227
1227
|
const shape = (table) => JSON.stringify(table.columns.map((column) => [
|
|
1228
1228
|
column.name,
|
|
1229
1229
|
column.sqlType,
|
|
1230
1230
|
column.notNull
|
|
1231
1231
|
]));
|
|
1232
|
-
for (const old of before.tables.filter((table) => !tables
|
|
1233
|
-
const candidates = after.tables.filter((next) => !
|
|
1232
|
+
for (const old of before.tables.filter((table) => !tables.has(table.name) && !after.tables.some((next) => next.name === table.name))) {
|
|
1233
|
+
const candidates = after.tables.filter((next) => ![...tables.values()].includes(next.name) && !before.tables.some((table) => table.name === next.name) && shape(old) === shape(next));
|
|
1234
1234
|
if (!candidates.length) continue;
|
|
1235
1235
|
const choice = await select(`Table ${old.name} disappeared. How should this change be represented?`, [...candidates.map((candidate) => `Rename ${old.name} → ${candidate.name}`), "Drop and add tables"]);
|
|
1236
1236
|
if (choice === void 0) throw new Error("symmetria: migration generation cancelled");
|
|
1237
|
-
if (choice < candidates.length) tables
|
|
1237
|
+
if (choice < candidates.length) tables.set(old.name, candidates[choice].name);
|
|
1238
1238
|
}
|
|
1239
1239
|
for (const oldTable of before.tables) {
|
|
1240
|
-
const table = after.tables.find((next) => next.name === (tables
|
|
1240
|
+
const table = after.tables.find((next) => next.name === (tables.get(oldTable.name) ?? oldTable.name));
|
|
1241
1241
|
if (!table) continue;
|
|
1242
|
-
const hints = columns
|
|
1243
|
-
for (const old of oldTable.columns.filter((column) => !hints
|
|
1244
|
-
const candidates = table.columns.filter((next) => !
|
|
1242
|
+
const hints = columns.get(table.name) ?? /* @__PURE__ */ new Map();
|
|
1243
|
+
for (const old of oldTable.columns.filter((column) => !hints.has(column.name) && !table.columns.some((next) => next.name === column.name))) {
|
|
1244
|
+
const candidates = table.columns.filter((next) => ![...hints.values()].includes(next.name) && !oldTable.columns.some((column) => column.name === next.name) && next.sqlType === old.sqlType && next.notNull === old.notNull);
|
|
1245
1245
|
if (!candidates.length) continue;
|
|
1246
1246
|
const choice = await select(`${table.name}.${old.name} disappeared. How should this change be represented?`, [...candidates.map((candidate) => `Rename ${old.name} → ${candidate.name}`), "Drop column and add new columns"]);
|
|
1247
1247
|
if (choice === void 0) throw new Error("symmetria: migration generation cancelled");
|
|
1248
|
-
if (choice < candidates.length) hints
|
|
1248
|
+
if (choice < candidates.length) hints.set(old.name, candidates[choice].name);
|
|
1249
1249
|
}
|
|
1250
|
-
if (
|
|
1250
|
+
if (hints.size) columns.set(table.name, hints);
|
|
1251
1251
|
}
|
|
1252
1252
|
return {
|
|
1253
1253
|
...options,
|
|
1254
1254
|
renames: {
|
|
1255
|
-
tables,
|
|
1256
|
-
columns
|
|
1255
|
+
tables: Object.fromEntries(tables),
|
|
1256
|
+
columns: Object.fromEntries([...columns].map(([name, entries]) => [name, Object.fromEntries(entries)]))
|
|
1257
1257
|
}
|
|
1258
1258
|
};
|
|
1259
1259
|
};
|