symmetria-kit 3.7.1 → 4.0.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 +6 -3
- package/dist/cli/query-inspect.js +1 -1
- package/dist/cli.js +21 -10
- package/dist/cli.js.map +1 -1
- package/dist/{diff-6qN8vcqd.js → diff-CC0_Wp9Z.js} +137 -36
- package/dist/diff-CC0_Wp9Z.js.map +1 -0
- package/dist/index.d.ts +15 -2
- package/dist/index.js +2 -2
- package/dist/{query-inspector-S6bPVzZd.js → query-inspector-C5e2s4hC.js} +3 -3
- package/dist/query-inspector-C5e2s4hC.js.map +1 -0
- package/dist/{src-BSrLopKL.js → src-4JLADRCG.js} +373 -83
- package/dist/src-4JLADRCG.js.map +1 -0
- package/dist/testing.d.ts +6 -2
- package/dist/testing.js +13 -3
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
- package/dist/diff-6qN8vcqd.js.map +0 -1
- package/dist/query-inspector-S6bPVzZd.js.map +0 -1
- package/dist/src-BSrLopKL.js.map +0 -1
package/README.md
CHANGED
|
@@ -394,9 +394,12 @@ Exports: `defineMigrationConfig`, `migrationSnapshot`, `parseMigrationSnapshot`,
|
|
|
394
394
|
`MigrationExecutionError` and `migrator`, with their associated types.
|
|
395
395
|
`pullSchema({ execute, ignoreTables })` returns the generated source, the
|
|
396
396
|
declared tables and the review warnings without touching the file system.
|
|
397
|
-
`loadMigrationState` returns `{ migrations, snapshot }
|
|
398
|
-
|
|
399
|
-
|
|
397
|
+
`loadMigrationState` returns `{ migrations, snapshot, undo? }`: the SQL chain,
|
|
398
|
+
the current schema snapshot and `undo: { migration, snapshot }`, the snapshot
|
|
399
|
+
from before the latest migration, which `generate` keeps in the journal so that
|
|
400
|
+
`discard` can take that migration back (absent after a squash or a discard). No
|
|
401
|
+
other earlier snapshot is stored. Generated and squashed migrations include
|
|
402
|
+
their new snapshot.
|
|
400
403
|
|
|
401
404
|
```ts
|
|
402
405
|
import { postgres } from "symmetria/driver";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as wrapExplainLines } from "../query-inspector-
|
|
1
|
+
export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as wrapExplainLines } from "../query-inspector-C5e2s4hC.js";
|
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { B as
|
|
3
|
-
import { a as boundaryDifferences, b as
|
|
2
|
+
import { B as commentText, G as parseMigrationSnapshot, K as snapshotHash, O as detectDrift, U as migrationSnapshot, g as runsSQL, h as parseMigrationSQL, i as diffSchemas, k as formatDriftFindings, p as lintMigrationSQL, s as renameMaps } from "./diff-CC0_Wp9Z.js";
|
|
3
|
+
import { C as lintMigration, S as formatLintFindings, _ as loadMigrationState, a as boundaryDifferences, b as unrecordedEmbeddings, c as migrationJournal, d as executeSQL, f as migrationLockHolder, g as generateMigration, h as embeddingRecordNote, l as migrator, m as discardTarget, n as schemaGraph, o as serverAddress, p as discardMigration, r as pullSchema, s as verifyMigrations, t as renderMermaid, u as MigrationExecutionError, x as recoverMigrationFiles, y as squashMigrations } from "./src-4JLADRCG.js";
|
|
4
4
|
import { a as trimUrl, i as parsePostgresUrl, n as credentialsSpilled, r as parseAsDriver, t as SPILLED_ADVICE } from "./connection-url-BWkVT0Cd.js";
|
|
5
|
-
import { A as terminalOutput, C as view, D as formatError, E as fitLine, F as flagGiven, I as interrupt, L as interruptible, M as terminalWidth, N as theme, O as numberedLines, P as wrapLines, R as interruption, S as choose, T as withSpinner, _ as formatPlan, a as highlightSQL, b as formatStatus, c as inspectTabs, d as matchingTables, f as formatCreated, g as formatHelp, h as formatExecution, i as wrapExplainLines, j as terminalText, k as supportsColor, l as matchesEntry, m as formatDiff, o as inspectEntries, p as formatDashboard, s as inspectTableSQL, t as explainLines, u as matchesTableName, v as formatPullWarnings, w as withScreen, x as ask, y as formatSchema } from "./query-inspector-
|
|
5
|
+
import { A as terminalOutput, C as view, D as formatError, E as fitLine, F as flagGiven, I as interrupt, L as interruptible, M as terminalWidth, N as theme, O as numberedLines, P as wrapLines, R as interruption, S as choose, T as withSpinner, _ as formatPlan, a as highlightSQL, b as formatStatus, c as inspectTabs, d as matchingTables, f as formatCreated, g as formatHelp, h as formatExecution, i as wrapExplainLines, j as terminalText, k as supportsColor, l as matchesEntry, m as formatDiff, o as inspectEntries, p as formatDashboard, s as inspectTableSQL, t as explainLines, u as matchesTableName, v as formatPullWarnings, w as withScreen, x as ask, y as formatSchema } from "./query-inspector-C5e2s4hC.js";
|
|
6
6
|
import * as nodeModule from "node:module";
|
|
7
7
|
import { access, lstat, mkdir, open, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
8
8
|
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
9
9
|
import { parseArgs, stripVTControlCharacters } from "node:util";
|
|
10
|
-
import { postgres } from "symmetria/driver";
|
|
11
10
|
import { sqlState } from "symmetria";
|
|
11
|
+
import { postgres } from "symmetria/driver";
|
|
12
12
|
import { readFileSync } from "node:fs";
|
|
13
13
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
14
14
|
import stringWidth from "string-width";
|
|
@@ -700,7 +700,7 @@ const overview = async (context, project) => {
|
|
|
700
700
|
...missing ? { missing } : {},
|
|
701
701
|
snapshot,
|
|
702
702
|
local: migrations.length,
|
|
703
|
-
changes: snapshot ? diffSchemas(before, snapshot).up.filter(
|
|
703
|
+
changes: snapshot ? diffSchemas(before, snapshot).up.filter(runsSQL).length : void 0,
|
|
704
704
|
config: project.present ? relative(process.cwd(), project.configPath) || project.configPath : "No config · symmetria init to get started"
|
|
705
705
|
};
|
|
706
706
|
};
|
|
@@ -2000,18 +2000,28 @@ const diff = async (context, project) => {
|
|
|
2000
2000
|
const diffOptions = await readDiffOptions(context);
|
|
2001
2001
|
const snapshot = declaredSchema(project, true);
|
|
2002
2002
|
const { snapshot: before } = await loadMigrationState(project.directory);
|
|
2003
|
-
const
|
|
2003
|
+
const after = migrationSnapshot(snapshot);
|
|
2004
|
+
const plan = diffSchemas(before, after, diffOptions);
|
|
2004
2005
|
if (values.sql) {
|
|
2005
2006
|
output(plan.up.map((statement) => `${statement};`).join("\n\n"));
|
|
2006
2007
|
return;
|
|
2007
2008
|
}
|
|
2009
|
+
const recorded = recordedOnly(plan, before, after);
|
|
2008
2010
|
context.emit({
|
|
2009
2011
|
json: plan,
|
|
2010
2012
|
indent: 2,
|
|
2011
|
-
pretty: () => formatDiff(plan, color, diffOptions.renames)
|
|
2012
|
-
plain: () => formatDiff(plan, false, diffOptions.renames)
|
|
2013
|
+
pretty: () => `${formatDiff(plan, color, diffOptions.renames)}${recorded}`,
|
|
2014
|
+
plain: () => `${formatDiff(plan, false, diffOptions.renames)}${recorded}`
|
|
2013
2015
|
});
|
|
2014
2016
|
};
|
|
2017
|
+
/**
|
|
2018
|
+
* What generate writes although the schema needs no SQL, as a line after "No
|
|
2019
|
+
* schema changes"; empty when it writes nothing.
|
|
2020
|
+
*/
|
|
2021
|
+
const recordedOnly = (plan, before, after) => {
|
|
2022
|
+
const columns = plan.up.length || plan.down.length ? [] : unrecordedEmbeddings(before, after);
|
|
2023
|
+
return columns.length ? `\nThe snapshot was saved by an earlier release: generate writes a migration without SQL, which ${embeddingRecordNote(columns)}.` : "";
|
|
2024
|
+
};
|
|
2015
2025
|
/** `generate [name]`: write up.sql, down.sql and the versioned snapshot. */
|
|
2016
2026
|
const generate = async (context, project, requestedName) => {
|
|
2017
2027
|
const { values, color, pretty, interactive, output } = context;
|
|
@@ -2023,7 +2033,8 @@ const generate = async (context, project, requestedName) => {
|
|
|
2023
2033
|
const plan = diffSchemas(before, after, diffOptions);
|
|
2024
2034
|
const name = requestedName ?? await ask("Migration name:", color);
|
|
2025
2035
|
if (!name) throw new Error(interruption() ? "symmetria: interrupted" : "symmetria: generate requires a migration name");
|
|
2026
|
-
|
|
2036
|
+
const recorded = values.empty ? "" : recordedOnly(plan, before, after);
|
|
2037
|
+
if (pretty && !values.json && !values.empty) output(`${formatDiff(plan, color, diffOptions.renames)}${recorded}`);
|
|
2027
2038
|
const migration = await context.progress("Writing migration", () => withCancellation((signal) => generateMigration({
|
|
2028
2039
|
...diffOptions,
|
|
2029
2040
|
directory: project.directory,
|
|
@@ -2037,7 +2048,7 @@ const generate = async (context, project, requestedName) => {
|
|
|
2037
2048
|
})));
|
|
2038
2049
|
const directory = project.directory;
|
|
2039
2050
|
const findings = migration ? lintMigration(plan, diffOptions.renames) : [];
|
|
2040
|
-
const review = findings.length ? `\n\nReview before applying:\n${formatLintFindings(findings)}` : "";
|
|
2051
|
+
const review = findings.length ? `\n\nReview before applying:\n${formatLintFindings(findings)}` : pretty ? "" : recorded;
|
|
2041
2052
|
context.emit({
|
|
2042
2053
|
json: migration ? {
|
|
2043
2054
|
id: migration.id,
|