@metaobjectsdev/migrate-ts 0.5.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.
- package/LICENSE +189 -0
- package/README.md +73 -0
- package/dist/diff/index.d.ts +30 -0
- package/dist/diff/index.d.ts.map +1 -0
- package/dist/diff/index.js +226 -0
- package/dist/diff/index.js.map +1 -0
- package/dist/diff/rename-heuristic.d.ts +23 -0
- package/dist/diff/rename-heuristic.d.ts.map +1 -0
- package/dist/diff/rename-heuristic.js +236 -0
- package/dist/diff/rename-heuristic.js.map +1 -0
- package/dist/diff/status.d.ts +8 -0
- package/dist/diff/status.d.ts.map +1 -0
- package/dist/diff/status.js +53 -0
- package/dist/diff/status.js.map +1 -0
- package/dist/emit/index.d.ts +17 -0
- package/dist/emit/index.d.ts.map +1 -0
- package/dist/emit/index.js +18 -0
- package/dist/emit/index.js.map +1 -0
- package/dist/emit/postgres.d.ts +3 -0
- package/dist/emit/postgres.d.ts.map +1 -0
- package/dist/emit/postgres.js +181 -0
- package/dist/emit/postgres.js.map +1 -0
- package/dist/emit/sqlite.d.ts +3 -0
- package/dist/emit/sqlite.d.ts.map +1 -0
- package/dist/emit/sqlite.js +302 -0
- package/dist/emit/sqlite.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +54 -0
- package/dist/errors.js.map +1 -0
- package/dist/expected-schema.d.ts +15 -0
- package/dist/expected-schema.d.ts.map +1 -0
- package/dist/expected-schema.js +243 -0
- package/dist/expected-schema.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/introspect/index.d.ts +6 -0
- package/dist/introspect/index.d.ts.map +1 -0
- package/dist/introspect/index.js +11 -0
- package/dist/introspect/index.js.map +1 -0
- package/dist/introspect/postgres.d.ts +57 -0
- package/dist/introspect/postgres.d.ts.map +1 -0
- package/dist/introspect/postgres.js +339 -0
- package/dist/introspect/postgres.js.map +1 -0
- package/dist/introspect/sqlite.d.ts +4 -0
- package/dist/introspect/sqlite.d.ts.map +1 -0
- package/dist/introspect/sqlite.js +192 -0
- package/dist/introspect/sqlite.js.map +1 -0
- package/dist/source-aware-diff.d.ts +20 -0
- package/dist/source-aware-diff.d.ts.map +1 -0
- package/dist/source-aware-diff.js +24 -0
- package/dist/source-aware-diff.js.map +1 -0
- package/dist/sql-type.d.ts +45 -0
- package/dist/sql-type.d.ts.map +1 -0
- package/dist/sql-type.js +76 -0
- package/dist/sql-type.js.map +1 -0
- package/dist/types.d.ts +223 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/view-ddl-postgres.d.ts +4 -0
- package/dist/view-ddl-postgres.d.ts.map +1 -0
- package/dist/view-ddl-postgres.js +13 -0
- package/dist/view-ddl-postgres.js.map +1 -0
- package/dist/view-ddl-sqlite.d.ts +3 -0
- package/dist/view-ddl-sqlite.d.ts.map +1 -0
- package/dist/view-ddl-sqlite.js +7 -0
- package/dist/view-ddl-sqlite.js.map +1 -0
- package/dist/view-diff.d.ts +13 -0
- package/dist/view-diff.d.ts.map +1 -0
- package/dist/view-diff.js +42 -0
- package/dist/view-diff.js.map +1 -0
- package/dist/write-migration.d.ts +19 -0
- package/dist/write-migration.d.ts.map +1 -0
- package/dist/write-migration.js +34 -0
- package/dist/write-migration.js.map +1 -0
- package/package.json +50 -0
- package/src/diff/index.ts +294 -0
- package/src/diff/rename-heuristic.ts +265 -0
- package/src/diff/status.ts +55 -0
- package/src/emit/index.ts +38 -0
- package/src/emit/postgres.ts +189 -0
- package/src/emit/sqlite.ts +322 -0
- package/src/errors.ts +58 -0
- package/src/expected-schema.ts +326 -0
- package/src/index.ts +49 -0
- package/src/introspect/index.ts +14 -0
- package/src/introspect/postgres.ts +428 -0
- package/src/introspect/sqlite.ts +216 -0
- package/src/source-aware-diff.ts +49 -0
- package/src/sql-type.ts +91 -0
- package/src/types.ts +174 -0
- package/src/view-ddl-postgres.ts +15 -0
- package/src/view-ddl-sqlite.ts +7 -0
- package/src/view-diff.ts +55 -0
- package/src/write-migration.ts +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other transformations
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of recording and
|
|
55
|
+
discussing modifications to the Work, but excluding communication that
|
|
56
|
+
is conspicuously marked or designated in writing by the copyright owner
|
|
57
|
+
as "Not a Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or contributory
|
|
82
|
+
patent infringement, then any patent licenses granted to You under
|
|
83
|
+
this License for that Work shall terminate as of the date such
|
|
84
|
+
litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or in addition to the
|
|
115
|
+
NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
You may add Your own license statement for Your modifications and
|
|
119
|
+
may provide additional grant of rights to use, reproduce, modify,
|
|
120
|
+
prepare derivative works of, distribute, and sublicense such modifications,
|
|
121
|
+
as an additional requirement of this License.
|
|
122
|
+
|
|
123
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
124
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
125
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
126
|
+
this License, without any additional terms or conditions.
|
|
127
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
128
|
+
the terms of any separate license agreement you may have executed
|
|
129
|
+
with Licensor regarding such Contributions.
|
|
130
|
+
|
|
131
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
132
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
133
|
+
except as required for reasonable and customary use in describing the
|
|
134
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
137
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
138
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
139
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
140
|
+
implied, including, without limitation, any conditions of TITLE,
|
|
141
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
142
|
+
PURPOSE. You are solely responsible for determining the
|
|
143
|
+
appropriateness of using or reproducing the Work and assume any
|
|
144
|
+
risks associated with Your exercise of permissions under this License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
147
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
148
|
+
unless required by applicable law (such as deliberate and grossly
|
|
149
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
150
|
+
liable to You for damages, including any direct, indirect, special,
|
|
151
|
+
incidental, or exemplary damages of any character arising as a
|
|
152
|
+
result of this License or out of the use or inability to use the
|
|
153
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
154
|
+
work stoppage, computer failure or malfunction, or all other
|
|
155
|
+
commercial damages or losses), even if such Contributor has been
|
|
156
|
+
advised of the possibility of such damages.
|
|
157
|
+
|
|
158
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
159
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
160
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
161
|
+
or other liability obligations and/or rights consistent with this
|
|
162
|
+
License. However, in accepting such obligations, You may offer
|
|
163
|
+
only obligations consistent to this License provided that the
|
|
164
|
+
obligations are consistent with this License.
|
|
165
|
+
|
|
166
|
+
END OF TERMS AND CONDITIONS
|
|
167
|
+
|
|
168
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
169
|
+
|
|
170
|
+
To apply the Apache License to your work, attach the following
|
|
171
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
172
|
+
replaced with your own identifying information. (Don't include
|
|
173
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
174
|
+
comment syntax for the file format in question. Also add information
|
|
175
|
+
on how to contact you electronically and/or by mail.
|
|
176
|
+
|
|
177
|
+
Copyright 2026 MetaObjects Contributors
|
|
178
|
+
|
|
179
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
180
|
+
you may not use this file except in compliance with the License.
|
|
181
|
+
You may obtain a copy of the License at
|
|
182
|
+
|
|
183
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
184
|
+
|
|
185
|
+
Unless required by applicable law or agreed to in writing, software
|
|
186
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
187
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
188
|
+
See the License for the specific language governing permissions and
|
|
189
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @metaobjectsdev/migrate-ts
|
|
2
|
+
|
|
3
|
+
Schema migration tool for MetaObjects-driven projects.
|
|
4
|
+
|
|
5
|
+
Compares loaded MetaObjects metadata against a live Postgres or SQLite (libsql/Turso) database
|
|
6
|
+
and emits paired `up.sql` + `down.sql` migration files.
|
|
7
|
+
|
|
8
|
+
**Status:** v0.3. TS reference implementation; emits migration SQL but does not yet apply against the DB.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @metaobjectsdev/migrate-ts
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { Kysely } from "kysely";
|
|
20
|
+
import { LibsqlDialect } from "@libsql/kysely-libsql";
|
|
21
|
+
import { FileMetaDataLoader } from "@metaobjectsdev/metadata/core";
|
|
22
|
+
import {
|
|
23
|
+
buildExpectedSchema, introspectSqlite, diff, emit, writeMigration,
|
|
24
|
+
} from "@metaobjectsdev/migrate-ts";
|
|
25
|
+
|
|
26
|
+
// 1. Load metadata.
|
|
27
|
+
const { root: metadata } = await new FileMetaDataLoader().loadDirectory("./metaobjects");
|
|
28
|
+
|
|
29
|
+
// 2. Connect to live DB.
|
|
30
|
+
const db = new Kysely({ dialect: new LibsqlDialect({ url: "file:./local.db" }) });
|
|
31
|
+
|
|
32
|
+
// 3. Introspect + diff.
|
|
33
|
+
const expected = buildExpectedSchema(metadata);
|
|
34
|
+
const actual = await introspectSqlite(db);
|
|
35
|
+
const result = await diff({
|
|
36
|
+
expected, actual,
|
|
37
|
+
allow: { dropColumn: false, dropTable: false },
|
|
38
|
+
onAmbiguous: async (q) => "rename", // or prompt the user; "drop+add"; "abort"
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (result.blocked.length > 0) {
|
|
42
|
+
console.error("Blocked changes:", result.blocked);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 4. Emit + write.
|
|
47
|
+
const sql = emit(result.changes, { dialect: "sqlite", expectedSchema: expected, actualMeta: actual.meta });
|
|
48
|
+
await writeMigration(sql, { dir: ".metaobjects/migrations", slug: "add-customer-shipping" });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Design
|
|
52
|
+
|
|
53
|
+
- Five-stage pure pipeline; library has no CLI dependencies.
|
|
54
|
+
- Same `SchemaSnapshot` shape from metadata-side and DB-side; diff is symmetric.
|
|
55
|
+
- Canonical `SqlType` (dialect-neutral); per-dialect renderer in emit.
|
|
56
|
+
- Postgres uses native ALTERs; SQLite uses native ALTERs where supported (≥ 3.35) and bundles
|
|
57
|
+
recreate-and-copy per table when needed (column type, nullable, default, FK changes).
|
|
58
|
+
- Rename detection via heuristic (Levenshtein on column names, column-set overlap on tables)
|
|
59
|
+
+ `onAmbiguous` callback — library doesn't prompt; CLI in SP5 wires the prompt.
|
|
60
|
+
- Per-change-kind allow flags for destructive opt-in.
|
|
61
|
+
|
|
62
|
+
## Not yet shipped
|
|
63
|
+
|
|
64
|
+
- `meta migrate --apply` (apply migrations against the DB).
|
|
65
|
+
- Migration history table.
|
|
66
|
+
- Triggers, generated columns, partial indexes, exclusion constraints, check constraints.
|
|
67
|
+
- MySQL.
|
|
68
|
+
- Data migrations (column-type changes that need data transformation: error with hint).
|
|
69
|
+
- Multi-step migration scaffolding (add nullable → backfill → set notnull).
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
Apache-2.0.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SchemaSnapshot, DiffResult, AllowOptions, AmbiguousCallback } from "../types.js";
|
|
2
|
+
export interface DiffArgs {
|
|
3
|
+
expected: SchemaSnapshot;
|
|
4
|
+
actual: SchemaSnapshot;
|
|
5
|
+
allow?: AllowOptions;
|
|
6
|
+
onAmbiguous?: AmbiguousCallback;
|
|
7
|
+
/**
|
|
8
|
+
* Table-name patterns to ignore on both sides of the diff. Tables matching
|
|
9
|
+
* any pattern are excluded from comparison — neither create-table nor
|
|
10
|
+
* drop-table changes are emitted for them, and they're omitted from index/
|
|
11
|
+
* fk passes. Supports exact names and `*` glob wildcards.
|
|
12
|
+
*
|
|
13
|
+
* Defaults to [`__drizzle_migrations`] when omitted so the Drizzle migration-
|
|
14
|
+
* tracking table doesn't surface as a drop. Pass `[]` explicitly to disable
|
|
15
|
+
* the default. Pass additional patterns to extend.
|
|
16
|
+
*/
|
|
17
|
+
ignoreTables?: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Compares an expected schema (from metadata) against an actual schema (from introspection)
|
|
21
|
+
* and produces the change list to bring actual → expected. Always returns a Promise.
|
|
22
|
+
*
|
|
23
|
+
* Per spec §6.
|
|
24
|
+
*
|
|
25
|
+
* Accepts either the full DiffArgs object, or positional (expected, actual[, opts]) for
|
|
26
|
+
* convenience in tests and simple callers.
|
|
27
|
+
*/
|
|
28
|
+
export declare function diff(args: DiffArgs): Promise<DiffResult>;
|
|
29
|
+
export declare function diff(expected: SchemaSnapshot, actual: SchemaSnapshot, opts?: Omit<DiffArgs, "expected" | "actual">): Promise<DiffResult>;
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/diff/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACQ,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAClE,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,MAAM,EAAE,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAgDD;;;;;;;;GAQG;AACH,wBAAsB,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAChE,wBAAsB,IAAI,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { sqlTypeEquals } from "../sql-type.js";
|
|
2
|
+
import { applyStatus } from "./status.js";
|
|
3
|
+
import { detectColumnRenames, detectTableRenames } from "./rename-heuristic.js";
|
|
4
|
+
import { DEFAULT_DB_SCHEMA_POSTGRES } from "@metaobjectsdev/metadata";
|
|
5
|
+
const ALLOWED = { state: "allowed" };
|
|
6
|
+
/**
|
|
7
|
+
* Default ignore-table patterns. Catches migration-tracking and replication
|
|
8
|
+
* sidecar tables that downstream tools (Drizzle, litestream) create automatically.
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_IGNORE_TABLES = [
|
|
11
|
+
"__drizzle_migrations",
|
|
12
|
+
"_litestream_*",
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Normalize undefined schema to "public" (Postgres default) for comparison purposes.
|
|
16
|
+
* Allows snapshots from buildExpectedSchema (often undefined) to compare equal to
|
|
17
|
+
* snapshots from introspect (always populated for Postgres).
|
|
18
|
+
*
|
|
19
|
+
* For SQLite (no schema concept), every table has schema=undefined, so this maps
|
|
20
|
+
* all tables to the same "public." prefix — harmless and preserves existing behavior.
|
|
21
|
+
*/
|
|
22
|
+
function tableIdentity(table) {
|
|
23
|
+
return (table.schema ?? DEFAULT_DB_SCHEMA_POSTGRES) + "." + table.name;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build the optional-schema spread used when constructing Change records.
|
|
27
|
+
* Required because `exactOptionalPropertyTypes: true` rejects explicit `undefined`
|
|
28
|
+
* for an optional field — we either include the key or we don't.
|
|
29
|
+
*/
|
|
30
|
+
function schemaSpread(schema) {
|
|
31
|
+
return schema !== undefined ? { schema } : {};
|
|
32
|
+
}
|
|
33
|
+
function tableMatchesPattern(name, pattern) {
|
|
34
|
+
if (pattern.includes("*")) {
|
|
35
|
+
const regex = new RegExp("^" + pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*") + "$");
|
|
36
|
+
return regex.test(name);
|
|
37
|
+
}
|
|
38
|
+
return name === pattern;
|
|
39
|
+
}
|
|
40
|
+
function shouldIgnoreTable(name, patterns) {
|
|
41
|
+
return patterns.some((p) => tableMatchesPattern(name, p));
|
|
42
|
+
}
|
|
43
|
+
export async function diff(argsOrExpected, actualMaybe, optsMaybe) {
|
|
44
|
+
// Normalize args.
|
|
45
|
+
const args = isDiffArgs(argsOrExpected)
|
|
46
|
+
? argsOrExpected
|
|
47
|
+
: { expected: argsOrExpected, actual: actualMaybe, ...(optsMaybe ?? {}) };
|
|
48
|
+
const changes = [];
|
|
49
|
+
const ignorePatterns = args.ignoreTables ?? DEFAULT_IGNORE_TABLES;
|
|
50
|
+
// Key tables on (schema, name) identity — same table name in different schemas
|
|
51
|
+
// are distinct entities. tableIdentity normalizes undefined → "public".
|
|
52
|
+
const expectedTables = new Map(args.expected.tables
|
|
53
|
+
.filter((t) => !shouldIgnoreTable(t.name, ignorePatterns))
|
|
54
|
+
.map((t) => [tableIdentity(t), t]));
|
|
55
|
+
const actualTables = new Map(args.actual.tables
|
|
56
|
+
.filter((t) => !shouldIgnoreTable(t.name, ignorePatterns))
|
|
57
|
+
.map((t) => [tableIdentity(t), t]));
|
|
58
|
+
// Pass 1: tables present in expected but not actual → create-table + add-index + add-fk
|
|
59
|
+
// Indexes and FKs are separate SQL statements (not part of CREATE TABLE), so they
|
|
60
|
+
// must be emitted as individual changes even for brand-new tables.
|
|
61
|
+
for (const [id, table] of expectedTables) {
|
|
62
|
+
if (!actualTables.has(id)) {
|
|
63
|
+
changes.push({ kind: "create-table", table, ...schemaSpread(table.schema), status: ALLOWED });
|
|
64
|
+
for (const index of table.indexes) {
|
|
65
|
+
changes.push({
|
|
66
|
+
kind: "add-index", table: table.name, ...schemaSpread(table.schema),
|
|
67
|
+
index, status: ALLOWED,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
for (const fk of table.foreignKeys) {
|
|
71
|
+
changes.push({
|
|
72
|
+
kind: "add-fk", table: table.name, ...schemaSpread(table.schema),
|
|
73
|
+
fk, status: ALLOWED,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Pass 1b: tables present in actual but not expected → drop-table
|
|
79
|
+
// Attach _columns side-channel so detectTableRenames can compare column sets.
|
|
80
|
+
for (const [id, t] of actualTables) {
|
|
81
|
+
if (!expectedTables.has(id)) {
|
|
82
|
+
const dropChange = {
|
|
83
|
+
kind: "drop-table", table: t.name, ...schemaSpread(t.schema), status: ALLOWED,
|
|
84
|
+
};
|
|
85
|
+
dropChange._columns = t.columns;
|
|
86
|
+
changes.push(dropChange);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Pass 2: tables in both → compare columns/indexes/FKs
|
|
90
|
+
for (const [id, expectedTable] of expectedTables) {
|
|
91
|
+
const actualTable = actualTables.get(id);
|
|
92
|
+
if (!actualTable)
|
|
93
|
+
continue;
|
|
94
|
+
diffTableColumns(expectedTable, actualTable, changes);
|
|
95
|
+
diffTableIndexes(expectedTable, actualTable, changes);
|
|
96
|
+
diffTableForeignKeys(expectedTable, actualTable, changes);
|
|
97
|
+
}
|
|
98
|
+
// Pass 3: detect table renames BEFORE column renames — so a renamed table's
|
|
99
|
+
// columns are not scanned as orphaned drop/add pairs.
|
|
100
|
+
await detectTableRenames(changes, args.onAmbiguous);
|
|
101
|
+
await detectColumnRenames(changes, args.onAmbiguous);
|
|
102
|
+
// Strip the rename-detection side-channel fields before status assignment / return.
|
|
103
|
+
for (const c of changes) {
|
|
104
|
+
delete c._sqlType;
|
|
105
|
+
delete c._nullable;
|
|
106
|
+
delete c._columns;
|
|
107
|
+
}
|
|
108
|
+
applyStatus(changes, args.allow ?? {});
|
|
109
|
+
return { changes, blocked: changes.filter((c) => c.status.state === "blocked") };
|
|
110
|
+
}
|
|
111
|
+
function isDiffArgs(x) {
|
|
112
|
+
return "expected" in x && "actual" in x;
|
|
113
|
+
}
|
|
114
|
+
function diffTableColumns(expected, actual, changes) {
|
|
115
|
+
const table = expected.name;
|
|
116
|
+
const sx = schemaSpread(expected.schema);
|
|
117
|
+
const expectedCols = new Map(expected.columns.map((c) => [c.name, c]));
|
|
118
|
+
const actualCols = new Map(actual.columns.map((c) => [c.name, c]));
|
|
119
|
+
for (const [name, ec] of expectedCols) {
|
|
120
|
+
const ac = actualCols.get(name);
|
|
121
|
+
if (!ac) {
|
|
122
|
+
changes.push({ kind: "add-column", table, ...sx, column: ec, status: ALLOWED });
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
// Compare type, nullable, default — emit per-aspect change.
|
|
126
|
+
if (!sqlTypeEquals(ec.sqlType, ac.sqlType)) {
|
|
127
|
+
changes.push({
|
|
128
|
+
kind: "change-column-type", table, ...sx, column: name,
|
|
129
|
+
from: ac.sqlType, to: ec.sqlType, status: ALLOWED,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (ec.nullable !== ac.nullable) {
|
|
133
|
+
changes.push({
|
|
134
|
+
kind: "change-column-nullable", table, ...sx, column: name,
|
|
135
|
+
from: ac.nullable, to: ec.nullable, status: ALLOWED,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (!columnDefaultsEqual(ec.default, ac.default)) {
|
|
139
|
+
const change = {
|
|
140
|
+
kind: "change-column-default", table, ...sx, column: name,
|
|
141
|
+
status: ALLOWED,
|
|
142
|
+
...(ac.default !== undefined ? { from: ac.default } : {}),
|
|
143
|
+
...(ec.default !== undefined ? { to: ec.default } : {}),
|
|
144
|
+
};
|
|
145
|
+
changes.push(change);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const [name, ac] of actualCols) {
|
|
149
|
+
if (!expectedCols.has(name)) {
|
|
150
|
+
const dropChange = {
|
|
151
|
+
kind: "drop-column", table, ...sx, column: name, status: ALLOWED,
|
|
152
|
+
};
|
|
153
|
+
dropChange._sqlType = ac.sqlType;
|
|
154
|
+
dropChange._nullable = ac.nullable;
|
|
155
|
+
changes.push(dropChange);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function diffTableIndexes(expected, actual, changes) {
|
|
160
|
+
const table = expected.name;
|
|
161
|
+
const sx = schemaSpread(expected.schema);
|
|
162
|
+
const expectedIdx = new Map(expected.indexes.map((i) => [i.name, i]));
|
|
163
|
+
const actualIdx = new Map(actual.indexes.map((i) => [i.name, i]));
|
|
164
|
+
for (const [name, ix] of expectedIdx) {
|
|
165
|
+
const a = actualIdx.get(name);
|
|
166
|
+
if (!a) {
|
|
167
|
+
changes.push({ kind: "add-index", table, ...sx, index: ix, status: ALLOWED });
|
|
168
|
+
}
|
|
169
|
+
else if (!indexEquals(ix, a)) {
|
|
170
|
+
// Index shape changed: drop + add (atomic from caller's perspective).
|
|
171
|
+
changes.push({ kind: "drop-index", table, ...sx, index: name, status: ALLOWED });
|
|
172
|
+
changes.push({ kind: "add-index", table, ...sx, index: ix, status: ALLOWED });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const [name] of actualIdx) {
|
|
176
|
+
if (!expectedIdx.has(name)) {
|
|
177
|
+
changes.push({ kind: "drop-index", table, ...sx, index: name, status: ALLOWED });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function diffTableForeignKeys(expected, actual, changes) {
|
|
182
|
+
const table = expected.name;
|
|
183
|
+
const sx = schemaSpread(expected.schema);
|
|
184
|
+
const expectedFk = new Map(expected.foreignKeys.map((f) => [f.name, f]));
|
|
185
|
+
const actualFk = new Map(actual.foreignKeys.map((f) => [f.name, f]));
|
|
186
|
+
for (const [name, fk] of expectedFk) {
|
|
187
|
+
const a = actualFk.get(name);
|
|
188
|
+
if (!a) {
|
|
189
|
+
changes.push({ kind: "add-fk", table, ...sx, fk, status: ALLOWED });
|
|
190
|
+
}
|
|
191
|
+
else if (!fkEquals(fk, a)) {
|
|
192
|
+
changes.push({ kind: "drop-fk", table, ...sx, fk: name, status: ALLOWED });
|
|
193
|
+
changes.push({ kind: "add-fk", table, ...sx, fk, status: ALLOWED });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
for (const [name] of actualFk) {
|
|
197
|
+
if (!expectedFk.has(name)) {
|
|
198
|
+
changes.push({ kind: "drop-fk", table, ...sx, fk: name, status: ALLOWED });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function columnDefaultsEqual(a, b) {
|
|
203
|
+
if (a === undefined && b === undefined)
|
|
204
|
+
return true;
|
|
205
|
+
if (a === undefined || b === undefined)
|
|
206
|
+
return false;
|
|
207
|
+
return a.kind === b.kind && a.value === b.value;
|
|
208
|
+
}
|
|
209
|
+
function indexEquals(a, b) {
|
|
210
|
+
if (a.unique !== b.unique)
|
|
211
|
+
return false;
|
|
212
|
+
if (a.columns.length !== b.columns.length)
|
|
213
|
+
return false;
|
|
214
|
+
return a.columns.every((c, i) => c === b.columns[i]);
|
|
215
|
+
}
|
|
216
|
+
function fkEquals(a, b) {
|
|
217
|
+
if (a.refTable !== b.refTable)
|
|
218
|
+
return false;
|
|
219
|
+
if (a.onDelete !== b.onDelete || a.onUpdate !== b.onUpdate)
|
|
220
|
+
return false;
|
|
221
|
+
if (a.columns.length !== b.columns.length || a.refColumns.length !== b.refColumns.length)
|
|
222
|
+
return false;
|
|
223
|
+
return a.columns.every((c, i) => c === b.columns[i])
|
|
224
|
+
&& a.refColumns.every((c, i) => c === b.refColumns[i]);
|
|
225
|
+
}
|
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,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,QAAQ,CAAC,CAAe,EAAE,CAAe;IAChD,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IACzE,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,UAAU,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACvG,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;WAC7C,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Change, AmbiguousCallback } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Mutates `changes` in place: detects (drop-table, create-table) pairs whose
|
|
4
|
+
* column sets have Jaccard similarity ≥ 0.8. Per spec §6.3.
|
|
5
|
+
*
|
|
6
|
+
* Must run BEFORE detectColumnRenames so a renamed table's columns aren't
|
|
7
|
+
* scanned as orphaned drop/add pairs.
|
|
8
|
+
*
|
|
9
|
+
* Side-channel: diff() attaches `_columns` to drop-table changes so this
|
|
10
|
+
* function has access to the dropped table's column list.
|
|
11
|
+
*/
|
|
12
|
+
export declare function detectTableRenames(changes: Change[], onAmbiguous: AmbiguousCallback | undefined): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Mutates `changes` in place: detects (drop-column 'old', add-column 'new') pairs
|
|
15
|
+
* on the same table that match the rename heuristic. Per spec §6.2.
|
|
16
|
+
*
|
|
17
|
+
* For each candidate: invokes onAmbiguous (default 'drop+add' if absent).
|
|
18
|
+
* - 'rename' → replace the pair with a single rename-column Change.
|
|
19
|
+
* - 'drop+add'→ leave both as-is.
|
|
20
|
+
* - 'abort' → throw.
|
|
21
|
+
*/
|
|
22
|
+
export declare function detectColumnRenames(changes: Change[], onAmbiguous: AmbiguousCallback | undefined): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=rename-heuristic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-heuristic.d.ts","sourceRoot":"","sources":["../../src/diff/rename-heuristic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EAAE,iBAAiB,EAE1B,MAAM,aAAa,CAAC;AAOrB;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EAAE,EACjB,WAAW,EAAE,iBAAiB,GAAG,SAAS,GACzC,OAAO,CAAC,IAAI,CAAC,CAyEf;AAwBD;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EAAE,EACjB,WAAW,EAAE,iBAAiB,GAAG,SAAS,GACzC,OAAO,CAAC,IAAI,CAAC,CA4Gf"}
|