1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

fix: failing auto migration of users table (resolve #171)

This commit is contained in:
Ferdinand Mütsch 2021-04-13 23:23:57 +02:00
parent 129e208169
commit f8e1453754
2 changed files with 22 additions and 8 deletions

View File

@ -174,13 +174,27 @@ func (c *Config) GetMigrationFunc(dbDialect string) models.MigrationFunc {
switch dbDialect { switch dbDialect {
default: default:
return func(db *gorm.DB) error { return func(db *gorm.DB) error {
db.AutoMigrate(&models.User{}) if err := db.AutoMigrate(&models.User{}); err != nil {
db.AutoMigrate(&models.KeyStringValue{}) return err
db.AutoMigrate(&models.Alias{}) }
db.AutoMigrate(&models.Heartbeat{}) if err := db.AutoMigrate(&models.KeyStringValue{}); err != nil {
db.AutoMigrate(&models.Summary{}) return err
db.AutoMigrate(&models.SummaryItem{}) }
db.AutoMigrate(&models.LanguageMapping{}) if err := db.AutoMigrate(&models.Alias{}); err != nil {
return err
}
if err := db.AutoMigrate(&models.Heartbeat{}); err != nil {
return err
}
if err := db.AutoMigrate(&models.Summary{}); err != nil {
return err
}
if err := db.AutoMigrate(&models.SummaryItem{}); err != nil {
return err
}
if err := db.AutoMigrate(&models.LanguageMapping{}); err != nil {
return err
}
return nil return nil
} }
} }

View File

@ -9,7 +9,7 @@ func init() {
type User struct { type User struct {
ID string `json:"id" gorm:"primary_key"` ID string `json:"id" gorm:"primary_key"`
ApiKey string `json:"api_key" gorm:"unique"` ApiKey string `json:"api_key" gorm:"unique"`
Email string `json:"email" gorm:"uniqueIndex:idx_user_email"` Email string `json:"email" gorm:"uniqueIndex:idx_user_email; size:255"`
Password string `json:"-"` Password string `json:"-"`
CreatedAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"` CreatedAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"`
LastLoggedInAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"` LastLoggedInAt CustomTime `gorm:"type:timestamp; default:CURRENT_TIMESTAMP" swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"`