Remove unused hostname_prefix from server types and add duplicate checking
build-and-push / test (push) Successful in 35s
build-and-push / build-and-push (push) Successful in 56s

The HostnamePrefix field on ServerType was loaded from YAML but never used —
hostnames are user-provided. This removes the field and adds explicit
duplicate checks (hostname + MAC) with clear per-field error messages in
both the JSON API and web UI, backed by a new GetByHostname store method
with case-insensitive matching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-14 10:50:16 -04:00
parent 1317ff6369
commit 2a0fbf6923
7 changed files with 122 additions and 12 deletions
+16
View File
@@ -87,6 +87,18 @@ func (s *Hosts) GetByMAC(ctx context.Context, mac string) (*model.Host, error) {
return &h, nil
}
func (s *Hosts) GetByHostname(ctx context.Context, hostname string) (*model.Host, error) {
row := s.DB.QueryRowContext(ctx, `SELECT `+hostColumns+` FROM hosts WHERE LOWER(hostname) = ?`, normalizeHostname(hostname))
var h model.Host
if err := scanHost(row, &h); err != nil {
if err == sql.ErrNoRows {
return nil, ErrNotFound
}
return nil, fmt.Errorf("get host by hostname: %w", err)
}
return &h, nil
}
func (s *Hosts) UpdateState(ctx context.Context, id int64, state model.HostState) error {
res, err := s.DB.ExecContext(ctx, `UPDATE hosts SET state = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ','now') WHERE id = ?`, state, id)
if err != nil {
@@ -143,3 +155,7 @@ func (s *Hosts) Delete(ctx context.Context, id int64) error {
func normalizeMAC(m string) string {
return strings.ToLower(strings.TrimSpace(m))
}
func normalizeHostname(h string) string {
return strings.ToLower(strings.TrimSpace(h))
}