You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
You can define @unique() @default(autoincrement()) on a field, but you cannot autoincrement with a constraint like tenantId or organizationId.
This is useful for things like accounting invoices that need a unique id (database) and a human-readable referenceId (UI) for users to reference.
It's also useful for jobs, e.g. Workday's "job requisition ID" (JR-ID) that candidates and recruiters can reference in a readable way, e.g. "J-012345".
Companies often require an internal increment to know which invoice, job, opening they might be on and what the next increment will be.
Describe the solution you'd like
Create a Zenstack feature that handles autoincrement on a field, taking a partition to autoincrement against. Proposed syntax:
modelInvoice {idString@id@default(uuid())tenantIdString// proposal 1:referenceIdInt@autoincrement(partition: tenantId)// or proposal 2:referenceIdInt@autoincrement(by: tenantId)@@unique([referenceId, tenantId])}
Simply increment to the last number, even if records are deleted in between (e.g. 1-2-[deleted]-4-5 increment to 6).
Describe alternatives you've considered
Originally I created a postgres sequence + nextval() but this requires setup for each tenant.
Database triggers
Dedicated sequencing table
Application-level sequence management (hacky findFirst... orderBy referenceId desc... return last result, increment by +1...)
The text was updated successfully, but these errors were encountered:
sajadmh
changed the title
[Feature Request] Tenant-based autoincrement (unique int autoincrement)
[Feature Request] Tenant-based autoincrement
Feb 5, 2025
sajadmh
changed the title
[Feature Request] Tenant-based autoincrement
[Feature Request] Tenant-based/partitioned autoincrement
Feb 5, 2025
Is your feature request related to a problem? Please describe.
You can define
@unique() @default(autoincrement())
on a field, but you cannot autoincrement with a constraint liketenantId
ororganizationId
.Companies often require an internal increment to know which invoice, job, opening they might be on and what the next increment will be.
Describe the solution you'd like
Create a Zenstack feature that handles autoincrement on a field, taking a partition to autoincrement against. Proposed syntax:
Simply increment to the last number, even if records are deleted in between (e.g. 1-2-[deleted]-4-5 increment to 6).
Describe alternatives you've considered
nextval()
but this requires setup for each tenant.referenceId
desc... return last result, increment by +1...)References
https://stackoverflow.com/questions/41336686/auto-increment-considering-tenant-id
https://stackoverflow.com/questions/51825936/auto-increment-ids-starting-at-1-per-tenant-in-a-single-database
The text was updated successfully, but these errors were encountered: