feat: remove domains whose zones vanished at the provider on import
This commit is contained in:
@@ -75,6 +75,47 @@ func (q *Queries) DeleteDomain(ctx context.Context, arg DeleteDomainParams) erro
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteDomainsNotInZones = `-- 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
|
||||
`
|
||||
|
||||
type DeleteDomainsNotInZonesParams struct {
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
ProviderAccountID uuid.UUID `json:"provider_account_id"`
|
||||
ZoneIds []string `json:"zone_ids"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteDomainsNotInZones(ctx context.Context, arg DeleteDomainsNotInZonesParams) ([]Domain, error) {
|
||||
rows, err := q.db.Query(ctx, deleteDomainsNotInZones, arg.ProjectID, arg.ProviderAccountID, arg.ZoneIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Domain
|
||||
for rows.Next() {
|
||||
var i Domain
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.ProviderAccountID,
|
||||
&i.ZoneName,
|
||||
&i.ZoneID,
|
||||
&i.TemplateID,
|
||||
&i.CreatedAt,
|
||||
&i.LastCheckStatus,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getDomain = `-- name: GetDomain :one
|
||||
SELECT id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at, last_check_status FROM domains WHERE id = $1 AND project_id = $2
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user