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

fix: replace contraints created on initial migration

parent 2e0bedae
No related branches found
No related tags found
No related merge requests found
......@@ -316,13 +316,45 @@ var (
)
func initialMigration(tx *gorm.DB) (err error) {
return tx.AutoMigrate(
&Show{},
&File{},
&ImportLog{},
&Playlist{},
&PlaylistEntry{},
)
if err = tx.AutoMigrate(&Show{}, &File{}, &ImportLog{}, &Playlist{}, &PlaylistEntry{}); 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
}
if err = 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; err != nil {
return err
}
if err = tx.Exec("ALTER TABLE playlists DROP CONSTRAINT fk_playlists_show").Error; err != nil {
return err
}
if err = tx.Exec("ALTER TABLE playlists ADD CONSTRAINT fk_playlists_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 playlist_entries DROP CONSTRAINT fk_playlist_entries_file").Error; err != nil {
return err
}
if err = tx.Exec("ALTER TABLE playlist_entries ADD CONSTRAINT fk_playlist_entries_file FOREIGN KEY (file_id) REFERENCES files(id) ON UPDATE CASCADE ON DELETE RESTRICT ").Error; err != nil {
return err
}
if err = tx.Exec("ALTER TABLE playlist_entries DROP CONSTRAINT fk_playlists_entries").Error; err != nil {
return err
}
if err = tx.Exec("ALTER TABLE playlist_entries ADD CONSTRAINT fk_playlists_entries FOREIGN KEY (playlist_id) REFERENCES playlists(id) ON UPDATE CASCADE ON DELETE CASCADE ").Error; err != nil {
return err
}
return nil
}
func (st *Store) initDBModel(cfg DBConfig) (err error) {
......
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