forked from wrenn/wrenn
- Add ON DELETE CASCADE to users_teams, oauth_providers, admin_permissions and ON DELETE SET NULL (with nullable columns) to team_api_keys.created_by, hosts.created_by, host_tokens.created_by so HardDeleteExpiredUsers no longer fails with FK violations - User account deletion now cascades to sole-owned teams via DeleteTeamInternal, preventing orphaned teams with live sandboxes after account removal - ListActiveSandboxesByTeam now includes hibernated sandboxes so their disk snapshots are cleaned up during team deletion - Team soft-delete now hard-deletes sandbox metric points, metric snapshots, API keys, and channels to prevent data accumulation on deleted teams - Extract deleteTeamCore() to deduplicate shared logic across DeleteTeam, AdminDeleteTeam, and DeleteTeamInternal - Fix ListAPIKeysByTeamWithCreator to use LEFT JOIN after created_by became nullable, and update handler to read pgtype.Text.String for creator_email
235 lines
5.5 KiB
Go
235 lines
5.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: channels.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const deleteAllChannelsByTeam = `-- name: DeleteAllChannelsByTeam :exec
|
|
DELETE FROM channels WHERE team_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteAllChannelsByTeam(ctx context.Context, teamID pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteAllChannelsByTeam, teamID)
|
|
return err
|
|
}
|
|
|
|
const deleteChannelByTeam = `-- name: DeleteChannelByTeam :exec
|
|
DELETE FROM channels WHERE id = $1 AND team_id = $2
|
|
`
|
|
|
|
type DeleteChannelByTeamParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteChannelByTeam(ctx context.Context, arg DeleteChannelByTeamParams) error {
|
|
_, err := q.db.Exec(ctx, deleteChannelByTeam, arg.ID, arg.TeamID)
|
|
return err
|
|
}
|
|
|
|
const getChannelByTeam = `-- name: GetChannelByTeam :one
|
|
SELECT id, team_id, name, provider, config, event_types, created_at, updated_at FROM channels WHERE id = $1 AND team_id = $2
|
|
`
|
|
|
|
type GetChannelByTeamParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
}
|
|
|
|
func (q *Queries) GetChannelByTeam(ctx context.Context, arg GetChannelByTeamParams) (Channel, error) {
|
|
row := q.db.QueryRow(ctx, getChannelByTeam, arg.ID, arg.TeamID)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertChannel = `-- name: InsertChannel :one
|
|
INSERT INTO channels (id, team_id, name, provider, config, event_types)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING id, team_id, name, provider, config, event_types, created_at, updated_at
|
|
`
|
|
|
|
type InsertChannelParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
Name string `json:"name"`
|
|
Provider string `json:"provider"`
|
|
Config []byte `json:"config"`
|
|
EventTypes []string `json:"event_types"`
|
|
}
|
|
|
|
func (q *Queries) InsertChannel(ctx context.Context, arg InsertChannelParams) (Channel, error) {
|
|
row := q.db.QueryRow(ctx, insertChannel,
|
|
arg.ID,
|
|
arg.TeamID,
|
|
arg.Name,
|
|
arg.Provider,
|
|
arg.Config,
|
|
arg.EventTypes,
|
|
)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listChannelsByTeam = `-- name: ListChannelsByTeam :many
|
|
SELECT id, team_id, name, provider, config, event_types, created_at, updated_at FROM channels WHERE team_id = $1 ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListChannelsByTeam(ctx context.Context, teamID pgtype.UUID) ([]Channel, error) {
|
|
rows, err := q.db.Query(ctx, listChannelsByTeam, teamID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Channel
|
|
for rows.Next() {
|
|
var i Channel
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listChannelsForEvent = `-- name: ListChannelsForEvent :many
|
|
SELECT id, team_id, name, provider, config, event_types, created_at, updated_at FROM channels
|
|
WHERE team_id = $1
|
|
AND $2::text = ANY(event_types)
|
|
ORDER BY created_at
|
|
`
|
|
|
|
type ListChannelsForEventParams struct {
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
EventType string `json:"event_type"`
|
|
}
|
|
|
|
func (q *Queries) ListChannelsForEvent(ctx context.Context, arg ListChannelsForEventParams) ([]Channel, error) {
|
|
rows, err := q.db.Query(ctx, listChannelsForEvent, arg.TeamID, arg.EventType)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Channel
|
|
for rows.Next() {
|
|
var i Channel
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateChannel = `-- name: UpdateChannel :one
|
|
UPDATE channels SET name = $3, event_types = $4, updated_at = NOW()
|
|
WHERE id = $1 AND team_id = $2
|
|
RETURNING id, team_id, name, provider, config, event_types, created_at, updated_at
|
|
`
|
|
|
|
type UpdateChannelParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
Name string `json:"name"`
|
|
EventTypes []string `json:"event_types"`
|
|
}
|
|
|
|
func (q *Queries) UpdateChannel(ctx context.Context, arg UpdateChannelParams) (Channel, error) {
|
|
row := q.db.QueryRow(ctx, updateChannel,
|
|
arg.ID,
|
|
arg.TeamID,
|
|
arg.Name,
|
|
arg.EventTypes,
|
|
)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateChannelConfig = `-- name: UpdateChannelConfig :one
|
|
UPDATE channels SET config = $3, updated_at = NOW()
|
|
WHERE id = $1 AND team_id = $2
|
|
RETURNING id, team_id, name, provider, config, event_types, created_at, updated_at
|
|
`
|
|
|
|
type UpdateChannelConfigParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
Config []byte `json:"config"`
|
|
}
|
|
|
|
func (q *Queries) UpdateChannelConfig(ctx context.Context, arg UpdateChannelConfigParams) (Channel, error) {
|
|
row := q.db.QueryRow(ctx, updateChannelConfig, arg.ID, arg.TeamID, arg.Config)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|