Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
37 строки
1.5 KiB
Go
37 строки
1.5 KiB
Go
package models
|
|
|
|
import (
|
|
"rocketgit.ru/rsmon/worker/app/models/concerns"
|
|
)
|
|
|
|
// ServerIp is a single IP (v4 or v6) bound to a Server. The
|
|
// canonical source for these rows is the deploymentd server-inventory
|
|
// receiver (M1) and the network-diagnostics partial plan; today the
|
|
// only writer is operator-entered via /api/v1/servers/:id/ips.
|
|
//
|
|
// `address` is Postgres `inet` so range queries (`<<` / `>>`) work
|
|
// without parsing text. One row per (server_id, address). The
|
|
// `is_primary` flag is set when more than one IP exists and the
|
|
// deploymentd payload signals a primary; otherwise the first row wins.
|
|
//
|
|
//nolint:revive // ServerIP rename deferred to M3; rstuff schema uses ServerIp verbatim and parity test depends on it.
|
|
type ServerIp struct {
|
|
concerns.Model
|
|
|
|
ServerID int64 `gorm:"type:bigint REFERENCES servers(id) ON DELETE CASCADE;not null;index" json:"server_id"`
|
|
Server *Server `json:"-"`
|
|
// Address is mapped to Postgres inet via raw SQL in Migrate(); the
|
|
// GORM `type:` tag is not enough because gorm.io/driver/postgres
|
|
// does not register `inet` in its type map. Field is stored as a
|
|
// string and validated by the API layer (see
|
|
// app/controllers/api/server.go ServerIPsAdd).
|
|
Address string `gorm:"type:inet;not null" json:"address"`
|
|
IsPrimary bool `gorm:"not null;default:false" json:"is_primary"`
|
|
RelatedSitesCount int `gorm:"not null;default:0" json:"related_sites_count"`
|
|
|
|
concerns.Timestamped
|
|
}
|
|
|
|
// TableName provides functionality.
|
|
func (ServerIp) TableName() string { return "server_ips" }
|