Skip to content

[finding] os generate migration emits no declared index at all — a generated table carries none of the object's unique constraints, while driver-sql creates them #16317

Description

@os-litant

Found while closing the keyed half of #16091 (PR #16298). Not fixed there: that card is about the COLUMN, this is about the INDEX.

The measurement

Live PostgreSQL 16.13, one object driven through all three producers — driver-sql via initObjects, os generate migration --format sql via db.raw, and the typescript format by importing the emitted module and calling up(db). Object:

{ name: 'probe', fields: { keyed_unique: { type: 'text', unique: true, maxLength: 100 } } }

pg_indexes for each producer's schema afterwards:

driver   probe_pkey, uniq_probe_keyed_unique
sql gen  probe_pkey
ts gen   probe_pkey

The column itself now agrees in all three (character varying(100), after #16298). The CONSTRAINT does not exist in either generated table.

Why it matters, and why it is sharper now

Two rows with the same keyed_unique value are refused by the platform's table and accepted by both generated ones. A scaffold that creates the table for an object silently drops a uniqueness guarantee the object declares, and nothing reports it — the same shape as #16091's own hard-failure class, one declaration over.

It is sharper after #16298 because the generators now READ field.unique and indexes[] to size the column (indexedKeyColumns' key set is what the driver's text-family arm branches on). The key set is therefore already computed in generate.ts; the index it implies is still not emitted. driver-sql's own normalizers are uniqueIndexesFromFields (field-level unique, ADR-0120 D1/D3 scoping) and normalizeDeclaredIndex (object-level indexes[]), both exported from @objectstack/driver-sql.

Not free to answer, which is why this is filed rather than fixed

Reproduce

Drive the object above into three PostgreSQL schemas, one per producer, and read pg_indexes for each.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions