-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
730b248
commit ba8e876
Showing
7 changed files
with
108 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package migration | ||
|
||
import ( | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// Movie stores all movies | ||
type Movie struct { | ||
Id int32 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:int;not null;"` | ||
Cover Files `gorm:"column:cover;type:int;not null"` | ||
} | ||
|
||
// Kino stores all movies | ||
type Kino struct { | ||
Cover Files `gorm:"column:cover;type:int;not null"` | ||
Trailer string `gorm:"column:trailer;type:text;"` | ||
} | ||
|
||
// TableName sets the insert table name for this struct type | ||
func (n *Kino) TableName() string { | ||
return "kino" | ||
} | ||
|
||
type Files struct{} | ||
|
||
// TableName sets the insert table name for this struct type | ||
func (f *Files) TableName() string { | ||
return "files" | ||
} | ||
|
||
// migrate2023090510000000 | ||
// removes the unused trailer column | ||
// makes the Cover FK into a not null field | ||
// renames kino -> movie | ||
// fixes the id being named kino | ||
func (m TumDBMigrator) migrate2023090510000000() *gormigrate.Migration { | ||
return &gormigrate.Migration{ | ||
ID: "migrate2023090510000000", | ||
Migrate: func(tx *gorm.DB) error { | ||
// fix the movie table | ||
if err := tx.Migrator().RenameTable(&Kino{}, &Movie{}); err != nil { | ||
return err | ||
} | ||
if err := tx.Migrator().DropColumn(&Movie{}, "trailer"); err != nil { | ||
return err | ||
} | ||
if err := tx.Migrator().RenameColumn(&Movie{}, "kino", "id"); err != nil { | ||
return err | ||
} | ||
if err := tx.Migrator().AlterColumn(&Movie{}, "cover"); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
|
||
Rollback: func(tx *gorm.DB) error { | ||
// rollback the kino table | ||
if err := tx.Migrator().RenameTable(&Kino{}, &Movie{}); err != nil { | ||
return err | ||
} | ||
if err := tx.Migrator().RenameColumn(&Movie{}, "id", "kino"); err != nil { | ||
return err | ||
} | ||
if err := tx.AutoMigrate(Kino{}); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package model | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// Movie stores all movies | ||
type Movie struct { | ||
Id int32 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:int;not null;"` | ||
Date time.Time `gorm:"column:date;type:datetime;not null;"` | ||
Created time.Time `gorm:"column:created;type:timestamp;not null;default:CURRENT_TIMESTAMP"` | ||
Title string `gorm:"column:title;type:text;not null;"` | ||
Year string `gorm:"column:year;type:varchar(4);not null;"` | ||
Runtime string `gorm:"column:runtime;type:varchar(40);not null;"` | ||
Genre string `gorm:"column:genre;type:varchar(100);not null;"` | ||
Director string `gorm:"column:director;type:text;not null;"` | ||
Actors string `gorm:"column:actors;type:text;not null;"` | ||
ImdbRating string `gorm:"column:rating;type:varchar(4);not null;"` | ||
Description string `gorm:"column:description;type:text;not null;"` | ||
FilesID int32 `gorm:"column:cover;not null"` | ||
Files Files `gorm:"foreignKey:FilesID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` | ||
Link string `gorm:"column:link;type:varchar(190);not null;unique;"` | ||
} |