@metaobjectsdev/sdk 0.20.12-rc.1 → 0.20.14-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.
|
@@ -147,11 +147,20 @@ What this means in practice:
|
|
|
147
147
|
it. You point it at the same database your server connects to:
|
|
148
148
|
|
|
149
149
|
```
|
|
150
|
-
meta migrate --db postgresql://... --
|
|
151
|
-
|
|
152
|
-
meta migrate --
|
|
150
|
+
meta migrate --from-db --db postgresql://... --dialect postgres --slug init --apply
|
|
151
|
+
# first migration on a brand-new database
|
|
152
|
+
meta migrate --dialect postgres --slug add-user-shipping # everyday: emit migration SQL
|
|
153
|
+
meta migrate --dialect postgres --slug add-user-shipping --apply --db postgresql://...
|
|
154
|
+
# ...and apply it
|
|
155
|
+
meta migrate --dialect postgres --slug add-user-shipping --dry-run # preview without writing
|
|
153
156
|
```
|
|
154
157
|
|
|
158
|
+
Always pass `--dialect` — it selects the diff pipeline, not just the SQL flavor.
|
|
159
|
+
It is *required* on the offline path and on `baseline`; with `--db` the CLI can
|
|
160
|
+
auto-detect it from the URL scheme, but being explicit keeps the two paths
|
|
161
|
+
reading the same. Do **not** run `meta migrate baseline` on a database that does
|
|
162
|
+
not exist yet; see `references/migration.md`.
|
|
163
|
+
|
|
155
164
|
- Dialects: `postgres` (default), `sqlite`, and `d1` (Cloudflare D1, TS-only).
|
|
156
165
|
- The JVM and Python ports have **no** migration command of their own — their
|
|
157
166
|
former migrate goals/modules were removed, and (ADR-0015 Decision 2) the JVM
|
|
@@ -40,25 +40,35 @@ active format, so callers can parse them without scraping stderr.
|
|
|
40
40
|
|
|
41
41
|
## The workflow
|
|
42
42
|
|
|
43
|
-
### Fresh database:
|
|
43
|
+
### Fresh database: create the tables with `--from-db … --apply`
|
|
44
44
|
|
|
45
45
|
The default `meta migrate` path is **offline** — it diffs metadata against a
|
|
46
46
|
committed schema snapshot rather than the live DB. On a fresh database there is no
|
|
47
|
-
snapshot yet
|
|
47
|
+
snapshot yet, so the first command introspects the (empty) database instead:
|
|
48
48
|
|
|
49
49
|
```bash
|
|
50
|
-
meta migrate
|
|
51
|
-
meta migrate baseline --dialect postgres # same for Postgres
|
|
52
|
-
meta migrate baseline --from-db --db postgresql://... --dialect postgres
|
|
53
|
-
# alternative: seed from live DB (for existing schemas)
|
|
50
|
+
meta migrate --from-db --db file:dev.sqlite --dialect sqlite --slug init --apply
|
|
54
51
|
```
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
That diffs metadata against what is *actually* in the database (nothing), emits the
|
|
54
|
+
full `CREATE TABLE` set, applies it, and records the resulting snapshot — so the
|
|
55
|
+
everyday offline flow works immediately afterwards, with no extra step.
|
|
56
|
+
|
|
57
|
+
**Do NOT reach for `meta migrate baseline` on a database that does not exist yet.**
|
|
58
|
+
An offline baseline derives the "existing" snapshot from your *metadata*, recording
|
|
59
|
+
your entities' target shape as already applied: no table is ever created, every
|
|
60
|
+
later `meta migrate` reports `no changes` (exit 0), and the failure only surfaces at
|
|
61
|
+
the API layer as `no such table`. The CLI now refuses an offline baseline when it can
|
|
62
|
+
prove the target `--db` is empty, and its no-snapshot hint routes to the `--from-db`
|
|
63
|
+
command above.
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
`baseline` is for the other case — **adopting** metadata onto a database that already
|
|
66
|
+
has its schema (a pre-existing, non-MetaObjects setup), where you want to record
|
|
67
|
+
current state without emitting any DDL:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
meta migrate baseline --from-db --db postgresql://... --dialect postgres
|
|
71
|
+
```
|
|
62
72
|
|
|
63
73
|
### Generating a migration
|
|
64
74
|
|
|
@@ -66,11 +76,18 @@ next-step hint pointing to the exact `baseline` command.
|
|
|
66
76
|
committed snapshot). The engine emits paired `up.sql` + `down.sql`:
|
|
67
77
|
|
|
68
78
|
```bash
|
|
69
|
-
meta migrate --
|
|
70
|
-
meta migrate --
|
|
71
|
-
meta migrate --
|
|
79
|
+
meta migrate --dialect postgres --slug add-user-shipping # offline: diff vs the committed snapshot
|
|
80
|
+
meta migrate --dialect postgres --slug add-user-shipping --dry-run # preview without writing
|
|
81
|
+
meta migrate --from-db --db postgresql://... --dialect postgres --slug add-user-shipping
|
|
82
|
+
# diff vs the LIVE database instead
|
|
72
83
|
```
|
|
73
84
|
|
|
85
|
+
`--dialect` is load-bearing — it selects the diff pipeline, not just the SQL
|
|
86
|
+
flavor. It is *required* offline and on `baseline`; with `--db` it is
|
|
87
|
+
auto-detected from the URL scheme. The default path is offline (`--db` is
|
|
88
|
+
ignored without `--from-db` or `--apply`); pass `--from-db` when you want the
|
|
89
|
+
diff taken against the live database.
|
|
90
|
+
|
|
74
91
|
2. **Review the SQL.** Read the emitted `up.sql` (forward) and `down.sql`
|
|
75
92
|
(rollback) before applying. Destructive changes (drop column / drop table) are
|
|
76
93
|
opt-in — the engine blocks them unless explicitly allowed, and routes ambiguous
|
|
@@ -80,7 +97,10 @@ next-step hint pointing to the exact `baseline` command.
|
|
|
80
97
|
a ledger table:
|
|
81
98
|
|
|
82
99
|
```bash
|
|
83
|
-
meta migrate --db postgresql://... --apply
|
|
100
|
+
meta migrate --dialect postgres --slug add-user-shipping --db postgresql://... --apply
|
|
101
|
+
# generate ...and apply it
|
|
102
|
+
meta migrate apply-pending --db postgresql://... --dialect postgres
|
|
103
|
+
# replay committed migrations, no diff (fresh DB / CI)
|
|
84
104
|
meta migrate --db postgresql://... --rollback <target> # run down.sql for migrations newer than <target>
|
|
85
105
|
meta migrate --db postgresql://... --rollback "" # roll back everything (empty target)
|
|
86
106
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metaobjectsdev/sdk",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.14-rc.1",
|
|
4
4
|
"description": "Workspace helpers and agent-docs utilities for MetaObjects projects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@metaobjectsdev/metadata": "0.20.
|
|
59
|
+
"@metaobjectsdev/metadata": "0.20.14-rc.1",
|
|
60
60
|
"zod": "^3.23.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|