Skip to content

Commit

Permalink
revert db.go change
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Aug 27, 2024
1 parent e369f95 commit c23e9f8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hscontrol/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,16 @@ func NewHeadscaleDatabase(
// changed ones, when machines where renamed to nodes, which is covered
// further up. This whole initial integration is a mess and if AutoMigrate
// is ran on a 0.22 to 0.23 update, it will wipe all the routes.
if !tx.Migrator().HasTable(&types.Route{}) {
err = tx.AutoMigrate(&types.Route{})
if tx.Migrator().HasTable(&types.Route{}) && tx.Migrator().HasTable(&types.Node{}) {
err := tx.Exec("delete from routes where node_id not in (select id from nodes)").Error
if err != nil {
return err
}
}
err = tx.AutoMigrate(&types.Route{})
if err != nil {
return err
}

err = tx.AutoMigrate(&types.Node{})
if err != nil {
Expand Down

0 comments on commit c23e9f8

Please sign in to comment.