diff --git a/CHANGELOG.md b/CHANGELOG.md index 817c8deb..8c41b84f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - Fix issue where email and username being equal fails to match in Policy [#2388](https://github.com/juanfont/headscale/pull/2388) +- Delete invalid routes before adding a NOT NULL constraint on node_id + [#2386](https://github.com/juanfont/headscale/pull/2386) ## 0.24.1 (2025-01-23) diff --git a/hscontrol/db/db.go b/hscontrol/db/db.go index 36955e22..b0654e36 100644 --- a/hscontrol/db/db.go +++ b/hscontrol/db/db.go @@ -565,6 +565,14 @@ COMMIT; } } + // Remove any invalid routes without a node_id. + if tx.Migrator().HasTable(&types.Route{}) { + err := tx.Exec("delete from routes where node_id is null").Error + if err != nil { + return err + } + } + err := tx.AutoMigrate(&types.Route{}) if err != nil { return err