set default value in gorm tag, so database timestamp defaults will get set

This commit is contained in:
Jim authored and GitHub committed 2020-05-03 16:10:14 -04:00
1 parent 73363d4c71
commit 2f0dd58f11
3 files changed
+19 -15

No files matched your search

+4
View File
@@ -122,6 +122,8 @@ func Test_BasicOplog(t *testing.T) {
resp = db.Create(&l)
assert.NilError(t, resp.Error)
assert.Check(t, l.CreateTime != nil)
assert.Check(t, l.UpdateTime != nil)
entryId := l.Id
var foundEntry Entry
@@ -771,6 +773,8 @@ func Test_TicketSerialization(t *testing.T) {
err = secondLogEntry.Write(context.Background(), &GormWriter{secondTx}, secondTicket)
assert.NilError(t, err)
assert.Assert(t, secondLogEntry.Id != 0)
assert.Check(t, secondLogEntry.CreateTime != nil)
assert.Check(t, secondLogEntry.UpdateTime != nil)
err = secondTx.Commit().Error
assert.NilError(t, err)
assert.Assert(t, secondLogEntry.Id != 0)
+10 -10
View File
@@ -88,10 +88,10 @@ type Entry struct {
// @inject_tag: gorm:"primary_key"
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty" gorm:"primary_key"`
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
CreateTime *Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"not_null;type:TIMESTAMP"`
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"not_null;type:TIMESTAMP"`
// @inject_tag: `gorm:"default:current_timestamp"`
CreateTime *Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:current_timestamp"`
// @inject_tag: `gorm:"default:current_timestamp"`
UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:current_timestamp"`
// @inject_tag: gorm:"not_null"
Version string `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty" gorm:"not_null"`
// @inject_tat: gorm:"not_null"
@@ -204,8 +204,8 @@ type Metadata struct {
// @inject_tag: gorm:"primary_key"
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty" gorm:"primary_key"`
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
CreateTime *Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"not_null;type:TIMESTAMP"` // @inject_tag: gorm:"not_nul
// @inject_tag: `gorm:"default:current_timestamp"`
CreateTime *Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:current_timestamp"` // @inject_tag: gorm:"not_nul
EntryId uint32 `protobuf:"varint,3,opt,name=entry_id,json=entryId,proto3" json:"entry_id,omitempty"`
// @inject_tag: gorm:"foreignkey:EntryId"
Entry *Entry `protobuf:"bytes,4,opt,name=entry,proto3" json:"entry,omitempty" gorm:"foreignkey:EntryId"`
@@ -297,10 +297,10 @@ type Ticket struct {
// @inject_tag: gorm:"primary_key"
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty" gorm:"primary_key"`
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
CreateTime *Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"not_null;type:TIMESTAMP"`
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"not_null;type:TIMESTAMP"`
// @inject_tag: `gorm:"default:current_timestamp"`
CreateTime *Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:current_timestamp"`
// @inject_tag: `gorm:"default:current_timestamp"`
UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:current_timestamp"`
// @inject_tat: gorm:"not_null"
Name string `protobuf:"bytes,6,opt,name=name,proto3" json:"name,omitempty"`
// @inject_tat: gorm:"not_null;default:'1'"
@@ -19,9 +19,9 @@ message Timestamp {
message Entry {
// @inject_tag: gorm:"primary_key"
uint32 id = 1;
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
// @inject_tag: `gorm:"default:current_timestamp"`
Timestamp create_time = 2;
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
// @inject_tag: `gorm:"default:current_timestamp"`
Timestamp update_time = 3;
// @inject_tag: gorm:"not_null"
@@ -48,7 +48,7 @@ message Entry {
message Metadata {
// @inject_tag: gorm:"primary_key"
uint32 id = 1;
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
// @inject_tag: `gorm:"default:current_timestamp"`
Timestamp create_time = 2;
// @inject_tag: gorm:"not_nul
@@ -66,9 +66,9 @@ message Metadata {
message Ticket {
// @inject_tag: gorm:"primary_key"
uint32 id = 1;
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
// @inject_tag: `gorm:"default:current_timestamp"`
Timestamp create_time = 2;
// @inject_tag: gorm:"not_null;type:TIMESTAMP"
// @inject_tag: `gorm:"default:current_timestamp"`
Timestamp update_time = 3;
// @inject_tat: gorm:"not_null"