This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
migrations.go
299 lines (294 loc) · 8.45 KB
/
migrations.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
package config
import (
"github.com/flyteorg/flyteadmin/pkg/repositories/models"
"github.com/jinzhu/gorm"
gormigrate "gopkg.in/gormigrate.v1"
)
var Migrations = []*gormigrate.Migration{
// Create projects table.
{
ID: "2019-05-22-projects",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Project{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("projects").Error
},
},
// Create Task
{
ID: "2018-05-23-tasks",
Migrate: func(tx *gorm.DB) error {
// The gormigrate library recommends that we copy the actual struct into here for record-keeping but after
// some internal discussion we've decided that that's not necessary. Just a history of what we've touched
// when should be sufficient.
return tx.AutoMigrate(&models.Task{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("tasks").Error
},
},
// Create Workflow
{
ID: "2018-05-23-workflows",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Workflow{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("workflows").Error
},
},
// Create Launch Plan table
{
ID: "2019-05-23-lp",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.LaunchPlan{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("launch_plans").Error
},
},
// Create executions table
{
ID: "2019-05-23-executions",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Execution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("executions").Error
},
},
// Create executions events table
{
ID: "2019-01-29-executions-events",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.ExecutionEvent{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("executions_events").Error
},
},
// Create node executions table
{
ID: "2019-04-17-node-executions",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&NodeExecution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("node_executions").Error
},
},
// Create node executions events table
{
ID: "2019-01-29-node-executions-events",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.NodeExecutionEvent{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("node_executions_events").Error
},
},
// Create task executions table
{
ID: "2019-03-16-task-executions",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&TaskExecution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("task_executions").Error
},
},
// Update node executions with null parent values
{
ID: "2019-04-17-node-executions-backfill",
Migrate: func(tx *gorm.DB) error {
return tx.Exec("update node_executions set parent_task_execution_id = NULL where parent_task_execution_id = 0").Error
},
},
// Update executions table to add cluster
{
ID: "2019-09-27-executions",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Execution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("ALTER TABLE executions DROP COLUMN IF EXISTS cluster").Error
},
},
// Update projects table to add description column
{
ID: "2019-10-09-project-description",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Project{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("ALTER TABLE projects DROP COLUMN IF EXISTS description").Error
},
},
// Add offloaded URIs to table
{
ID: "2019-10-15-offload-inputs",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Execution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("ALTER TABLE executions DROP COLUMN IF EXISTS InputsURI, DROP COLUMN IF EXISTS UserInputsURI").Error
},
},
// Create named_entity_metadata table.
{
ID: "2019-11-05-named-entity-metadata",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.NamedEntityMetadata{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("named_entity_metadata").Error
},
},
// Add ProjectAttributes with custom resource attributes.
{
ID: "2020-01-10-resource",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Resource{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.DropTable("resources").Error
},
},
// Add Type to Task model.
{
ID: "2020-03-17-task-type",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Task{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("ALTER TABLE tasks DROP COLUMN IF EXISTS type").Error
},
},
// Add state to name entity model
{
ID: "2020-04-03-named-entity-state",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.NamedEntityMetadata{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Table("named_entity_metadata").DropColumn("state").Error
},
},
// Set default state value for workflow model
{
ID: "2020-04-03-named-entity-state-default",
Migrate: func(tx *gorm.DB) error {
return tx.Exec("UPDATE named_entity_metadata SET state = 0").Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("UPDATE named_entity_metadata set state = NULL").Error
},
},
// Modify the workflows table, if necessary
{
ID: "2020-04-03-workflow-state",
Migrate: func(tx *gorm.DB) error {
return tx.Exec("ALTER TABLE workflows DROP COLUMN IF EXISTS state").Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("ALTER TABLE workflows ADD COLUMN IF NOT EXISTS state integer;").Error
},
},
// Modify the executions & node_execution table, if necessary
{
ID: "2020-04-29-executions",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Execution{}, &models.NodeExecution{}).Error
},
Rollback: func(tx *gorm.DB) error {
if err := tx.Model(&models.Execution{}).DropColumn("error_code").DropColumn("error_kind").Error; err != nil {
return err
}
return tx.Model(&models.NodeExecution{}).DropColumn("error_code").DropColumn("error_kind").Error
},
},
// Add TaskID to Execution model.
{
ID: "2020-04-14-task-type",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Execution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("ALTER TABLE executions DROP COLUMN IF EXISTS task_id").Error
},
},
// NodeExecutions table has CacheStatus for Task nodes
{
ID: "2020-07-27-cachestatus",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.NodeExecution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Model(&models.NodeExecution{}).DropColumn("cache_status").Error
},
},
{
ID: "2020-07-31-node-execution",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.NodeExecution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Model(&models.NodeExecution{}).DropColumn("parent_id").DropColumn("node_execution_metadata").Error
},
},
{
ID: "2020-08-13-node-execution",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.NodeExecution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Model(&models.NodeExecution{}).DropColumn("parent_id").DropColumn("node_execution_metadata").Error
},
},
{
ID: "2020-08-17-labels-addition",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Project{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Model(&models.Project{}).DropColumn("labels").Error
},
},
{
ID: "2020-09-01-task-exec-idx",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&TaskExecution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Model(&TaskExecution{}).RemoveIndex("idx_task_executions_exec").Error
},
},
{
ID: "2020-11-03-project-state-addition",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Project{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Model(&models.Project{}).DropColumn("state").Error
},
},
{
ID: "2020-11-03-project-state-default",
Migrate: func(tx *gorm.DB) error {
return tx.Exec("UPDATE projects set state = 0").Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("UPDATE projects set state = NULL").Error
},
},
{
ID: "2021-01-22-execution-user",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Execution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Model(&models.Execution{}).DropColumn("user").Error
},
},
}