Opt-in `AUTOINCREMENT` for `gorm.Model`
- Dominant language
- Go
- Stars
- 231
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
## 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`](https://gorm.io/docs/delete.html#Delete-permanently), `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](https://www.sqlite.org/autoinc.html) 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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.