@uncutsql/core 0.0.0-stage → 0.1.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
@@ -1,3 +1,80 @@
1
- # Temporary Holding Version
1
+ # @uncutsql/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Dialect-independent database models, structural comparison and logical migration
4
+ procedures. The only runtime dependency is Effect. No SQL parser, codec, dialect,
5
+ filesystem or database driver is imported here.
6
+
7
+ `DatabaseSchema` contains tables, standalone indexes, columns, constraints and option properties.
8
+ Table identities distinguish catalog and schema. Each dialect adapter supplies
9
+ normalized table identities and column keys; core does not infer namespaces or
10
+ fold case. Types and constraint properties use serializable structured values.
11
+ Namespaced option keys retain dialect features without hardcoding their meaning.
12
+ Object property order is ignored, while array order remains significant.
13
+
14
+ ```ts
15
+ import { resolveMigrationDecisions, planDatabaseMigration } from "@uncutsql/core";
16
+
17
+ const { diff } = yield * resolveMigrationDecisions(beforeDatabase, afterDatabase, decisions);
18
+ const migration = planDatabaseMigration(diff);
19
+ // migration.procedures: CreateTable | DropTable | AlterTable | RenameTable
20
+ ```
21
+
22
+ The logical procedures express requested changes. Each dialect chooses physical
23
+ operations, dependency order, rebuild strategy and SQL rendering. Cross-dialect
24
+ semantic equivalence is not inferred: adapters must agree on normalized values
25
+ before comparison. Views carry a query, and triggers carry a target identity and a
26
+ dialect-normalized definition. Changes to either trigger field produce a ReplaceTrigger procedure.
27
+
28
+ ```sh
29
+ pnpm --filter @uncutsql/core check
30
+ pnpm --filter @uncutsql/core build
31
+ ```
32
+
33
+ `Dialect<Ast, PhysicalPlan, E, R>` is the capability contract for interchangeable
34
+ adapters: parse/format SQL, convert ASTs to the shared model, lower logical
35
+ procedures and render a physical plan. Users own the composition. Core never
36
+ selects or imports a dialect, and dialect packages must not run the core diff or
37
+ logical planner on behalf of callers. The CLI demonstrates the wiring and tests
38
+ its workflow with a separate fixture adapter that has a different AST and plan.
39
+
40
+ `decodeDatabaseSchema(unknown)` validates JSON-restored/external model shapes and
41
+ serializable semantic values with path-based SchemaModelError failures. Model
42
+ validation is separate from duplicate-identity checking in the diff. Lock versions,
43
+ dialect IDs, migration history and filesystem persistence remain consumer concerns.
44
+
45
+ `MigrationExecutor` is a separate optional runtime contract. Consumers provide the
46
+ full ordered MigrationSource history and a schema-verification callback, leaving
47
+ core comparison in the application. An executor owns connections, physical
48
+ transactions and applied-history recording. It is selected independently from the
49
+ syntax dialect; core itself has no database driver or filesystem dependency.
50
+
51
+ ## Migration decisions
52
+
53
+ `prepareMigrationDecisions(before, after)` returns a versioned JSON document with
54
+ both schema snapshots and structured questions for removed tables and columns.
55
+ Column questions list all added keys in that table as candidates; no similarity
56
+ heuristic selects a rename. Each `resolution` starts as `{ "action": "pending" }`.
57
+
58
+ Table questions list added table names in the same namespace. Consumers choose
59
+ `drop`, `drop_if_empty`, or `rename` with a listed target. After choosing a table
60
+ rename, `mergeMigrationDecisions` adds questions for columns removed from that
61
+ table and retains reviewed answers for the same source and target. Then
62
+ `resolveMigrationDecisions(before, after, document)` validates the untrusted
63
+ answers and snapshots and returns a resolved diff and sanitized decision record.
64
+ Missing, stale, duplicate or conflicting answers fail with MigrationDecisionError;
65
+ its `pending` field carries the review document. Additions alone need no answers.
66
+
67
+ Table renames become RenameTable procedures. Column renames become ColumnRenamed alterations, including separate dataType/constraints
68
+ change fields. The desired schema remains authoritative: rename decisions do not
69
+ rewrite desired CHECK expressions or foreign-key references. Custom transformations, similarity ranking and automatic approval are not provided.
70
+
71
+ Core has no prompts or persistence. `planDatabaseMigration` remains a low-level
72
+ primitive for caller-approved intent; user-facing workflows should resolve
73
+ choices before calling it. The CLI enforces this sequence for migration/generate.
74
+
75
+ ## Roadmap
76
+
77
+ - [x] Represent views in serializable database snapshots, validate restored snapshots, and describe view changes in the diff and logical plan.
78
+ - [x] Represent trigger snapshots, validate restored models and lower trigger diffs to logical procedures.
79
+
80
+ See the [workspace roadmap](../../ROADMAP.md) for cross-project sequencing.