From f49f27adf8f2b1db3599b5318b12e733a65838c2 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 15 Jun 2026 10:10:18 +0000 Subject: [PATCH] db, sqliteconfig: remove dead and unreachable code --- hscontrol/db/db.go | 6 ------ hscontrol/db/sqliteconfig/config.go | 20 -------------------- hscontrol/db/sqliteconfig/config_test.go | 19 ------------------- hscontrol/db/users.go | 2 -- 4 files changed, 47 deletions(-) diff --git a/hscontrol/db/db.go b/hscontrol/db/db.go index 8c088c49..e963373a 100644 --- a/hscontrol/db/db.go +++ b/hscontrol/db/db.go @@ -981,12 +981,6 @@ func runMigrations(cfg types.DatabaseConfig, dbConn *gorm.DB, migrations *gormig // Add other migration IDs here as they are identified to need FK disabled } - // Get the current foreign key status - var fkOriginallyEnabled int - if err := dbConn.Raw("PRAGMA foreign_keys").Scan(&fkOriginallyEnabled).Error; err != nil { //nolint:noinlineerr - return fmt.Errorf("checking foreign key status: %w", err) - } - // Get all migration IDs in order from the actual migration definitions // Only IDs that are in the migrationsRequiringFKDisabled map will be processed with FK disabled // any other new migrations are ran after. diff --git a/hscontrol/db/sqliteconfig/config.go b/hscontrol/db/sqliteconfig/config.go index b4c80795..711e434a 100644 --- a/hscontrol/db/sqliteconfig/config.go +++ b/hscontrol/db/sqliteconfig/config.go @@ -101,11 +101,6 @@ func (j JournalMode) IsValid() bool { } } -// String returns the string representation. -func (j JournalMode) String() string { - return string(j) -} - // AutoVacuum represents SQLite auto_vacuum pragma values. // Auto-vacuum controls how SQLite reclaims space from deleted data. // @@ -157,11 +152,6 @@ func (a AutoVacuum) IsValid() bool { } } -// String returns the string representation. -func (a AutoVacuum) String() string { - return string(a) -} - // Synchronous represents SQLite synchronous pragma values. // Synchronous mode controls how aggressively SQLite flushes data to disk. // @@ -221,11 +211,6 @@ func (s Synchronous) IsValid() bool { } } -// String returns the string representation. -func (s Synchronous) String() string { - return string(s) -} - // TxLock represents SQLite transaction lock mode. // Transaction lock mode determines when write locks are acquired during transactions. // @@ -277,11 +262,6 @@ func (t TxLock) IsValid() bool { } } -// String returns the string representation. -func (t TxLock) String() string { - return string(t) -} - // Config holds SQLite database configuration with type-safe enums. // This configuration balances performance, durability, and operational requirements // for Headscale's SQLite database usage patterns. diff --git a/hscontrol/db/sqliteconfig/config_test.go b/hscontrol/db/sqliteconfig/config_test.go index 7829d9e9..9f233902 100644 --- a/hscontrol/db/sqliteconfig/config_test.go +++ b/hscontrol/db/sqliteconfig/config_test.go @@ -98,25 +98,6 @@ func TestTxLock(t *testing.T) { } } -func TestTxLockString(t *testing.T) { - tests := []struct { - mode TxLock - want string - }{ - {TxLockDeferred, "deferred"}, - {TxLockImmediate, "immediate"}, - {TxLockExclusive, "exclusive"}, - } - - for _, tt := range tests { - t.Run(tt.want, func(t *testing.T) { - if got := tt.mode.String(); got != tt.want { - t.Errorf("TxLock.String() = %q, want %q", got, tt.want) - } - }) - } -} - func TestConfigValidate(t *testing.T) { tests := []struct { name string diff --git a/hscontrol/db/users.go b/hscontrol/db/users.go index 3eee704c..271c3e3d 100644 --- a/hscontrol/db/users.go +++ b/hscontrol/db/users.go @@ -95,8 +95,6 @@ var ErrCannotChangeOIDCUser = errors.New("cannot edit OIDC user") // RenameUser renames a [types.User]. Returns error if the [types.User] does // not exist or if another [types.User] exists with the new name. func RenameUser(tx *gorm.DB, uid types.UserID, newName string) error { - var err error - oldUser, err := GetUserByID(tx, uid) if err != nil { return err