@vibeorm/migrate 1.3.1 → 2.0.0-alpha.10

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 (73) hide show
  1. package/README.md +33 -66
  2. package/dist/ddl/drop-order.d.ts +25 -0
  3. package/dist/ddl/drop-order.d.ts.map +1 -0
  4. package/dist/ddl/mysql.d.ts +46 -0
  5. package/dist/ddl/mysql.d.ts.map +1 -0
  6. package/dist/ddl/postgres.d.ts +24 -0
  7. package/dist/ddl/postgres.d.ts.map +1 -0
  8. package/dist/ddl/render.d.ts +25 -0
  9. package/dist/ddl/render.d.ts.map +1 -0
  10. package/dist/ddl/rls.d.ts +40 -0
  11. package/dist/ddl/rls.d.ts.map +1 -0
  12. package/dist/ddl/sqlite.d.ts +79 -0
  13. package/dist/ddl/sqlite.d.ts.map +1 -0
  14. package/dist/differ.d.ts +41 -0
  15. package/dist/differ.d.ts.map +1 -0
  16. package/dist/down.d.ts +57 -0
  17. package/dist/down.d.ts.map +1 -0
  18. package/dist/enum-values.d.ts +32 -0
  19. package/dist/enum-values.d.ts.map +1 -0
  20. package/dist/execute.d.ts +124 -0
  21. package/dist/execute.d.ts.map +1 -0
  22. package/dist/execution.d.ts +168 -0
  23. package/dist/execution.d.ts.map +1 -0
  24. package/dist/extensions.d.ts +74 -0
  25. package/dist/extensions.d.ts.map +1 -0
  26. package/dist/index.d.ts +32 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +5688 -0
  29. package/dist/index.js.map +37 -0
  30. package/dist/introspect/mysql.d.ts +31 -0
  31. package/dist/introspect/mysql.d.ts.map +1 -0
  32. package/dist/introspect/postgres-rls.d.ts +41 -0
  33. package/dist/introspect/postgres-rls.d.ts.map +1 -0
  34. package/dist/introspect/postgres.d.ts +12 -0
  35. package/dist/introspect/postgres.d.ts.map +1 -0
  36. package/dist/introspect/shared.d.ts +78 -0
  37. package/dist/introspect/shared.d.ts.map +1 -0
  38. package/dist/introspect/sqlite.d.ts +53 -0
  39. package/dist/introspect/sqlite.d.ts.map +1 -0
  40. package/dist/journal-table.d.ts +15 -0
  41. package/dist/journal-table.d.ts.map +1 -0
  42. package/dist/mysql-types.d.ts +66 -0
  43. package/dist/mysql-types.d.ts.map +1 -0
  44. package/dist/normalize.d.ts +143 -0
  45. package/dist/normalize.d.ts.map +1 -0
  46. package/dist/postgres-types.d.ts +95 -0
  47. package/dist/postgres-types.d.ts.map +1 -0
  48. package/dist/push.d.ts +51 -0
  49. package/dist/push.d.ts.map +1 -0
  50. package/dist/recovery.d.ts +41 -0
  51. package/dist/recovery.d.ts.map +1 -0
  52. package/dist/relations.d.ts +40 -0
  53. package/dist/relations.d.ts.map +1 -0
  54. package/dist/renames.d.ts +58 -0
  55. package/dist/renames.d.ts.map +1 -0
  56. package/dist/runner.d.ts +181 -0
  57. package/dist/runner.d.ts.map +1 -0
  58. package/dist/sqlite-types.d.ts +101 -0
  59. package/dist/sqlite-types.d.ts.map +1 -0
  60. package/dist/types.d.ts +329 -0
  61. package/dist/types.d.ts.map +1 -0
  62. package/package.json +34 -23
  63. package/src/cascade-actions.ts +0 -88
  64. package/src/ddl-builder.ts +0 -415
  65. package/src/index.ts +0 -41
  66. package/src/introspector.ts +0 -684
  67. package/src/migration-runner.ts +0 -127
  68. package/src/relation-utils.ts +0 -79
  69. package/src/schema-differ.ts +0 -865
  70. package/src/schema-printer.ts +0 -259
  71. package/src/snapshot.ts +0 -141
  72. package/src/sql-utils.ts +0 -45
  73. package/src/types.ts +0 -13
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Statement-execution helpers shared by push and the migration runner.
3
+ *
4
+ * Two sqlite realities live here:
5
+ *
6
+ * - SELF-MANAGED SCRIPTS: the table-rebuild recipe (ddl/sqlite.ts) carries its
7
+ * own `PRAGMA foreign_keys=OFF; BEGIN; … COMMIT; PRAGMA foreign_keys=ON;`
8
+ * sequence, because `PRAGMA foreign_keys` is a no-op inside a transaction.
9
+ * Callers must NOT wrap such scripts in an outer BEGIN/COMMIT —
10
+ * `usesSelfManagedTransactions` detects them. Plain statements in a
11
+ * self-managed script auto-commit individually (documented sqlite
12
+ * limitation: a mixed script is not atomic as a whole; each rebuild block
13
+ * is). Because of that, the migration runner records per-statement progress
14
+ * for these scripts and resumes with `selfManagedResumeStart`, which rewinds
15
+ * INTO the enclosing block so the session-scoped `PRAGMA foreign_keys=OFF`
16
+ * is re-issued before the block replays.
17
+ * - `PRAGMA foreign_key_check` RETURNS VIOLATION ROWS instead of failing —
18
+ * `executeStatement` runs it row-returning (`values: []`, the adapter-sqlite
19
+ * contract for reads) and throws VIBE_MIGRATION when any come back.
20
+ */
21
+ import type { Dialect } from "@vibeorm/schema";
22
+ import type { SqlExecutor } from "./types.ts";
23
+ /** True when the script manages its own transactions (sqlite rebuilds). */
24
+ export declare function usesSelfManagedTransactions(params: {
25
+ sql: readonly string[];
26
+ }): boolean;
27
+ /**
28
+ * Where a resume of a self-managed sqlite script must actually restart.
29
+ *
30
+ * A recorded statement_index can point INSIDE a rebuild block: the progress
31
+ * UPDATE issued after `PRAGMA foreign_keys=OFF;` auto-commits (no transaction
32
+ * is open yet), while every UPDATE after the block's `BEGIN;` is rolled back
33
+ * with the crash — so the persisted index lands on the block's `BEGIN;`, one
34
+ * past a pragma that is SESSION-scoped and gone in the new session. Resuming
35
+ * there would run the rebuild — `DROP TABLE` of a possibly-referenced parent
36
+ * included — with foreign keys ON.
37
+ *
38
+ * This rewinds `start` to the nearest preceding `PRAGMA foreign_keys=OFF` that
39
+ * is not already closed by a `PRAGMA foreign_keys=ON`. Replaying from a
40
+ * block's start is safe only for an uncommitted block: the runner checkpoints
41
+ * past COMMIT inside the transaction, so a committed block is never replayed.
42
+ * Legacy journals pointing AT COMMIT are ambiguous and refused by the runner.
43
+ * Scripts with no marker before `start` are returned unchanged.
44
+ */
45
+ export declare function selfManagedResumeStart(params: {
46
+ sql: readonly string[];
47
+ start: number;
48
+ }): number;
49
+ /** True when a supported block must checkpoint BEFORE committing its transaction. */
50
+ export declare function isSelfManagedCommit(params: {
51
+ statement: string;
52
+ }): boolean;
53
+ /**
54
+ * An old writer could persist an index AT COMMIT after the block committed.
55
+ * The new writer checkpoints past it atomically and cannot produce this state.
56
+ * Keep historical uncertainty visible until an operator establishes the result.
57
+ */
58
+ export declare function assertSelfManagedResumeSafe(params: {
59
+ sql: readonly string[];
60
+ start: number;
61
+ migration: string;
62
+ direction: "up" | "down";
63
+ }): void;
64
+ /**
65
+ * Can this statement of a self-managed sqlite script commit together with its
66
+ * own journal checkpoint?
67
+ *
68
+ * True for a statement that sits OUTSIDE every rebuild block and that sqlite
69
+ * allows inside a transaction. Wrapping such a statement with its checkpoint in
70
+ * one `BEGIN`/`COMMIT` closes the crash window entirely: either both landed or
71
+ * neither did, so a resume never has to guess whether it already ran.
72
+ *
73
+ * Block membership is decided by {@link selfManagedResumeStart}, the SAME
74
+ * backward scan the resume path uses — the two can never disagree about where a
75
+ * block starts. Inside a block no wrapping is possible or needed: the block
76
+ * carries its own transaction, so nothing of it survives a crash and
77
+ * `selfManagedResumeStart` rewinds to its opening pragma.
78
+ */
79
+ export declare function canCheckpointAtomically(params: {
80
+ sql: readonly string[];
81
+ index: number;
82
+ }): boolean;
83
+ /**
84
+ * Refuse a self-managed sqlite script whose control flow the resume path
85
+ * cannot honour, BEFORE any statement of it runs.
86
+ *
87
+ * The generated rebuild recipe (ddl/sqlite.ts) always emits
88
+ * `PRAGMA foreign_keys=OFF;` immediately followed by `BEGIN;`, and `COMMIT;`
89
+ * immediately followed by `PRAGMA foreign_keys=ON;`. Recovery relies on that
90
+ * adjacency: it is what makes "inside a foreign-keys-off region" and "inside a
91
+ * transaction" the same statement set, so rewinding to the region's pragma can
92
+ * never replay anything that already committed.
93
+ *
94
+ * A hand-authored script that deviates breaks the equivalence silently. An
95
+ * unclosed pragma, or a statement between `COMMIT;` and the restore, commits on
96
+ * its own while still counting as region-internal, so a crash replays it. That
97
+ * is a data defect with no error attached, so the script is refused up front
98
+ * instead. `resolveMigration` and `migrationStatus` are deliberately not
99
+ * gated by this: an operator must still be able to read and repair the journal
100
+ * row of a migration that is refused.
101
+ */
102
+ export declare function assertSupportedSelfManagedScript(params: {
103
+ sql: readonly string[];
104
+ migration: string;
105
+ direction: "up" | "down";
106
+ }): void;
107
+ /**
108
+ * Execute one migration statement. On sqlite, `PRAGMA foreign_key_check` is
109
+ * executed row-returning and its violations become a VIBE_MIGRATION error.
110
+ */
111
+ export declare function executeStatement(params: {
112
+ executor: SqlExecutor;
113
+ statement: string;
114
+ dialect: Dialect;
115
+ }): Promise<void>;
116
+ /**
117
+ * Best-effort cleanup after a failed self-managed sqlite script: roll back a
118
+ * possibly-open rebuild transaction and restore FK enforcement. Never throws
119
+ * — the original failure matters more.
120
+ */
121
+ export declare function cleanupSelfManagedFailure(params: {
122
+ executor: SqlExecutor;
123
+ }): Promise<void>;
124
+ //# sourceMappingURL=execute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAU9C,2EAA2E;AAC3E,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAAG,OAAO,CAEvF;AA+BD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC7C,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,MAAM,CAcT;AAED,qFAAqF;AACrF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IAClD,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;CAC1B,GAAG,IAAI,CAWP;AAyBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE;IAC9C,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAIV;AAgCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gCAAgC,CAAC,MAAM,EAAE;IACvD,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;CAC1B,GAAG,IAAI,CAyDP;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC7C,QAAQ,EAAE,WAAW,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBhB;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAAC,MAAM,EAAE;IAAE,QAAQ,EAAE,WAAW,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhG"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Explicit execution semantics for a migration file: which transaction regime
3
+ * it runs in, which session limits it scopes to its own work, and what each of
4
+ * its statements is DECLARED to do.
5
+ *
6
+ * Why declarations and not SQL parsing: a nontransactional migration can die
7
+ * between a statement committing and the journal recording it. Recovery then
8
+ * has to establish what actually happened, and the only honest way to do that
9
+ * is to compare the live catalog against a declared postcondition. Guessing an
10
+ * operation out of SQL text is exactly the class of bug F29/F33 came from.
11
+ *
12
+ * CHECKSUM COMPATIBILITY — the rule this module exists to protect. A migration
13
+ * with no execution block, or one that asks for nothing beyond today's
14
+ * behaviour, hashes byte-for-byte as before ({@link isDefaultExecution} is
15
+ * true ⇒ {@link executionChecksumSuffix} is empty). Every migration file
16
+ * written before this feature existed therefore keeps its historical checksum
17
+ * and no journal row starts looking corrupt. Only an explicitly non-default
18
+ * block folds a canonical description into the hash, so editing execution
19
+ * semantics after a migration was applied surfaces as the existing
20
+ * checksum-mismatch refusal instead of silently changing how it runs.
21
+ */
22
+ import type { Dialect } from "@vibeorm/schema";
23
+ import type { MigrationStep } from "./types.ts";
24
+ /**
25
+ * How the runner wraps a migration's statements.
26
+ *
27
+ * - `"default"` — the dialect's own regime, unchanged: one transaction per
28
+ * migration on postgres/sqlite, per-statement bookkeeping on mysql.
29
+ * - `"none"` — the migration runs OUTSIDE any transaction the runner opens,
30
+ * with per-statement journal progress. Required for statements PostgreSQL
31
+ * refuses inside a transaction block, `CREATE INDEX CONCURRENTLY` first
32
+ * among them.
33
+ */
34
+ export type MigrationTransactionMode = "default" | "none";
35
+ /**
36
+ * What one statement of a nontransactional migration is declared to do — the
37
+ * postcondition recovery checks against the live catalog. Declared by whoever
38
+ * wrote the migration; never inferred from the SQL text.
39
+ */
40
+ export type MigrationOperation = {
41
+ readonly kind: "createIndexConcurrently";
42
+ readonly index: string;
43
+ readonly table: string;
44
+ readonly unique: boolean;
45
+ /** Access method as PostgreSQL names it (`btree`, `gin`, …). */
46
+ readonly method: string;
47
+ /** Key columns in index order, as PostgreSQL deparses them. */
48
+ readonly columns: readonly string[];
49
+ /** Partial-index predicate, when the index has one. */
50
+ readonly where?: string;
51
+ } | {
52
+ readonly kind: "dropIndexConcurrently";
53
+ readonly index: string;
54
+ } | {
55
+ readonly kind: "addConstraintNotValid";
56
+ readonly table: string;
57
+ readonly constraint: string;
58
+ } | {
59
+ readonly kind: "validateConstraint";
60
+ readonly table: string;
61
+ readonly constraint: string;
62
+ } | {
63
+ readonly kind: "renameTable";
64
+ readonly from: string;
65
+ readonly to: string;
66
+ } | {
67
+ readonly kind: "renameColumn";
68
+ readonly table: string;
69
+ readonly from: string;
70
+ readonly to: string;
71
+ };
72
+ /** One statement's declared operation, keyed by its index in `MigrationFile.sql`. */
73
+ export type MigrationOperationBinding = {
74
+ /** 0-based index into the migration's statement array. */
75
+ readonly statement: number;
76
+ readonly operation: MigrationOperation;
77
+ };
78
+ /** Explicit execution semantics of one direction (up or down) of a migration. */
79
+ export type MigrationExecution = {
80
+ readonly transaction: MigrationTransactionMode;
81
+ /** Migration-owned `lock_timeout` in milliseconds; 0 = no limit (server default). */
82
+ readonly lockTimeoutMs?: number;
83
+ /** Migration-owned `statement_timeout` in milliseconds; 0 = no limit. */
84
+ readonly statementTimeoutMs?: number;
85
+ readonly operations?: readonly MigrationOperationBinding[];
86
+ };
87
+ /** On-disk sidecar filename beside `migration.sql` / `down.sql`. */
88
+ export declare const EXECUTION_SIDECAR_FILENAME: string;
89
+ /** Sidecar format version — bumped only on an incompatible layout change. */
90
+ export declare const EXECUTION_SIDECAR_VERSION: number;
91
+ /** True when the block asks for nothing beyond the dialect's existing behaviour. */
92
+ export declare function isDefaultExecution(params: {
93
+ execution?: MigrationExecution;
94
+ }): boolean;
95
+ /** Deterministic one-line description of an operation — checksum input and error text. */
96
+ export declare function describeOperation(params: {
97
+ operation: MigrationOperation;
98
+ }): string;
99
+ /**
100
+ * The canonical text folded into the migration checksum — EMPTY for a default
101
+ * block, so historical checksums are untouched (see the module doc). The text
102
+ * is built field by field in a fixed order rather than JSON-stringified, so it
103
+ * cannot drift with object key order.
104
+ */
105
+ export declare function executionChecksumSuffix(params: {
106
+ execution?: MigrationExecution;
107
+ }): string;
108
+ /**
109
+ * Structural checks a declared block must pass before the runner trusts it:
110
+ * every operation binding points at a real statement, no statement carries two
111
+ * operations, and the timeouts are non-negative safe integers.
112
+ */
113
+ export declare function assertValidExecution(params: {
114
+ execution?: MigrationExecution;
115
+ statements: number;
116
+ migration: string;
117
+ }): void;
118
+ /** The operation declared for one statement, if any. */
119
+ export declare function operationFor(params: {
120
+ execution?: MigrationExecution;
121
+ statement: number;
122
+ }): MigrationOperation | undefined;
123
+ /**
124
+ * Serialize the execution sidecar, or `undefined` when both directions are
125
+ * default and no file should be written at all. Keeping the file absent for
126
+ * ordinary migrations is what makes the feature invisible to existing trees.
127
+ */
128
+ export declare function serializeExecutionSidecar(params: {
129
+ execution?: MigrationExecution;
130
+ downExecution?: MigrationExecution;
131
+ }): string | undefined;
132
+ /**
133
+ * Read and validate the sidecar. Nothing here is trusted: an unknown version,
134
+ * a malformed body or an out-of-range operation binding refuses rather than
135
+ * silently degrading to default semantics — a migration that believes it runs
136
+ * outside a transaction and quietly runs inside one is exactly the failure
137
+ * this metadata exists to prevent.
138
+ */
139
+ export declare function parseExecutionSidecar(params: {
140
+ text: string;
141
+ migration: string;
142
+ statements: number;
143
+ downStatements: number;
144
+ }): {
145
+ readonly execution?: MigrationExecution;
146
+ readonly downExecution?: MigrationExecution;
147
+ };
148
+ /** A reviewable risk a planned migration carries, for dry-run output. */
149
+ export type MigrationRisk = {
150
+ readonly kind: "tableRewrite" | "exclusiveLock" | "concurrentIndex" | "validateScan" | "notOnline";
151
+ readonly detail: string;
152
+ readonly table?: string;
153
+ };
154
+ /**
155
+ * Describe the operational risk of a planned migration, for dry-run output.
156
+ *
157
+ * Deliberately conservative and deliberately incomplete: it reports what the
158
+ * step model can prove (a type change that rewrites the table on postgres, an
159
+ * ALTER/DROP that takes ACCESS EXCLUSIVE, a validation scan) and it always
160
+ * appends the `notOnline` note, because nothing here — `lock_timeout`
161
+ * included — makes a migration online. A short lock WAIT is not a short lock
162
+ * HOLD.
163
+ */
164
+ export declare function describeMigrationRisks(params: {
165
+ steps: readonly MigrationStep[];
166
+ dialect: Dialect;
167
+ }): readonly MigrationRisk[];
168
+ //# sourceMappingURL=execution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"m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AAM,CAAC;CACnB,GAAG,IAAI,CAsBP;AAED,wDAAwD;AACxD,wBAAgB,YAAY,CAAC,MAAM,EAAE;IACnC,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,kBAAkB,GAAG,SAAS,CAEjC;AAID;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAChD,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC,GAAG,MAAM,GAAG,SAAS,CAUrB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CACxB,GAAG;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,kBAAkB,CAAA;CAAE,CA0B3F;AAID,yEAAyE;AACzE,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,eAAe,GAAG,iBAAiB,GAAG,cAAc,GAAG,WAAW,CAAC;IACnG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC7C,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IAChC,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,SAAS,aAAa,EAAE,CAuD3B"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Extension artifacts in the migrate pipeline (extensions.md §3 migrate plane).
3
+ *
4
+ * Extensions own database objects the core differ does not model: CREATE
5
+ * EXTENSION, generated tsvector columns, FTS5 shadow tables + triggers,
6
+ * specialty indexes (gin_trgm_ops, hnsw, bm25, FULLTEXT). The contract:
7
+ *
8
+ * 1. `collectExtensionArtifacts` asks each configured extension for its
9
+ * artifacts (dialect-correct, idempotent SQL + a structured owner).
10
+ * 2. `stripExtensionArtifacts` removes owned objects from the INTROSPECTED
11
+ * IR before diffing, so the core differ never schedules their drop —
12
+ * the introspector-representation-is-the-contract rule (LEARNINGS).
13
+ * 3. `planMissingArtifacts` decides which artifacts must be created, by
14
+ * checking the introspected IR for their owners (columns, indexes,
15
+ * tables by name); non-introspectable owners (postgres extensions,
16
+ * triggers) rely on their idempotent IF NOT EXISTS forms and always run.
17
+ *
18
+ * Removing a declaration does NOT auto-drop its artifacts (mirrors the v1
19
+ * phantom-join-table precedent) — `drop` SQL is carried for tooling, not
20
+ * scheduled by push.
21
+ */
22
+ import type { Dialect, ExtensionArtifact, SchemaIR, VibeExtension } from "@vibeorm/schema";
23
+ /** Artifacts of every configured extension for this schema, in order. */
24
+ export type CollectedArtifacts = {
25
+ /** CREATE EXTENSION-class artifacts — run BEFORE the core diff SQL. */
26
+ readonly setup: readonly ExtensionArtifact[];
27
+ /** Object artifacts (columns, indexes, shadow tables, triggers) — run AFTER. */
28
+ readonly objects: readonly ExtensionArtifact[];
29
+ };
30
+ export declare function collectExtensionArtifacts(params: {
31
+ schema: SchemaIR;
32
+ dialect: Dialect;
33
+ extensions: readonly VibeExtension[];
34
+ }): CollectedArtifacts;
35
+ /**
36
+ * Remove extension-owned objects from an INTROSPECTED SchemaIR so the core
37
+ * differ never sees them (they are neither dropped nor re-created by it).
38
+ */
39
+ export declare function stripExtensionArtifacts(params: {
40
+ schema: SchemaIR;
41
+ artifacts: readonly ExtensionArtifact[];
42
+ }): SchemaIR;
43
+ /** Owner presence the IR cannot answer, probed live by push (both optional). */
44
+ export type InstalledExtensionState = {
45
+ /** `SELECT extname FROM pg_extension` — postgres only. */
46
+ readonly pgExtensions?: ReadonlySet<string>;
47
+ /** `sqlite_master WHERE type='trigger'` names — sqlite only. */
48
+ readonly triggers?: ReadonlySet<string>;
49
+ };
50
+ /**
51
+ * The artifacts whose owner is missing from the introspected IR (must be
52
+ * created). Owners the IR cannot see — postgres extensions and triggers —
53
+ * consult the live-probed `installed` state when given, else always plan;
54
+ * their `create` SQL is idempotent (IF NOT EXISTS) so replays converge.
55
+ */
56
+ export declare function planMissingArtifacts(params: {
57
+ introspected: SchemaIR;
58
+ artifacts: readonly ExtensionArtifact[];
59
+ installed?: InstalledExtensionState;
60
+ }): ExtensionArtifact[];
61
+ /** Probe live owner state the IR cannot carry (used by push before planning). */
62
+ export declare function probeInstalledExtensionState(params: {
63
+ executor: (execParams: {
64
+ text: string;
65
+ values?: unknown[];
66
+ }) => Promise<Record<string, unknown>[]>;
67
+ dialect: Dialect;
68
+ artifacts: readonly ExtensionArtifact[];
69
+ }): Promise<InstalledExtensionState>;
70
+ /** Flatten artifacts to their create statements, in order. */
71
+ export declare function artifactCreateSql(params: {
72
+ artifacts: readonly ExtensionArtifact[];
73
+ }): string[];
74
+ //# sourceMappingURL=extensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EAEjB,QAAQ,EACR,aAAa,EACd,MAAM,iBAAiB,CAAC;AAIzB,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,uEAAuE;IACvE,QAAQ,CAAC,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC7C,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAChD,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAChD,MAAM,EAAE,QAAQ,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,SAAS,aAA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
4
+ *
5
+ * All three dialects are live: postgres/pglite, sqlite (table-rebuild recipe
6
+ * for the ALTERs sqlite cannot express) and mysql (non-transactional runner
7
+ * with per-statement resume). `renderSteps` / `push` / `pull` /
8
+ * `generateMigration` / `applyMigrations` route per dialect; the per-dialect
9
+ * modules live under src/ddl/ and src/introspect/.
10
+ */
11
+ export { describeStep } from "./types.ts";
12
+ export type { AlterColumnAspect, AppliedResult, IndexColumn, JoinTableEnd, MigrationFile, MigrationStatus, MigrationStep, PushResult, RecordedMigration, RecordedMigrationState, SqlExecutor, } from "./types.ts";
13
+ export { diffSchemas } from "./differ.ts";
14
+ export { detectImplicitM2MPairs } from "./relations.ts";
15
+ export type { ImplicitM2MPair } from "./relations.ts";
16
+ export { renderSteps } from "./ddl/render.ts";
17
+ export { introspectPostgres } from "./introspect/postgres.ts";
18
+ export { introspectSqlite } from "./introspect/sqlite.ts";
19
+ export { introspectMysql } from "./introspect/mysql.ts";
20
+ export { MIGRATIONS_TABLE_NAME, applyMigrations, ensureMigrationsTable, generateMigration, migrationChecksum, migrationStatus, recordedMigrations, resolveMigration, rollbackMigration, } from "./runner.ts";
21
+ export { EXECUTION_SIDECAR_FILENAME, EXECUTION_SIDECAR_VERSION, assertValidExecution, describeMigrationRisks, describeOperation, executionChecksumSuffix, isDefaultExecution, operationFor, parseExecutionSidecar, serializeExecutionSidecar, } from "./execution.ts";
22
+ export type { MigrationExecution, MigrationOperation, MigrationOperationBinding, MigrationRisk, MigrationTransactionMode, } from "./execution.ts";
23
+ export { establishOperationState } from "./recovery.ts";
24
+ export type { OperationState } from "./recovery.ts";
25
+ export { planRenames } from "./renames.ts";
26
+ export type { RenameIntent } from "./renames.ts";
27
+ export { generateDownMigration } from "./down.ts";
28
+ export type { DownMigrationFile } from "./down.ts";
29
+ export { pull, push } from "./push.ts";
30
+ export { artifactCreateSql, collectExtensionArtifacts, planMissingArtifacts, probeInstalledExtensionState, stripExtensionArtifacts, } from "./extensions.ts";
31
+ export type { CollectedArtifacts, InstalledExtensionState } from "./extensions.ts";
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,YAAY,EACZ,aAAa,EACb,eAAe,EACf,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,GACZ,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIxD,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAIrB,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,aAAa,EACb,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe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