Skip to content

DB-native autonumber sequence (multi-instance correctness) #1603

Description

@xuyushun441-sys

Context

Follow-up from the autonumber generation fix in objectql (engine applyAutonumbers). Today, empty autonumber fields are generated before required-validation as max(existing)+1, seeded per object.field and incremented in memory.

Gap

  • The in-memory counter is correct for a single instance (re-seeds from max on restart; monotonic in-process), but two instances can collide.
  • The seed currently loads up to 5000 rows to compute max.

Proposal

Back autonumber with a persistent, atomically-incremented sequence at the driver layer (e.g. a sys_sequence row with UPDATE ... RETURNING value+1, or native DB sequences), so values are correct across instances. Replace the row-scan seed with a max() aggregate as an interim improvement.

Notes

  • Touches packages/objectql/src/engine.ts + drivers — hot files; dedicated, reviewed change.

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