/
migration_field_time.go
64 lines (56 loc) · 1.62 KB
/
migration_field_time.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package migration
/**
* @Description: 相当于为软删除添加一个可空的 deleted_at 字段
* @receiver m
* @auth: daguang
* @return *MigrationAttributes
*/
func (m *MigrationTable) SoftDeletes() *MigrationAttributes {
m.table.result = append(m.table.result,&MigrationAttribute{
field: "deleted_at",
fieldType: "timestamp",
})
return m.table
}
func (m *MigrationTable) Time(field string) *MigrationAttributes {
m.table.result = append(m.table.result,&MigrationAttribute{
field: field,
fieldType: "TIME",
})
return m.table
}
func (m *MigrationTable) Timestamp(field string) *MigrationAttributes {
m.table.result = append(m.table.result,&MigrationAttribute{
field: field,
fieldType: "timestamp",
})
return m.table
}
// 生成可以由框架自动维护的 create_at 与 update_at
func (m *MigrationTable) Timestamps() *MigrationAttributes {
m.table.result = append(m.table.result,&MigrationAttribute{
fieldType: "timestamps",
})
return m.table
}
func (m *MigrationTable) Year(field string) *MigrationAttributes {
m.table.result = append(m.table.result,&MigrationAttribute{
field: field,
fieldType: "year",
})
return m.table
}
func (m *MigrationTable) Date(field string) *MigrationAttributes {
m.table.result = append(m.table.result,&MigrationAttribute{
field: field,
fieldType: "DATE",
})
return m.table
}
func (m *MigrationTable) DateTime(field string) *MigrationAttributes {
m.table.result = append(m.table.result,&MigrationAttribute{
field: field,
fieldType: "DATETIME",
})
return m.table
}