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 authored and Kristoffer Dalby committed 2023-01-19 12:54:34 +01:00
1 parent 81441afe70
commit 9eaa8dd049
1 file changed
+7 -7
+7 -7
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