SeaQL / SeaQL/sea-orm

Custom ID, Soft Delete, Optimistic Lock & Auto Field Fill

Open
#2,969 2 comments 0 reactions 0 assignees View on GitHub

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:

  1. 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).

  1. Soft Delete
  • Default value 0 for the soft delete field on insertion; set to 1 instead 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_remove instead of is_deleted).

  1. Optimistic Locking
  • Default version value 0 on insertion with validation; auto increment version by 1 on update and soft delete.

  • Allow customization of the version field name (e.g., lock_version instead of version).

  1. Auto Field Fill & Update
  • On insert: Auto populate created_at, created_by, set soft delete field to default 0, version field to default 0.

  • On update: Auto increment version, populate updated_at, updated_by.

  • On soft delete: Set soft delete field to 1, increment version, populate updated_at, updated_by.

  • Allow full customization of all auto-filled fields (e.g., create_time instead of created_at, operator instead of created_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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.