@metaobjectsdev/migrate-ts 0.15.21 → 0.16.0-rc.1

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.
Files changed (51) hide show
  1. package/dist/diff/index.d.ts.map +1 -1
  2. package/dist/diff/index.js +141 -16
  3. package/dist/diff/index.js.map +1 -1
  4. package/dist/diff/status.js +28 -2
  5. package/dist/diff/status.js.map +1 -1
  6. package/dist/drift/drift.d.ts +2 -2
  7. package/dist/drift/drift.d.ts.map +1 -1
  8. package/dist/emit/postgres.d.ts.map +1 -1
  9. package/dist/emit/postgres.js +94 -4
  10. package/dist/emit/postgres.js.map +1 -1
  11. package/dist/expected-schema.d.ts +19 -2
  12. package/dist/expected-schema.d.ts.map +1 -1
  13. package/dist/expected-schema.js +26 -2
  14. package/dist/expected-schema.js.map +1 -1
  15. package/dist/introspect/postgres.d.ts +15 -1
  16. package/dist/introspect/postgres.d.ts.map +1 -1
  17. package/dist/introspect/postgres.js +132 -11
  18. package/dist/introspect/postgres.js.map +1 -1
  19. package/dist/snapshot/plan.d.ts +4 -3
  20. package/dist/snapshot/plan.d.ts.map +1 -1
  21. package/dist/snapshot/plan.js.map +1 -1
  22. package/dist/snapshot/serialize.d.ts +15 -1
  23. package/dist/snapshot/serialize.d.ts.map +1 -1
  24. package/dist/snapshot/serialize.js +15 -1
  25. package/dist/snapshot/serialize.js.map +1 -1
  26. package/dist/types.d.ts +95 -7
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/view-column-types.d.ts +40 -0
  29. package/dist/view-column-types.d.ts.map +1 -0
  30. package/dist/view-column-types.js +100 -0
  31. package/dist/view-column-types.js.map +1 -0
  32. package/dist/view-fingerprint.d.ts +40 -0
  33. package/dist/view-fingerprint.d.ts.map +1 -0
  34. package/dist/view-fingerprint.js +88 -0
  35. package/dist/view-fingerprint.js.map +1 -0
  36. package/dist/view-sql-compare.d.ts.map +1 -1
  37. package/dist/view-sql-compare.js +24 -19
  38. package/dist/view-sql-compare.js.map +1 -1
  39. package/package.json +2 -2
  40. package/src/diff/index.ts +151 -19
  41. package/src/diff/status.ts +29 -2
  42. package/src/drift/drift.ts +2 -2
  43. package/src/emit/postgres.ts +102 -4
  44. package/src/expected-schema.ts +44 -3
  45. package/src/introspect/postgres.ts +148 -10
  46. package/src/snapshot/plan.ts +4 -3
  47. package/src/snapshot/serialize.ts +15 -1
  48. package/src/types.ts +109 -9
  49. package/src/view-column-types.ts +110 -0
  50. package/src/view-fingerprint.ts +97 -0
  51. package/src/view-sql-compare.ts +24 -19
@@ -1,25 +1,30 @@
1
- // view-sql-compare.ts — the single shared comparator for view definition SQL.
1
+ // view-sql-compare.ts — the SQLITE/D1 comparator for view definition SQL.
2
2
  //
3
- // View definition SQL arrives in two shapes across the pipeline:
4
- // - EXPECTED (buildProjectionViews): the body only `SELECT ... FROM ...`.
5
- // - ACTUAL (introspect): sqlite's/D1's sqlite_master.sql is the full
6
- // `CREATE VIEW <name> AS <body>`; Postgres' view_definition is body-only.
3
+ // SCOPE read this before reusing it. This comparator is sound ONLY on engines that
4
+ // store view SQL VERBATIM. SQLite and D1 do: `sqlite_master.sql` hands back the exact
5
+ // `CREATE VIEW <name> AS <body>` text we wrote, so normalizing away whitespace and the
6
+ // CREATE wrapper leaves two strings that genuinely can be equal.
7
7
  //
8
- // normalizeViewSql reduces either of these to a comparable canonical form so the
9
- // diff (expected vs introspected) uses ONE comparison. It strips a leading
10
- // `CREATE [OR REPLACE] VIEW <name> AS`,
11
- // collapses runs of whitespace to a single space, drops a trailing `;`, and
12
- // lower-cases view-body drift should be classified by structure, not by
13
- // incidental whitespace/case/wrapper differences.
8
+ // It is NOT usable on Postgres, and used to be. Postgres does not store view SQL — it
9
+ // stores the parse tree, and `pg_get_viewdef()` DEPARSES it back in Postgres's own
10
+ // style (lowercased functions, `LEFT OUTER JOIN` rewritten to `LEFT JOIN`,
11
+ // parenthesized FROM items and ON predicates, redundant aliases dropped). The text we
12
+ // emitted therefore NEVER comes back, this comparator returned false every single
13
+ // time, and `replace-view` fired on every migrate for every view, forever — while
14
+ // `verify --db` stayed permanently red for any project with a projection. Postgres now
15
+ // compares FINGERPRINTS instead (see view-fingerprint.ts), which never consults the
16
+ // deparser at all. Do not point this function at Postgres again.
14
17
  //
15
- // CAVEAT (accepted tradeoff): lower-casing makes keyword/identifier comparison
16
- // case-insensitive but can mask a difference that lives ONLY in a case-sensitive
17
- // string literal in the body (e.g. `WHERE status = 'Active'` vs `'active'`) —
18
- // such a change would NOT be flagged as drift. Acceptable for generated
19
- // aggregate/passthrough projections (no literals); revisit if hand-authored
20
- // views with case-sensitive literals become a drift concern. The name regex
21
- // matches one whitespace/`(`-free token, so a quoted view name containing a
22
- // space would not strip cleanly also a non-issue for generated identifiers.
18
+ // normalizeViewSql strips a leading `CREATE [OR REPLACE] VIEW <name> AS`, collapses
19
+ // whitespace runs, drops a trailing `;`, and lower-cases.
20
+ //
21
+ // CAVEAT (accepted tradeoff): lower-casing can mask a difference living ONLY in a
22
+ // case-sensitive string literal (e.g. `WHERE status = 'Active'` vs `'active'`), which
23
+ // an `origin.aggregate @filter` predicate can now carry. The fingerprint path
24
+ // deliberately does NOT lowercase for exactly this reason; this SQLite path keeps it
25
+ // for backwards-compatible behavior. The name regex matches one whitespace/`(`-free
26
+ // token, so a quoted view name containing a space would not strip cleanly — a non-issue
27
+ // for generated identifiers.
23
28
 
24
29
  const CREATE_VIEW_PREFIX =
25
30
  /^\s*create\s+(?:or\s+replace\s+)?(?:temp(?:orary)?\s+)?view\s+(?:if\s+not\s+exists\s+)?[^\s(]+(?:\s*\([^)]*\))?\s+as\s+/i;