-
Notifications
You must be signed in to change notification settings - Fork 0
/
20210226000010_release_background_job.go
46 lines (38 loc) · 1.39 KB
/
20210226000010_release_background_job.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
package dbmigrations
import (
"time"
"github.com/fullstaq-labs/sqedule/server/dbutils/gormigrate"
"gorm.io/gorm"
)
func init() {
registerDbMigration(&migration20210226000010)
}
var migration20210226000010 = gormigrate.Migration{
ID: "20210226000010 Release background job",
Migrate: func(tx *gorm.DB) error {
type Organization struct {
ID string `gorm:"type:citext; primaryKey; not null"`
}
type BaseModel struct {
OrganizationID string `gorm:"type:citext; primaryKey; not null"`
Organization Organization `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
}
type Release struct {
BaseModel
ApplicationID string `gorm:"type:citext; primaryKey; not null"`
ID uint64 `gorm:"primaryKey; not null"`
}
type ReleaseBackgroundJob struct {
BaseModel
ApplicationID string `gorm:"type:citext; primaryKey; not null"`
ReleaseID uint64 `gorm:"primaryKey; not null"`
Release Release `gorm:"foreignKey:OrganizationID,ApplicationID,ReleaseID; references:OrganizationID,ApplicationID,ID; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
LockSubID uint32 `gorm:"type:int; autoIncrement; unique; not null; check:(lock_sub_id > 0)"`
CreatedAt time.Time `gorm:"not null"`
}
return tx.AutoMigrate(&ReleaseBackgroundJob{})
},
Rollback: func(tx *gorm.DB) error {
return tx.Migrator().DropTable("release_background_jobs")
},
}