diff --git a/README.md b/README.md index 8bad291f..6485def5 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,11 @@ Flamenco Manager has a SwaggerUI interface at http://localhost:8080/api/swagger- ## Database Flamenco Manager includes a copy of https://github.com/go-gorm/sqlite.git, adjusted to use the pure-Go SQLite from https://modernc.org/sqlite. + +Flamenco Manager and Worker use SQLite as database, and Gorm as +object-relational mapper. + +Since SQLite has limited support for altering table schemas, migration requires +copying old data to a temporary table with the new schema, then swap out the +tables. Because of this, avoid `NOT NULL` columns, as they will be problematic +in this process. diff --git a/internal/manager/persistence/jobs.go b/internal/manager/persistence/jobs.go index dac02859..aa143d21 100644 --- a/internal/manager/persistence/jobs.go +++ b/internal/manager/persistence/jobs.go @@ -35,12 +35,12 @@ import ( type Job struct { gorm.Model - UUID string `gorm:"type:char(36);not null;unique;index"` + UUID string `gorm:"type:char(36);default:'';unique;index"` - Name string `gorm:"type:varchar(64);not null"` - JobType string `gorm:"type:varchar(32);not null"` - Priority int `gorm:"type:smallint;not null"` - Status api.JobStatus `gorm:"type:varchar(32);not null"` + Name string `gorm:"type:varchar(64);default:''"` + JobType string `gorm:"type:varchar(32);default:''"` + Priority int `gorm:"type:smallint;default:0"` + Status api.JobStatus `gorm:"type:varchar(32);default:''"` Settings StringInterfaceMap `gorm:"type:jsonb"` Metadata StringStringMap `gorm:"type:jsonb"` @@ -51,14 +51,14 @@ type StringStringMap map[string]string type Task struct { gorm.Model - UUID string `gorm:"type:char(36);not null;unique;index"` + UUID string `gorm:"type:char(36);default:'';unique;index"` - Name string `gorm:"type:varchar(64);not null"` - Type string `gorm:"type:varchar(32);not null"` - JobID uint `gorm:"not null"` - Job *Job `gorm:"foreignkey:JobID;references:ID;constraint:OnDelete:CASCADE;not null"` - Priority int `gorm:"type:smallint;not null"` - Status api.TaskStatus `gorm:"type:varchar(16);not null"` + Name string `gorm:"type:varchar(64);default:''"` + Type string `gorm:"type:varchar(32);default:''"` + JobID uint `gorm:"default:0"` + Job *Job `gorm:"foreignkey:JobID;references:ID;constraint:OnDelete:CASCADE"` + Priority int `gorm:"type:smallint;default:50"` + Status api.TaskStatus `gorm:"type:varchar(16);default:''"` // Which worker is/was working on this. WorkerID *uint @@ -68,7 +68,7 @@ type Task struct { Dependencies []*Task `gorm:"many2many:task_dependencies;constraint:OnDelete:CASCADE"` Commands Commands `gorm:"type:jsonb"` - Activity string `gorm:"type:varchar(255);not null;default:\"\""` + Activity string `gorm:"type:varchar(255);default:''"` } type Commands []Command diff --git a/internal/manager/persistence/workers.go b/internal/manager/persistence/workers.go index e97b8199..6e77d064 100644 --- a/internal/manager/persistence/workers.go +++ b/internal/manager/persistence/workers.go @@ -32,18 +32,18 @@ import ( type Worker struct { gorm.Model - UUID string `gorm:"type:char(36);not null;unique;index"` - Secret string `gorm:"type:varchar(255);not null"` - Name string `gorm:"type:varchar(64);not null"` + UUID string `gorm:"type:char(36);default:'';unique;index;default:''"` + Secret string `gorm:"type:varchar(255);default:''"` + Name string `gorm:"type:varchar(64);default:''"` - Address string `gorm:"type:varchar(39);not null;index"` // 39 = max length of IPv6 address. - LastActivity string `gorm:"type:varchar(255);not null"` - Platform string `gorm:"type:varchar(16);not null"` - Software string `gorm:"type:varchar(32);not null"` - Status api.WorkerStatus `gorm:"type:varchar(16);not null"` - StatusRequested api.WorkerStatus `gorm:"type:varchar(16);not null;default:''"` + Address string `gorm:"type:varchar(39);default:'';index"` // 39 = max length of IPv6 address. + LastActivity string `gorm:"type:varchar(255);default:''"` + Platform string `gorm:"type:varchar(16);default:''"` + Software string `gorm:"type:varchar(32);default:''"` + Status api.WorkerStatus `gorm:"type:varchar(16);default:''"` + StatusRequested api.WorkerStatus `gorm:"type:varchar(16);default:''"` - SupportedTaskTypes string `gorm:"type:varchar(255);not null"` // comma-separated list of task types. + SupportedTaskTypes string `gorm:"type:varchar(255);default:''"` // comma-separated list of task types. } // TaskTypes returns the worker's supported task types as list of strings.