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 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 }`; only the current schema
398
- snapshot is stored. Generated and squashed migrations include their new
399
- snapshot.
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-S6bPVzZd.js";
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 migrationSnapshot, E as formatDriftFindings, H as parseMigrationSnapshot, L as commentText, T as detectDrift, U as snapshotHash, f as parseMigrationSQL, i as diffSchemas, o as renameMaps, u as lintMigrationSQL } from "./diff-6qN8vcqd.js";
3
- import { a as boundaryDifferences, b as formatLintFindings, c as migrationJournal, d as executeSQL, f as migrationLockHolder, g as loadMigrationState, h as generateMigration, 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, v as squashMigrations, x as lintMigration, y as recoverMigrationFiles } from "./src-BSrLopKL.js";
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-S6bPVzZd.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-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((statement) => !statement.startsWith("--")).length : void 0,
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 plan = diffSchemas(before, migrationSnapshot(snapshot), diffOptions);
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
- if (pretty && !values.json && !values.empty) output(formatDiff(plan, color, diffOptions.renames));
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,