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
33 lines
929 B
SQL
33 lines
929 B
SQL
-- name: InsertChannel :one
|
|
INSERT INTO channels (id, team_id, name, provider, config, event_types)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING *;
|
|
|
|
-- name: ListChannelsByTeam :many
|
|
SELECT * FROM channels WHERE team_id = $1 ORDER BY created_at DESC;
|
|
|
|
-- name: GetChannelByTeam :one
|
|
SELECT * FROM channels WHERE id = $1 AND team_id = $2;
|
|
|
|
-- name: UpdateChannel :one
|
|
UPDATE channels SET name = $3, event_types = $4, updated_at = NOW()
|
|
WHERE id = $1 AND team_id = $2
|
|
RETURNING *;
|
|
|
|
-- name: UpdateChannelConfig :one
|
|
UPDATE channels SET config = $3, updated_at = NOW()
|
|
WHERE id = $1 AND team_id = $2
|
|
RETURNING *;
|
|
|
|
-- name: DeleteChannelByTeam :exec
|
|
DELETE FROM channels WHERE id = $1 AND team_id = $2;
|
|
|
|
-- name: DeleteAllChannelsByTeam :exec
|
|
DELETE FROM channels WHERE team_id = $1;
|
|
|
|
-- name: ListChannelsForEvent :many
|
|
SELECT * FROM channels
|
|
WHERE team_id = $1
|
|
AND sqlc.arg(event_type)::text = ANY(event_types)
|
|
ORDER BY created_at;
|