Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt-in AUTOINCREMENT for gorm.Model #195

Open
michal-kapala opened this issue Oct 2, 2024 · 0 comments
Open

Opt-in AUTOINCREMENT for gorm.Model #195

michal-kapala opened this issue Oct 2, 2024 · 0 comments
Assignees

Comments

@michal-kapala
Copy link

michal-kapala commented Oct 2, 2024

Describe the feature

For integer primary keys, gorm:"primaryKey" should behave like gorm:"primaryKey;autoIncrement:false" instead of gorm:"primaryKey;autoIncrement:true".

Motivation

  1. The default behaviour for gorm.Model is soft deletion. As soft deleted records persist, there's no need for AUTOINCREMENT use as in this case no key values are deleted and thus cannot be reused.
  2. When a record gets deleted with Unscoped, AUTOINCREMENT prevents reuse of the record's ROWID for future records, this may or may not be desired depending on a particular use case.
  3. Use of AUTOINCREMENT is discouraged by SQLite creators due to its performance overhead.

Given the above, I think changing the default behaviour of gorm:"primaryKey" would be beneficial as the use of AUTOINCREMENT is unnecessary in most cases.

Related Issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants