Skip to content
Snippets Groups Projects
Verified Commit e8e6f8de authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

feat: move constraints -> type definitions

parent 066862ff
No related branches found
No related tags found
No related merge requests found
......@@ -202,22 +202,7 @@ var (
)
func initialMigration(tx *gorm.DB) (err error) {
if err = tx.AutoMigrate(&Show{}, &File{}, &ImportLog{}); err != nil {
return err
}
// replace the constraints created
if err = tx.Exec("ALTER TABLE files DROP CONSTRAINT fk_files_show").Error; err != nil {
return err
}
if err = tx.Exec("ALTER TABLE files ADD CONSTRAINT fk_files_show FOREIGN KEY (show_id) REFERENCES shows(id) ON UPDATE CASCADE ON DELETE CASCADE").Error; err != nil {
return err
}
if err = tx.Exec("ALTER TABLE import_logs DROP CONSTRAINT fk_import_logs_file").Error; err != nil {
return err
}
return tx.Exec("ALTER TABLE import_logs ADD CONSTRAINT fk_import_logs_file FOREIGN KEY (file_id) REFERENCES files(id) ON UPDATE CASCADE ON DELETE CASCADE ").Error
return tx.AutoMigrate(&Show{}, &File{}, &ImportLog{})
}
func (st *Store) initDBModel(cfg DBConfig) (err error) {
......
......@@ -159,7 +159,7 @@ type File struct {
CreatedAt time.Time `json:"created"`
UpdatedAt time.Time `json:"updated"`
ShowID uint64 `json:"showId" gorm:"not null;index"`
Show Show `json:"-" gorm:"associationForeignKey:ID"`
Show Show `json:"-" gorm:"associationForeignKey:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Source FileSource `json:"source" gorm:"embedded;embeddedPrefix:source__"`
Metadata FileMetadata `json:"metadata" gorm:"embedded;embeddedPrefix:metadata__"`
Size uint64 `json:"size"`
......@@ -170,7 +170,7 @@ type File struct {
type ImportLog struct {
ID uint64 `gorm:"primaryKey"`
File File `gorm:"associationAutoUpdate:false;associationAutoCreate:false"`
File File `gorm:"associationAutoUpdate:false;associationAutoCreate:false;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
FileID uint64 `gorm:"not null;index;uniqueIndex:unique_import_log_step"`
ImportStep string `gorm:"not null;index;uniqueIndex:unique_import_log_step"`
Encoded []byte `gorm:"size:-1"`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment