fix: For time type, the time field will be automatically updated. Eve… #7316
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix: For time type, the time field will be automatically updated. Even if the table structure is not changed, the table modification operation will be repeated.
fix:时间类型,自动更新时间字段会。表结构没改动,也会重复 执行改表操作。
User Case Description
// Table Structure
// 表结构
type CreateUpdateTimeAt struct {
CreatedAt time.Time
gorm:"column:created_at;type:timestamp(3);default:CURRENT_TIMESTAMP(3);index:created_idx;" json:"created_at"
UpdatedAt time.Time
gorm:"column:updated_at;type:timestamp(3);default:CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3);" json:"updated_at"
}
// SQL to modify the table. Even if the table is not modified, it will be executed every time.
// 改表的SQL。表没改动,每次也会执行。
2024/12/12 16:15:50 /xxxx/service_context.go:46
[118.788ms] [rows:0] ALTER TABLE
tenant_third_config
MODIFY COLUMNupdated_at
timestamp(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)