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.
@@ -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
