mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: enable experimental column altering for cockroachdb (see #442)
This commit is contained in:
parent
8a26e24081
commit
cd5c511474
35
config/db_opts.go
Normal file
35
config/db_opts.go
Normal file
@ -0,0 +1,35 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type WakapiDBOpts struct {
|
||||
dbConfig *dbConfig
|
||||
}
|
||||
|
||||
func GetWakapiDBOpts(dbConfig *dbConfig) *WakapiDBOpts {
|
||||
return &WakapiDBOpts{dbConfig: dbConfig}
|
||||
}
|
||||
|
||||
func (opts WakapiDBOpts) Apply(config *gorm.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts WakapiDBOpts) AfterInitialize(db *gorm.DB) error {
|
||||
// initial session variables
|
||||
if opts.dbConfig.Type == "cockroach" {
|
||||
// https://www.cockroachlabs.com/docs/stable/experimental-features.html#alter-column-types
|
||||
if err := db.Exec("SET enable_experimental_alter_column_type_general = true;").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if opts.dbConfig.IsSQLite() {
|
||||
if err := db.Exec("PRAGMA foreign_keys = ON;").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
5
main.go
5
main.go
@ -132,14 +132,11 @@ func main() {
|
||||
|
||||
// Connect to database
|
||||
var err error
|
||||
db, err = gorm.Open(config.Db.GetDialector(), &gorm.Config{Logger: gormLogger})
|
||||
db, err = gorm.Open(config.Db.GetDialector(), &gorm.Config{Logger: gormLogger}, conf.GetWakapiDBOpts(&config.Db))
|
||||
if err != nil {
|
||||
logbuch.Error(err.Error())
|
||||
logbuch.Fatal("could not open database")
|
||||
}
|
||||
if config.Db.IsSQLite() {
|
||||
db.Exec("PRAGMA foreign_keys = ON;")
|
||||
}
|
||||
|
||||
if config.IsDev() {
|
||||
db = db.Debug()
|
||||
|
@ -34,7 +34,7 @@ type Summary struct {
|
||||
Machines SummaryItems `json:"machines" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
||||
Labels SummaryItems `json:"labels" gorm:"-"` // labels are not persisted, but calculated at runtime, i.e. when summary is retrieved
|
||||
Branches SummaryItems `json:"branches" gorm:"-"` // branches are not persisted, but calculated at runtime in case a project filter is applied
|
||||
NumHeartbeats int `json:"-" gorm:"default:0"`
|
||||
NumHeartbeats int `json:"-"`
|
||||
}
|
||||
|
||||
type SummaryItems []*SummaryItem
|
||||
|
@ -20,7 +20,7 @@ type User struct {
|
||||
Password string `json:"-"`
|
||||
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"`
|
||||
ShareDataMaxDays int `json:"-" gorm:"default:0"`
|
||||
ShareDataMaxDays int `json:"-"`
|
||||
ShareEditors bool `json:"-" gorm:"default:false; type:bool"`
|
||||
ShareLanguages bool `json:"-" gorm:"default:false; type:bool"`
|
||||
ShareProjects bool `json:"-" gorm:"default:false; type:bool"`
|
||||
|
Loading…
Reference in New Issue
Block a user