Migrate DB: rename table is plural, order matters

The calls to AutoMigrate to other classes that refer to users will
create the table and it will break, it needs to be done before
everything else.

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2023-01-18 17:23:37 +01:00 committed by Kristoffer Dalby
parent 81441afe70
commit 9eaa8dd049

14
db.go
View file

@ -41,6 +41,13 @@ func (h *Headscale) initDB() error {
db.Exec(`create extension if not exists "uuid-ossp";`)
}
_ = db.Migrator().RenameTable("namespaces", "users")
err = db.AutoMigrate(&User{})
if err != nil {
return err
}
_ = db.Migrator().RenameColumn(&Machine{}, "ip_address", "ip_addresses")
_ = db.Migrator().RenameColumn(&Machine{}, "name", "hostname")
@ -187,13 +194,6 @@ func (h *Headscale) initDB() error {
return err
}
_ = db.Migrator().RenameTable("Namespace", "User")
err = db.AutoMigrate(&User{})
if err != nil {
return err
}
err = db.AutoMigrate(&PreAuthKey{})
if err != nil {
return err