fix(store,api): идемпотентный import (UNIQUE+ON CONFLICT) + PATCH привязки шаблона к домену
This commit is contained in:
@@ -87,6 +87,44 @@ func (q *Queries) GetDomain(ctx context.Context, arg GetDomainParams) (Domain, e
|
||||
return i, err
|
||||
}
|
||||
|
||||
const importDomain = `-- 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 id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at
|
||||
`
|
||||
|
||||
type ImportDomainParams struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
ProviderAccountID uuid.UUID `json:"provider_account_id"`
|
||||
ZoneName string `json:"zone_name"`
|
||||
ZoneID string `json:"zone_id"`
|
||||
TemplateID *uuid.UUID `json:"template_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) ImportDomain(ctx context.Context, arg ImportDomainParams) (Domain, error) {
|
||||
row := q.db.QueryRow(ctx, importDomain,
|
||||
arg.ID,
|
||||
arg.ProjectID,
|
||||
arg.ProviderAccountID,
|
||||
arg.ZoneName,
|
||||
arg.ZoneID,
|
||||
arg.TemplateID,
|
||||
)
|
||||
var i Domain
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.ProviderAccountID,
|
||||
&i.ZoneName,
|
||||
&i.ZoneID,
|
||||
&i.TemplateID,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listDomains = `-- name: ListDomains :many
|
||||
SELECT id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at FROM domains WHERE project_id = $1 ORDER BY created_at
|
||||
`
|
||||
@@ -145,3 +183,29 @@ func (q *Queries) LoadDomainFull(ctx context.Context, id uuid.UUID) (LoadDomainF
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateDomainTemplate = `-- name: UpdateDomainTemplate :one
|
||||
UPDATE domains SET template_id = $3 WHERE id = $1 AND project_id = $2
|
||||
RETURNING id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at
|
||||
`
|
||||
|
||||
type UpdateDomainTemplateParams struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
TemplateID *uuid.UUID `json:"template_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateDomainTemplate(ctx context.Context, arg UpdateDomainTemplateParams) (Domain, error) {
|
||||
row := q.db.QueryRow(ctx, updateDomainTemplate, arg.ID, arg.ProjectID, arg.TemplateID)
|
||||
var i Domain
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.ProviderAccountID,
|
||||
&i.ZoneName,
|
||||
&i.ZoneID,
|
||||
&i.TemplateID,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user