mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-02-09 15:28:49 -06:00
* Initial plan * Initial plan for organization transfer feature Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com> * Add organization transfer feature with UI, DB layer, and integration test Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com> * Address PR feedback: verify old owner in property transfer, swap org membership, show masked email in audit, add negative tests Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>
676 lines
21 KiB
Go
676 lines
21 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: properties.sql
|
|
|
|
package generated
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"time"
|
|
)
|
|
|
|
const createProperty = `-- name: CreateProperty :one
|
|
INSERT INTO backend.properties (name, org_id, creator_id, org_owner_id, domain, level, growth, validity_interval, allow_subdomains, allow_localhost, max_replay_count)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
|
RETURNING id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count
|
|
`
|
|
|
|
type CreatePropertyParams struct {
|
|
Name string `db:"name" json:"name"`
|
|
OrgID pgtype.Int4 `db:"org_id" json:"org_id"`
|
|
CreatorID pgtype.Int4 `db:"creator_id" json:"creator_id"`
|
|
OrgOwnerID pgtype.Int4 `db:"org_owner_id" json:"org_owner_id"`
|
|
Domain string `db:"domain" json:"domain"`
|
|
Level pgtype.Int2 `db:"level" json:"level"`
|
|
Growth DifficultyGrowth `db:"growth" json:"growth"`
|
|
ValidityInterval time.Duration `db:"validity_interval" json:"validity_interval"`
|
|
AllowSubdomains bool `db:"allow_subdomains" json:"allow_subdomains"`
|
|
AllowLocalhost bool `db:"allow_localhost" json:"allow_localhost"`
|
|
MaxReplayCount int32 `db:"max_replay_count" json:"max_replay_count"`
|
|
}
|
|
|
|
func (q *Queries) CreateProperty(ctx context.Context, arg *CreatePropertyParams) (*Property, error) {
|
|
row := q.db.QueryRow(ctx, createProperty,
|
|
arg.Name,
|
|
arg.OrgID,
|
|
arg.CreatorID,
|
|
arg.OrgOwnerID,
|
|
arg.Domain,
|
|
arg.Level,
|
|
arg.Growth,
|
|
arg.ValidityInterval,
|
|
arg.AllowSubdomains,
|
|
arg.AllowLocalhost,
|
|
arg.MaxReplayCount,
|
|
)
|
|
var i Property
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const deleteProperties = `-- name: DeleteProperties :exec
|
|
DELETE FROM backend.properties WHERE id = ANY($1::INT[])
|
|
`
|
|
|
|
func (q *Queries) DeleteProperties(ctx context.Context, dollar_1 []int32) error {
|
|
_, err := q.db.Exec(ctx, deleteProperties, dollar_1)
|
|
return err
|
|
}
|
|
|
|
const getOrgProperties = `-- name: GetOrgProperties :many
|
|
SELECT id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count
|
|
FROM backend.properties
|
|
WHERE org_id = $1 AND deleted_at IS NULL
|
|
ORDER BY created_at
|
|
OFFSET $2
|
|
LIMIT $3
|
|
`
|
|
|
|
type GetOrgPropertiesParams struct {
|
|
OrgID pgtype.Int4 `db:"org_id" json:"org_id"`
|
|
Offset int32 `db:"offset" json:"offset"`
|
|
Limit int32 `db:"limit" json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) GetOrgProperties(ctx context.Context, arg *GetOrgPropertiesParams) ([]*Property, error) {
|
|
rows, err := q.db.Query(ctx, getOrgProperties, arg.OrgID, arg.Offset, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*Property
|
|
for rows.Next() {
|
|
var i Property
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getOrgPropertiesCount = `-- name: GetOrgPropertiesCount :one
|
|
SELECT COUNT(*) as count FROM backend.properties WHERE org_id = $1 AND deleted_at IS NULL
|
|
`
|
|
|
|
func (q *Queries) GetOrgPropertiesCount(ctx context.Context, orgID pgtype.Int4) (int64, error) {
|
|
row := q.db.QueryRow(ctx, getOrgPropertiesCount, orgID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const getOrgPropertyByName = `-- name: GetOrgPropertyByName :one
|
|
SELECT id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count from backend.properties WHERE org_id = $1 AND name = $2 AND deleted_at IS NULL
|
|
`
|
|
|
|
type GetOrgPropertyByNameParams struct {
|
|
OrgID pgtype.Int4 `db:"org_id" json:"org_id"`
|
|
Name string `db:"name" json:"name"`
|
|
}
|
|
|
|
func (q *Queries) GetOrgPropertyByName(ctx context.Context, arg *GetOrgPropertyByNameParams) (*Property, error) {
|
|
row := q.db.QueryRow(ctx, getOrgPropertyByName, arg.OrgID, arg.Name)
|
|
var i Property
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getProperties = `-- name: GetProperties :many
|
|
SELECT id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count FROM backend.properties LIMIT $1
|
|
`
|
|
|
|
func (q *Queries) GetProperties(ctx context.Context, limit int32) ([]*Property, error) {
|
|
rows, err := q.db.Query(ctx, getProperties, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*Property
|
|
for rows.Next() {
|
|
var i Property
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getPropertiesByExternalID = `-- name: GetPropertiesByExternalID :many
|
|
SELECT id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count from backend.properties WHERE external_id = ANY($1::UUID[])
|
|
`
|
|
|
|
func (q *Queries) GetPropertiesByExternalID(ctx context.Context, dollar_1 []pgtype.UUID) ([]*Property, error) {
|
|
rows, err := q.db.Query(ctx, getPropertiesByExternalID, dollar_1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*Property
|
|
for rows.Next() {
|
|
var i Property
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getPropertiesByID = `-- name: GetPropertiesByID :many
|
|
SELECT id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count from backend.properties WHERE id = ANY($1::INT[])
|
|
`
|
|
|
|
func (q *Queries) GetPropertiesByID(ctx context.Context, dollar_1 []int32) ([]*Property, error) {
|
|
rows, err := q.db.Query(ctx, getPropertiesByID, dollar_1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*Property
|
|
for rows.Next() {
|
|
var i Property
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getPropertyByExternalID = `-- name: GetPropertyByExternalID :one
|
|
SELECT id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count from backend.properties WHERE external_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetPropertyByExternalID(ctx context.Context, externalID pgtype.UUID) (*Property, error) {
|
|
row := q.db.QueryRow(ctx, getPropertyByExternalID, externalID)
|
|
var i Property
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getPropertyByID = `-- name: GetPropertyByID :one
|
|
SELECT id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count from backend.properties WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetPropertyByID(ctx context.Context, id int32) (*Property, error) {
|
|
row := q.db.QueryRow(ctx, getPropertyByID, id)
|
|
var i Property
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getSoftDeletedProperties = `-- name: GetSoftDeletedProperties :many
|
|
SELECT p.id, p.name, p.external_id, p.org_id, p.creator_id, p.org_owner_id, p.domain, p.level, p.salt, p.growth, p.created_at, p.updated_at, p.deleted_at, p.validity_interval, p.allow_subdomains, p.allow_localhost, p.max_replay_count
|
|
FROM backend.properties p
|
|
JOIN backend.organizations o ON p.org_id = o.id
|
|
JOIN backend.users u ON o.user_id = u.id
|
|
WHERE p.deleted_at IS NOT NULL
|
|
AND p.deleted_at < $1
|
|
AND o.deleted_at IS NULL
|
|
AND u.deleted_at IS NULL
|
|
LIMIT $2
|
|
`
|
|
|
|
type GetSoftDeletedPropertiesParams struct {
|
|
DeletedAt pgtype.Timestamptz `db:"deleted_at" json:"deleted_at"`
|
|
Limit int32 `db:"limit" json:"limit"`
|
|
}
|
|
|
|
type GetSoftDeletedPropertiesRow struct {
|
|
Property Property `db:"property" json:"property"`
|
|
}
|
|
|
|
func (q *Queries) GetSoftDeletedProperties(ctx context.Context, arg *GetSoftDeletedPropertiesParams) ([]*GetSoftDeletedPropertiesRow, error) {
|
|
rows, err := q.db.Query(ctx, getSoftDeletedProperties, arg.DeletedAt, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*GetSoftDeletedPropertiesRow
|
|
for rows.Next() {
|
|
var i GetSoftDeletedPropertiesRow
|
|
if err := rows.Scan(
|
|
&i.Property.ID,
|
|
&i.Property.Name,
|
|
&i.Property.ExternalID,
|
|
&i.Property.OrgID,
|
|
&i.Property.CreatorID,
|
|
&i.Property.OrgOwnerID,
|
|
&i.Property.Domain,
|
|
&i.Property.Level,
|
|
&i.Property.Salt,
|
|
&i.Property.Growth,
|
|
&i.Property.CreatedAt,
|
|
&i.Property.UpdatedAt,
|
|
&i.Property.DeletedAt,
|
|
&i.Property.ValidityInterval,
|
|
&i.Property.AllowSubdomains,
|
|
&i.Property.AllowLocalhost,
|
|
&i.Property.MaxReplayCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getUserPropertiesCount = `-- name: GetUserPropertiesCount :one
|
|
SELECT COUNT(*) as count FROM backend.properties WHERE org_owner_id = $1 AND deleted_at IS NULL
|
|
`
|
|
|
|
func (q *Queries) GetUserPropertiesCount(ctx context.Context, orgOwnerID pgtype.Int4) (int64, error) {
|
|
row := q.db.QueryRow(ctx, getUserPropertiesCount, orgOwnerID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const moveProperty = `-- name: MoveProperty :one
|
|
UPDATE backend.properties SET org_id = $2, org_owner_id = $3, updated_at = NOW()
|
|
WHERE id = $1
|
|
RETURNING id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count
|
|
`
|
|
|
|
type MovePropertyParams struct {
|
|
ID int32 `db:"id" json:"id"`
|
|
OrgID pgtype.Int4 `db:"org_id" json:"org_id"`
|
|
OrgOwnerID pgtype.Int4 `db:"org_owner_id" json:"org_owner_id"`
|
|
}
|
|
|
|
func (q *Queries) MoveProperty(ctx context.Context, arg *MovePropertyParams) (*Property, error) {
|
|
row := q.db.QueryRow(ctx, moveProperty, arg.ID, arg.OrgID, arg.OrgOwnerID)
|
|
var i Property
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const softDeleteProperties = `-- name: SoftDeleteProperties :many
|
|
UPDATE backend.properties SET deleted_at = NOW(), updated_at = NOW(), name = name || ' deleted_' || substr(md5(random()::text), 1, 8) WHERE id = ANY($1::INT[]) AND (creator_id = $2 OR org_owner_id = $2) AND (org_id = $3 OR $3 IS NULL) AND deleted_at IS NULL RETURNING id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count
|
|
`
|
|
|
|
type SoftDeletePropertiesParams struct {
|
|
Column1 []int32 `db:"column_1" json:"column_1"`
|
|
CreatorID pgtype.Int4 `db:"creator_id" json:"creator_id"`
|
|
OrgID pgtype.Int4 `db:"org_id" json:"org_id"`
|
|
}
|
|
|
|
func (q *Queries) SoftDeleteProperties(ctx context.Context, arg *SoftDeletePropertiesParams) ([]*Property, error) {
|
|
rows, err := q.db.Query(ctx, softDeleteProperties, arg.Column1, arg.CreatorID, arg.OrgID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*Property
|
|
for rows.Next() {
|
|
var i Property
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const softDeleteProperty = `-- name: SoftDeleteProperty :one
|
|
UPDATE backend.properties SET deleted_at = NOW(), updated_at = NOW(), name = name || ' deleted_' || substr(md5(random()::text), 1, 8) WHERE id = $1 RETURNING id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count
|
|
`
|
|
|
|
func (q *Queries) SoftDeleteProperty(ctx context.Context, id int32) (*Property, error) {
|
|
row := q.db.QueryRow(ctx, softDeleteProperty, id)
|
|
var i Property
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const transferOrgProperties = `-- name: TransferOrgProperties :exec
|
|
UPDATE backend.properties SET org_owner_id = $2, updated_at = NOW() WHERE org_id = $1 AND org_owner_id = $3
|
|
`
|
|
|
|
type TransferOrgPropertiesParams struct {
|
|
OrgID pgtype.Int4 `db:"org_id" json:"org_id"`
|
|
OrgOwnerID pgtype.Int4 `db:"org_owner_id" json:"org_owner_id"`
|
|
OrgOwnerID_2 pgtype.Int4 `db:"org_owner_id_2" json:"org_owner_id_2"`
|
|
}
|
|
|
|
func (q *Queries) TransferOrgProperties(ctx context.Context, arg *TransferOrgPropertiesParams) error {
|
|
_, err := q.db.Exec(ctx, transferOrgProperties, arg.OrgID, arg.OrgOwnerID, arg.OrgOwnerID_2)
|
|
return err
|
|
}
|
|
|
|
const updateProperty = `-- name: UpdateProperty :one
|
|
WITH old AS (
|
|
SELECT id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count FROM backend.properties p
|
|
WHERE p.id = $1 AND (p.creator_id = $9 OR p.org_owner_id = $9) AND (p.org_id = $10 OR $10 IS NULL)
|
|
FOR UPDATE
|
|
),
|
|
upd AS (
|
|
UPDATE backend.properties p
|
|
SET name = $2,
|
|
level = $3,
|
|
growth = $4,
|
|
validity_interval = $5,
|
|
allow_subdomains = $6,
|
|
allow_localhost = $7,
|
|
max_replay_count = $8,
|
|
updated_at = NOW()
|
|
WHERE p.id = (SELECT id FROM old)
|
|
RETURNING id, name, external_id, org_id, creator_id, org_owner_id, domain, level, salt, growth, created_at, updated_at, deleted_at, validity_interval, allow_subdomains, allow_localhost, max_replay_count -- This ensures the final SELECT only returns data if the update actually happened
|
|
)
|
|
SELECT
|
|
upd.id, upd.name, upd.external_id, upd.org_id, upd.creator_id, upd.org_owner_id, upd.domain, upd.level, upd.salt, upd.growth, upd.created_at, upd.updated_at, upd.deleted_at, upd.validity_interval, upd.allow_subdomains, upd.allow_localhost, upd.max_replay_count,
|
|
old.name AS old_name,
|
|
old.level AS old_level,
|
|
old.growth AS old_growth,
|
|
old.validity_interval AS old_validity_interval,
|
|
old.allow_subdomains AS old_allow_subdomains,
|
|
old.allow_localhost AS old_allow_localhost,
|
|
old.max_replay_count AS old_max_replay_count
|
|
FROM upd
|
|
CROSS JOIN old
|
|
`
|
|
|
|
type UpdatePropertyParams struct {
|
|
ID int32 `db:"id" json:"id"`
|
|
Name string `db:"name" json:"name"`
|
|
Level pgtype.Int2 `db:"level" json:"level"`
|
|
Growth DifficultyGrowth `db:"growth" json:"growth"`
|
|
ValidityInterval time.Duration `db:"validity_interval" json:"validity_interval"`
|
|
AllowSubdomains bool `db:"allow_subdomains" json:"allow_subdomains"`
|
|
AllowLocalhost bool `db:"allow_localhost" json:"allow_localhost"`
|
|
MaxReplayCount int32 `db:"max_replay_count" json:"max_replay_count"`
|
|
CreatorID pgtype.Int4 `db:"creator_id" json:"creator_id"`
|
|
OrgID pgtype.Int4 `db:"org_id" json:"org_id"`
|
|
}
|
|
|
|
type UpdatePropertyRow struct {
|
|
ID int32 `db:"id" json:"id"`
|
|
Name string `db:"name" json:"name"`
|
|
ExternalID pgtype.UUID `db:"external_id" json:"external_id"`
|
|
OrgID pgtype.Int4 `db:"org_id" json:"org_id"`
|
|
CreatorID pgtype.Int4 `db:"creator_id" json:"creator_id"`
|
|
OrgOwnerID pgtype.Int4 `db:"org_owner_id" json:"org_owner_id"`
|
|
Domain string `db:"domain" json:"domain"`
|
|
Level pgtype.Int2 `db:"level" json:"level"`
|
|
Salt []byte `db:"salt" json:"salt"`
|
|
Growth DifficultyGrowth `db:"growth" json:"growth"`
|
|
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
|
|
DeletedAt pgtype.Timestamptz `db:"deleted_at" json:"deleted_at"`
|
|
ValidityInterval time.Duration `db:"validity_interval" json:"validity_interval"`
|
|
AllowSubdomains bool `db:"allow_subdomains" json:"allow_subdomains"`
|
|
AllowLocalhost bool `db:"allow_localhost" json:"allow_localhost"`
|
|
MaxReplayCount int32 `db:"max_replay_count" json:"max_replay_count"`
|
|
OldName string `db:"old_name" json:"old_name"`
|
|
OldLevel pgtype.Int2 `db:"old_level" json:"old_level"`
|
|
OldGrowth DifficultyGrowth `db:"old_growth" json:"old_growth"`
|
|
OldValidityInterval time.Duration `db:"old_validity_interval" json:"old_validity_interval"`
|
|
OldAllowSubdomains bool `db:"old_allow_subdomains" json:"old_allow_subdomains"`
|
|
OldAllowLocalhost bool `db:"old_allow_localhost" json:"old_allow_localhost"`
|
|
OldMaxReplayCount int32 `db:"old_max_replay_count" json:"old_max_replay_count"`
|
|
}
|
|
|
|
func (q *Queries) UpdateProperty(ctx context.Context, arg *UpdatePropertyParams) (*UpdatePropertyRow, error) {
|
|
row := q.db.QueryRow(ctx, updateProperty,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.Level,
|
|
arg.Growth,
|
|
arg.ValidityInterval,
|
|
arg.AllowSubdomains,
|
|
arg.AllowLocalhost,
|
|
arg.MaxReplayCount,
|
|
arg.CreatorID,
|
|
arg.OrgID,
|
|
)
|
|
var i UpdatePropertyRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ExternalID,
|
|
&i.OrgID,
|
|
&i.CreatorID,
|
|
&i.OrgOwnerID,
|
|
&i.Domain,
|
|
&i.Level,
|
|
&i.Salt,
|
|
&i.Growth,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ValidityInterval,
|
|
&i.AllowSubdomains,
|
|
&i.AllowLocalhost,
|
|
&i.MaxReplayCount,
|
|
&i.OldName,
|
|
&i.OldLevel,
|
|
&i.OldGrowth,
|
|
&i.OldValidityInterval,
|
|
&i.OldAllowSubdomains,
|
|
&i.OldAllowLocalhost,
|
|
&i.OldMaxReplayCount,
|
|
)
|
|
return &i, err
|
|
}
|