|
| 1 | +--- |
| 2 | +"@objectstack/spec": major |
| 3 | +"@objectstack/metadata-core": patch |
| 4 | +--- |
| 5 | + |
| 6 | +refactor(spec)!: retire `indexes[].type` and `indexes[].partial` — two authorable index keys no driver ever read (#5248, #4943) |
| 7 | + |
| 8 | +`IndexSchema` declared five keys; only three of them ever reached a `CREATE |
| 9 | +INDEX`. `SqlDriver.syncDeclaredIndexes` builds every declared index through |
| 10 | +knex's `table.index(fields, name)` / `table.unique(fields, { indexName })`, and |
| 11 | +the drift differ's `DeclaredIndexInput` carries `name` / `fields` / `unique` / |
| 12 | +`nullSafeColumns`. So: |
| 13 | + |
| 14 | +- **`partial`** — documented as *"Partial index condition (SQL WHERE clause)"* — |
| 15 | + produced a **full** index with the predicate silently discarded. This was the |
| 16 | + damaging half, because it reads as a correctness control: the platform's own |
| 17 | + `sys_metadata` declared `partial: "state = 'active'"` for overlay uniqueness, |
| 18 | + and what the declaration alone materialized was an *unrestricted* unique index. |
| 19 | +- **`type`** additionally carried `.default('btree')`, so it appeared in **every** |
| 20 | + parse output of **every** index — an access-method knob that had never |
| 21 | + influenced a single statement, rendered as live configuration. (It was pinned |
| 22 | + as such in a `sys_presence` test, on an object that never declared it.) |
| 23 | + |
| 24 | +Both are the ADR-0078 no-silently-inert / ADR-0049 enforce-or-remove shape. |
| 25 | +Remove was chosen over enforce: enforcing needs per-dialect algorithm mapping |
| 26 | +(`gin`/`gist` Postgres-only, `fulltext` MySQL-family), raw-SQL `CREATE INDEX … |
| 27 | +WHERE` on the dialects that have partial indexes at all (MySQL does not), and a |
| 28 | +redesign of how `isSyncReproducibleIndex` excludes partial indexes from |
| 29 | +incremental sync — design cost for a capability with no demand. If a real need |
| 30 | +appears it returns enforce-first. |
| 31 | + |
| 32 | +## Migration |
| 33 | + |
| 34 | +| FROM | TO | |
| 35 | +| :--- | :--- | |
| 36 | +| `indexes: [{ fields: […], type: 'gin' }]` | `indexes: [{ fields: […] }]` — create the specialised index from a database-layer migration | |
| 37 | +| `indexes: [{ fields: […], partial: "state = 'active'" }]` | `indexes: [{ fields: […] }]` — issue `CREATE [UNIQUE] INDEX … WHERE …` from a runtime migration | |
| 38 | + |
| 39 | +**One-line fix: delete the key.** Neither removal changes any DDL, because no |
| 40 | +DDL ever depended on them — verified byte-for-byte against the `CREATE INDEX` |
| 41 | +statements SQLite actually stores |
| 42 | +(`packages/drivers/driver-sql/src/declared-index-retired-keys.test.ts`). |
| 43 | + |
| 44 | +Both capabilities remain available where they are implementable. The index |
| 45 | +method is the driver/dialect's choice. A partial index is issued as raw SQL from |
| 46 | +a runtime migration — exactly what `metadata-protocol`'s `ensureOverlayIndex` |
| 47 | +already does for `sys_metadata`, and what actually delivers that table's |
| 48 | +active-row-scoped uniqueness today. |
| 49 | + |
| 50 | +⚠️ **Not affected:** driver-sql's own `partial` flag (`parseIndexDdl` / |
| 51 | +`introspectIndexes` / `isSyncReproducibleIndex`). That is a boolean parsed back |
| 52 | +out of the *database's own* DDL for drift detection — the opposite direction — |
| 53 | +so migration-created partial indexes stay recognized and exempt from incremental |
| 54 | +sync, unchanged. |
| 55 | + |
| 56 | +## The retirement kit |
| 57 | + |
| 58 | +- `retiredKey()` tombstones at `IndexSchema` (the shape is deliberately |
| 59 | + `.strip()`, so a plain delete would swap one silent no-op for another): writing |
| 60 | + either key is now a `tsc` error and a parse error carrying the prescription. |
| 61 | + They sit at the bottom of the shape per the #5606 renderer note. |
| 62 | +- **ADR-0087 D2 conversion + D3 chain step** (`object-index-type-partial-removed`, |
| 63 | + `toMajor: 17`, wired into the existing step-17 chain): strips both keys from |
| 64 | + `objects[]` and `objectExtensions[]`; `os migrate meta --from 16` rewrites sources |
| 65 | + mechanically. A pure lossless delete — there was no effect to lose. |
| 66 | +- **Producers flipped:** `sys_metadata` (`idx_sys_metadata_overlay_active`, the |
| 67 | + case #4943 named) and `sys_view_definition` (`idx_sys_view_def_active`), both |
| 68 | + with their comments corrected to say what is actually materialized. |
| 69 | +- Published skill (`objectstack-data`), `content/docs/data-modeling/objects.mdx`, |
| 70 | + liveness ledger note and generated baselines updated. |
0 commit comments