[PR #1562] [MERGED] Restore foreign keys and add constraints #2182

Closed
opened 2025-12-29 03:20:07 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/1562
Author: @vsychov
Created: 9/26/2023
Status: Merged
Merged: 5/16/2024
Merged by: @kradalby

Base: mainHead: fix-1482


📝 Commits (5)

📊 Changes

15 files changed (+149 additions, -61 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 Makefile (+1 -0)
📝 hscontrol/auth.go (+9 -2)
📝 hscontrol/db/db.go (+4 -5)
📝 hscontrol/db/ip_test.go (+26 -0)
📝 hscontrol/db/node.go (+1 -1)
📝 hscontrol/db/node_test.go (+38 -19)
📝 hscontrol/db/preauth_keys.go (+2 -1)
📝 hscontrol/db/preauth_keys_test.go (+14 -7)
📝 hscontrol/db/routes_test.go (+34 -9)
📝 hscontrol/db/users_test.go (+8 -4)
📝 hscontrol/mapper/mapper_test.go (+3 -4)
📝 hscontrol/mapper/tail_test.go (+0 -1)
📝 hscontrol/types/node.go (+4 -4)
📝 hscontrol/types/preauth_key.go (+4 -4)

📄 Description

Hello there,

This pull request addresses the issue #1482, aiming to fix the anomalies regarding foreign keys and constraints in database models. Initially FK was disabled here: https://github.com/juanfont/headscale/pull/41 without any description why it was done.

These changes improve data integrity, maintain referential integrity between different tables, and ensure that the application's behavior remains consistent and predictable when handling database records, particularly in delete operations.

https://gorm.io/docs/gorm_config.html#DisableForeignKeyConstraintWhenMigrating

Fixes #1482

  • read the CONTRIBUTING guidelines
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • updated CHANGELOG.md

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/juanfont/headscale/pull/1562 **Author:** [@vsychov](https://github.com/vsychov) **Created:** 9/26/2023 **Status:** ✅ Merged **Merged:** 5/16/2024 **Merged by:** [@kradalby](https://github.com/kradalby) **Base:** `main` ← **Head:** `fix-1482` --- ### 📝 Commits (5) - [`074d2fa`](https://github.com/juanfont/headscale/commit/074d2fa2ba36c54e5a21af681efc66f56a7dd2a4) fix #1482, restore foregin keys, add constraints - [`eefd9ee`](https://github.com/juanfont/headscale/commit/eefd9ee21e0a064836b7df15b536d979dc73c31a) #1562, fix tests, fix formatting - [`9c53d11`](https://github.com/juanfont/headscale/commit/9c53d116761777169bd3e4d925f511bf0d30fb32) Merge branch 'main' into fix-1482 - [`a30a3fc`](https://github.com/juanfont/headscale/commit/a30a3fca3eaf4b8f20c25764de9af93b60910d47) #1562: fix tests - [`18bd635`](https://github.com/juanfont/headscale/commit/18bd635e1cf66e76135ff8785c43735dea2351a4) #1562: fix local run of test_integration ### 📊 Changes **15 files changed** (+149 additions, -61 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `Makefile` (+1 -0) 📝 `hscontrol/auth.go` (+9 -2) 📝 `hscontrol/db/db.go` (+4 -5) 📝 `hscontrol/db/ip_test.go` (+26 -0) 📝 `hscontrol/db/node.go` (+1 -1) 📝 `hscontrol/db/node_test.go` (+38 -19) 📝 `hscontrol/db/preauth_keys.go` (+2 -1) 📝 `hscontrol/db/preauth_keys_test.go` (+14 -7) 📝 `hscontrol/db/routes_test.go` (+34 -9) 📝 `hscontrol/db/users_test.go` (+8 -4) 📝 `hscontrol/mapper/mapper_test.go` (+3 -4) 📝 `hscontrol/mapper/tail_test.go` (+0 -1) 📝 `hscontrol/types/node.go` (+4 -4) 📝 `hscontrol/types/preauth_key.go` (+4 -4) </details> ### 📄 Description Hello there, This pull request addresses the issue #1482, aiming to fix the anomalies regarding foreign keys and constraints in database models. Initially FK was disabled here: https://github.com/juanfont/headscale/pull/41 without any description why it was done. These changes improve data integrity, maintain referential integrity between different tables, and ensure that the application's behavior remains consistent and predictable when handling database records, particularly in delete operations. https://gorm.io/docs/gorm_config.html#DisableForeignKeyConstraintWhenMigrating Fixes #1482 - [x] read the [CONTRIBUTING guidelines](README.md#contributing) - [x] raised a GitHub issue or discussed it on the projects chat beforehand - [x] updated CHANGELOG.md --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 03:20:07 +01:00
adam closed this issue 2025-12-29 03:20:07 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#2182