db: add last_control_address with explicit DDL

Migration rules forbid struct-driven schema changes; re-date the ID to
sort after its neighbours.

Updates #2272
This commit is contained in:
Kristoffer Dalby committed 2026-11-05 12:38:53 +01:00
1 parent 3af065bb03
commit 5adc504fed
2 files changed
+9 -11

No files matched your search

+8 -10
View File
@@ -359,19 +359,17 @@ WHERE auth_key_id IN (
Rollback: func(db *gorm.DB) error { return nil },
},
{
// Persist the source IP most recently observed on an authenticated
// control connection from each node. Existing rows intentionally
// remain NULL until the node next connects.
ID: "202609040900-add-last-control-address",
// The source IP of each node's latest authenticated control
// connection. Existing rows stay NULL until the node next connects.
ID: "202611041200-node-last-control-address",
Migrate: func(tx *gorm.DB) error {
if !tx.Migrator().HasColumn(&types.Node{}, "last_control_address") {
err := tx.Migrator().AddColumn(&types.Node{}, "LastControlAddress")
if err != nil {
return fmt.Errorf("adding last_control_address to nodes: %w", err)
return tx.Transaction(func(tx *gorm.DB) error {
if tx.Migrator().HasColumn(&types.Node{}, "last_control_address") {
return nil
}
}
return nil
return tx.Exec(`ALTER TABLE nodes ADD COLUMN last_control_address text`).Error
})
},
Rollback: func(db *gorm.DB) error { return nil },
},
+1 -1
View File
@@ -1129,7 +1129,7 @@ func TestLastControlAddressMigration(t *testing.T) {
result := database.DB.Exec(
"DELETE FROM migrations WHERE id = ?",
"202609040900-add-last-control-address",
"202611041200-node-last-control-address",
)
require.NoError(t, result.Error)
require.Equal(t, int64(1), result.RowsAffected)