The domains list had no way to narrow itself down, so an operator with dozens of zones had to scan the whole table to find the drifted ones. Add two client-side filters above the table (the full list already arrives in one request, so server-side filtering would only add contract surface). The status filter compares against the same derived value the row's badge renders — a domain with no template shows "без шаблона" and must not match "drift" just because it kept a stale last_check_status from before its template was detached, so that derivation lives in one function used by both. Sorting is now decided in the store: ListDomains orders by zone_name instead of created_at, so every consumer of the list gets the same order and the filters never reorder anything. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Yr8frsaxBgab1Aa7yfPuU
45 lines
1.5 KiB
SQL
45 lines
1.5 KiB
SQL
-- name: CreateDomain :one
|
|
INSERT INTO domains (id, project_id, provider_account_id, zone_name, zone_id, template_id)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING *;
|
|
|
|
-- name: ImportDomain :one
|
|
INSERT INTO domains (id, project_id, provider_account_id, zone_name, zone_id, template_id)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
ON CONFLICT (project_id, zone_id) DO NOTHING
|
|
RETURNING *;
|
|
|
|
-- name: UpdateDomainTemplate :one
|
|
UPDATE domains SET template_id = $3 WHERE id = $1 AND project_id = $2
|
|
RETURNING *;
|
|
|
|
-- name: GetDomain :one
|
|
SELECT * FROM domains WHERE id = $1 AND project_id = $2;
|
|
|
|
-- name: ListDomains :many
|
|
SELECT * FROM domains WHERE project_id = $1 ORDER BY zone_name;
|
|
|
|
-- name: DeleteDomain :exec
|
|
DELETE FROM domains WHERE id = $1 AND project_id = $2;
|
|
|
|
-- name: LoadDomainFull :one
|
|
SELECT d.zone_id, d.zone_name, a.provider, a.secret_enc, t.doc
|
|
FROM domains d
|
|
JOIN provider_accounts a ON a.id = d.provider_account_id
|
|
LEFT JOIN templates t ON t.id = d.template_id
|
|
WHERE d.id = $1 AND d.project_id = $2;
|
|
|
|
-- name: GetDomainStatus :one
|
|
SELECT last_check_status FROM domains WHERE id = $1;
|
|
|
|
-- name: SetDomainStatus :exec
|
|
UPDATE domains SET last_check_status = $2 WHERE id = $1 AND project_id = $3;
|
|
|
|
-- name: CountDriftDomains :one
|
|
SELECT count(*) FROM domains WHERE last_check_status = 'drift';
|
|
|
|
-- name: DeleteDomainsNotInZones :many
|
|
DELETE FROM domains
|
|
WHERE project_id = $1 AND provider_account_id = $2 AND zone_id <> ALL($3::text[])
|
|
RETURNING id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at, last_check_status;
|