Remove routes without a node_id (#2386)

The routes table has a NOT NULL constraint on node_id.

Fixes: #2376
This commit is contained in:
nblock 2025-01-30 14:57:06 +01:00 committed by Kristoffer Dalby
parent 46b82269e0
commit 341a3d3005
No known key found for this signature in database
2 changed files with 10 additions and 0 deletions

View file

@ -7,6 +7,8 @@
- Fix issue where email and username being equal fails to match in Policy - Fix issue where email and username being equal fails to match in Policy
[#2388](https://github.com/juanfont/headscale/pull/2388) [#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) ## 0.24.1 (2025-01-23)

View file

@ -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{}) err := tx.AutoMigrate(&types.Route{})
if err != nil { if err != nil {
return err return err