Skip to content

Commit

Permalink
Fix: db open in mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Nov 17, 2023
1 parent 89b2c32 commit cc23248
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions internal/bootstrap/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@ func InitDatabase(ctx context.Context) error {
if conf.Conf.Database.CustomDSN != "" {
dsn = conf.Conf.Database.CustomDSN
} else if conf.Conf.Database.Port == 0 {
dsn = fmt.Sprintf("%s:%s@unix(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local&tls=%s&interpolateParams=true",
dsn = fmt.Sprintf("%s:%s@unix(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local&interpolateParams=true",
conf.Conf.Database.User,
conf.Conf.Database.Password,
conf.Conf.Database.Host,
conf.Conf.Database.DBName,
conf.Conf.Database.SslMode,
)
log.Infof("mysql database unix socket: %s", conf.Conf.Database.Host)
} else {
dsn = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local&tls=%s&interpolateParams=true",
dsn = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local&interpolateParams=true",
conf.Conf.Database.User,
conf.Conf.Database.Password,
conf.Conf.Database.Host,
conf.Conf.Database.Port,
conf.Conf.Database.DBName,
conf.Conf.Database.SslMode,
)
log.Infof("mysql database tcp: %s:%d", conf.Conf.Database.Host, conf.Conf.Database.Port)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
func Init(d *gorm.DB, t conf.DatabaseType) error {
db = d
dbType = t
return AutoMigrate(new(model.Movie), new(model.Room), new(model.User), new(model.RoomUserRelation), new(model.UserProvider), new(model.Setting), new(model.StreamingVendorInfo))
return AutoMigrate(new(model.Setting), new(model.User), new(model.UserProvider), new(model.Room), new(model.RoomUserRelation), new(model.StreamingVendorInfo), new(model.Movie))
}

func AutoMigrate(dst ...any) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/model/movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Movie struct {
UpdatedAt time.Time `json:"-"`
Position uint `gorm:"not null" json:"-"`
RoomID string `gorm:"not null;index" json:"-"`
CreatorID string `gorm:"not null;index" json:"creatorId"`
CreatorID string `gorm:"index" json:"creatorId"`
Base BaseMovie `gorm:"embedded;embeddedPrefix:base_" json:"base"`
}

Expand Down

0 comments on commit cc23248

Please sign in to comment.