[PR #2156] [MERGED] use gorm serialiser instead of custom hooks #2527

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

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/2156
Author: @kradalby
Created: 9/27/2024
Status: Merged
Merged: 10/2/2024
Merged by: @kradalby

Base: mainHead: kradalby/gorm-serializer-no-custom-types


📝 Commits (2)

  • 7309efd add sqlite to debug/test image
  • ece488c test using gorm serialiser instead of custom hooks

📊 Changes

21 files changed (+243 additions, -354 deletions)

View changed files

📝 Dockerfile.debug (+1 -1)
📝 hscontrol/db/db.go (+16 -5)
📝 hscontrol/db/db_test.go (+28 -8)
📝 hscontrol/db/ip_test.go (+0 -37)
📝 hscontrol/db/node.go (+10 -4)
📝 hscontrol/db/node_test.go (+10 -6)
📝 hscontrol/db/preauth_keys.go (+1 -1)
📝 hscontrol/db/routes.go (+4 -4)
📝 hscontrol/db/routes_test.go (+6 -13)
hscontrol/db/testdata/0-23-0-to-0-24-0-no-more-special-types.sqlite (+0 -0)
hscontrol/db/text_serialiser.go (+99 -0)
📝 hscontrol/mapper/mapper_test.go (+3 -3)
📝 hscontrol/mapper/tail_test.go (+3 -3)
📝 hscontrol/policy/acls.go (+15 -8)
📝 hscontrol/policy/acls_test.go (+4 -11)
📝 hscontrol/poll.go (+11 -3)
📝 hscontrol/types/common.go (+0 -72)
📝 hscontrol/types/node.go (+19 -159)
📝 hscontrol/types/routes.go (+5 -5)
📝 hscontrol/types/routes_test.go (+6 -11)

...and 1 more files

📄 Description

This pr removes the custom types we have to wrap things to put them in the database, instead, we use gorm serialisers: https://gorm.io/docs/serializer.html.

We use the standard JSON serialiser and we introduce a Text serialiser that allows us to serialise types that implements: https://pkg.go.dev/encoding#TextMarshaler.

This allows us to remove even more custom code handling and a bunch of type casting/conversion.


🔄 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/2156 **Author:** [@kradalby](https://github.com/kradalby) **Created:** 9/27/2024 **Status:** ✅ Merged **Merged:** 10/2/2024 **Merged by:** [@kradalby](https://github.com/kradalby) **Base:** `main` ← **Head:** `kradalby/gorm-serializer-no-custom-types` --- ### 📝 Commits (2) - [`7309efd`](https://github.com/juanfont/headscale/commit/7309efd4ccea33b1b872db4598017a2c94386f6e) add sqlite to debug/test image - [`ece488c`](https://github.com/juanfont/headscale/commit/ece488cbf4bccd0f38554d03cb239f32e1e393ac) test using gorm serialiser instead of custom hooks ### 📊 Changes **21 files changed** (+243 additions, -354 deletions) <details> <summary>View changed files</summary> 📝 `Dockerfile.debug` (+1 -1) 📝 `hscontrol/db/db.go` (+16 -5) 📝 `hscontrol/db/db_test.go` (+28 -8) 📝 `hscontrol/db/ip_test.go` (+0 -37) 📝 `hscontrol/db/node.go` (+10 -4) 📝 `hscontrol/db/node_test.go` (+10 -6) 📝 `hscontrol/db/preauth_keys.go` (+1 -1) 📝 `hscontrol/db/routes.go` (+4 -4) 📝 `hscontrol/db/routes_test.go` (+6 -13) ➕ `hscontrol/db/testdata/0-23-0-to-0-24-0-no-more-special-types.sqlite` (+0 -0) ➕ `hscontrol/db/text_serialiser.go` (+99 -0) 📝 `hscontrol/mapper/mapper_test.go` (+3 -3) 📝 `hscontrol/mapper/tail_test.go` (+3 -3) 📝 `hscontrol/policy/acls.go` (+15 -8) 📝 `hscontrol/policy/acls_test.go` (+4 -11) 📝 `hscontrol/poll.go` (+11 -3) 📝 `hscontrol/types/common.go` (+0 -72) 📝 `hscontrol/types/node.go` (+19 -159) 📝 `hscontrol/types/routes.go` (+5 -5) 📝 `hscontrol/types/routes_test.go` (+6 -11) _...and 1 more files_ </details> ### 📄 Description This pr removes the custom types we have to wrap things to put them in the database, instead, we use gorm serialisers: https://gorm.io/docs/serializer.html. We use the standard JSON serialiser and we introduce a Text serialiser that allows us to serialise types that implements: https://pkg.go.dev/encoding#TextMarshaler. This allows us to remove even more custom code handling and a bunch of type casting/conversion. --- <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:21:40 +01:00
adam closed this issue 2025-12-29 03:21:40 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#2527