From 341a3d3005c1b083094e433999aa9eb63b569f01 Mon Sep 17 00:00:00 2001 From: nblock Date: Thu, 30 Jan 2025 14:57:06 +0100 Subject: [PATCH] Remove routes without a node_id (#2386) The routes table has a NOT NULL constraint on node_id. Fixes: #2376 --- CHANGELOG.md | 2 ++ hscontrol/db/db.go | 8 ++++++++ 2 files changed, 10 insertions(+) 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