/
schema.go
123 lines (119 loc) · 4.1 KB
/
schema.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// TCarColumns holds the columns for the "t_car" table.
TCarColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "create_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "update_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "model", Type: field.TypeString},
{Name: "registered_at", Type: field.TypeTime},
{Name: "user_cars", Type: field.TypeInt, Nullable: true},
}
// TCarTable holds the schema information for the "t_car" table.
TCarTable = &schema.Table{
Name: "t_car",
Columns: TCarColumns,
PrimaryKey: []*schema.Column{TCarColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "t_car_t_user_cars",
Columns: []*schema.Column{TCarColumns[5]},
RefColumns: []*schema.Column{TUserColumns[0]},
OnDelete: schema.SetNull,
},
},
}
// TGroupColumns holds the columns for the "t_group" table.
TGroupColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "create_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "update_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "name", Type: field.TypeString},
}
// TGroupTable holds the schema information for the "t_group" table.
TGroupTable = &schema.Table{
Name: "t_group",
Columns: TGroupColumns,
PrimaryKey: []*schema.Column{TGroupColumns[0]},
}
// PetsColumns holds the columns for the "pets" table.
PetsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "age", Type: field.TypeInt},
{Name: "name", Type: field.TypeString},
{Name: "weight", Type: field.TypeFloat64},
}
// PetsTable holds the schema information for the "pets" table.
PetsTable = &schema.Table{
Name: "pets",
Columns: PetsColumns,
PrimaryKey: []*schema.Column{PetsColumns[0]},
}
// TUserColumns holds the columns for the "t_user" table.
TUserColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "create_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "update_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
{Name: "age", Type: field.TypeInt},
{Name: "name", Type: field.TypeString, Default: "unknown"},
}
// TUserTable holds the schema information for the "t_user" table.
TUserTable = &schema.Table{
Name: "t_user",
Columns: TUserColumns,
PrimaryKey: []*schema.Column{TUserColumns[0]},
}
// GroupUsersColumns holds the columns for the "group_users" table.
GroupUsersColumns = []*schema.Column{
{Name: "group_id", Type: field.TypeInt},
{Name: "user_id", Type: field.TypeInt},
}
// GroupUsersTable holds the schema information for the "group_users" table.
GroupUsersTable = &schema.Table{
Name: "group_users",
Columns: GroupUsersColumns,
PrimaryKey: []*schema.Column{GroupUsersColumns[0], GroupUsersColumns[1]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "group_users_group_id",
Columns: []*schema.Column{GroupUsersColumns[0]},
RefColumns: []*schema.Column{TGroupColumns[0]},
OnDelete: schema.Cascade,
},
{
Symbol: "group_users_user_id",
Columns: []*schema.Column{GroupUsersColumns[1]},
RefColumns: []*schema.Column{TUserColumns[0]},
OnDelete: schema.Cascade,
},
},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
TCarTable,
TGroupTable,
PetsTable,
TUserTable,
GroupUsersTable,
}
)
func init() {
TCarTable.ForeignKeys[0].RefTable = TUserTable
TCarTable.Annotation = &entsql.Annotation{
Table: "t_car",
}
TGroupTable.Annotation = &entsql.Annotation{
Table: "t_group",
}
TUserTable.Annotation = &entsql.Annotation{
Table: "t_user",
}
GroupUsersTable.ForeignKeys[0].RefTable = TGroupTable
GroupUsersTable.ForeignKeys[1].RefTable = TUserTable
}