mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-20 04:14:32 +09:00
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:
1 parent
3af065bb03
commit
5adc504fed
2 files changed
+9
-11
No files matched your search
+8
-10
@@ -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 },
|
||||
},
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user