Custom ID, Soft Delete, Optimistic Lock & Auto Field Fill
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 734
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
Description
Dear Sea-orm developers, hello. I have the following requests:
I would like to request support for the following features in SeaORM, with the ability to customize related fields and implement them via macro annotations:
- Custom ID Generation
-
Support custom primary key generation rules (e.g., distributed ID).
-
Auto-populate the primary key when inserting a new record.
-
Allow customization of the primary key field name (not limited to fixed names like
id).
- Soft Delete
-
Default value
0for the soft delete field on insertion; set to1instead of performing hard delete. -
Automatically add soft delete condition (e.g.,
is_deleted = 0) to all queries by default. -
Allow customization of the soft delete field name (e.g.,
deleted,is_removeinstead ofis_deleted).
- Optimistic Locking
-
Default version value
0on insertion with validation; auto increment version by1on update and soft delete. -
Allow customization of the version field name (e.g.,
lock_versioninstead ofversion).
- Auto Field Fill & Update
-
On insert: Auto populate
created_at,created_by, set soft delete field to default0, version field to default0. -
On update: Auto increment version, populate
updated_at,updated_by. -
On soft delete: Set soft delete field to
1, increment version, populateupdated_at,updated_by. -
Allow full customization of all auto-filled fields (e.g.,
create_timeinstead ofcreated_at,operatorinstead ofcreated_by).
Preferred Implementation Approach
These features are expected to be implemented through macro annotations (attributes) on entity fields, for example:
-
#[sea_orm(primary_key, generator = "distributed_id")]for custom ID generation
-
#[sea_orm(soft_delete, default = 0, deleted_value = 1)]for soft delete field
-
#[sea_orm(optimistic_lock, default = 0)]for version field
-
#[sea_orm(auto_fill = "created_at")]/#[sea_orm(auto_fill = "updated_by")]for auto-filled fields
Use Case
These features are widely used in enterprise applications and can greatly reduce boilerplate code for data integrity, traceability, and concurrency control. Customizable fields and macro-based implementation will make the features more flexible and adaptable to different project specifications.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or entry points. Start by reviewing the existing entity macro annotations and the insert, update, delete, and query behavior before defining separate scopes for custom IDs, soft deletion, optimistic locking, and auto-filled fields. Done would require an agreed design, customizable annotations, implementation, and tests for each requested behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100