Files
Primora/apps/backend/internal/database/db/projects.sql.go
T
2026-04-10 12:03:31 +02:00

461 lines
12 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: projects.sql
package db
import (
"context"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
const addProjectMember = `-- name: AddProjectMember :one
INSERT INTO core.project_members (project_id, user_id, role)
VALUES ($1, $2, $3)
ON CONFLICT (project_id, user_id) DO UPDATE
SET role = EXCLUDED.role
RETURNING id, project_id, user_id, role, created_at
`
type AddProjectMemberParams struct {
ProjectID uuid.UUID `json:"project_id"`
UserID uuid.UUID `json:"user_id"`
Role string `json:"role"`
}
func (q *Queries) AddProjectMember(ctx context.Context, arg AddProjectMemberParams) (CoreProjectMember, error) {
row := q.db.QueryRow(ctx, addProjectMember, arg.ProjectID, arg.UserID, arg.Role)
var i CoreProjectMember
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.UserID,
&i.Role,
&i.CreatedAt,
)
return i, err
}
const countProjectAdmins = `-- name: CountProjectAdmins :one
SELECT COUNT(*)::BIGINT FROM core.project_members
WHERE project_id = $1
AND role = 'admin'
`
func (q *Queries) CountProjectAdmins(ctx context.Context, projectID uuid.UUID) (int64, error) {
row := q.db.QueryRow(ctx, countProjectAdmins, projectID)
var column_1 int64
err := row.Scan(&column_1)
return column_1, err
}
const createProject = `-- name: CreateProject :one
INSERT INTO core.projects (
organization_id,
slug,
name,
description
) VALUES ($1, $2, $3, $4)
RETURNING id, organization_id, slug, name, description, created_at
`
type CreateProjectParams struct {
OrganizationID uuid.UUID `json:"organization_id"`
Slug string `json:"slug"`
Name string `json:"name"`
Description *string `json:"description"`
}
func (q *Queries) CreateProject(ctx context.Context, arg CreateProjectParams) (CoreProject, error) {
row := q.db.QueryRow(ctx, createProject,
arg.OrganizationID,
arg.Slug,
arg.Name,
arg.Description,
)
var i CoreProject
err := row.Scan(
&i.ID,
&i.OrganizationID,
&i.Slug,
&i.Name,
&i.Description,
&i.CreatedAt,
)
return i, err
}
const deleteProjectByID = `-- name: DeleteProjectByID :one
DELETE FROM core.projects
WHERE id = $1
RETURNING id, organization_id, slug, name, description, created_at
`
func (q *Queries) DeleteProjectByID(ctx context.Context, id uuid.UUID) (CoreProject, error) {
row := q.db.QueryRow(ctx, deleteProjectByID, id)
var i CoreProject
err := row.Scan(
&i.ID,
&i.OrganizationID,
&i.Slug,
&i.Name,
&i.Description,
&i.CreatedAt,
)
return i, err
}
const getProjectByID = `-- name: GetProjectByID :one
SELECT id, organization_id, slug, name, description, created_at FROM core.projects
WHERE id = $1
`
func (q *Queries) GetProjectByID(ctx context.Context, id uuid.UUID) (CoreProject, error) {
row := q.db.QueryRow(ctx, getProjectByID, id)
var i CoreProject
err := row.Scan(
&i.ID,
&i.OrganizationID,
&i.Slug,
&i.Name,
&i.Description,
&i.CreatedAt,
)
return i, err
}
const getProjectMembership = `-- name: GetProjectMembership :one
SELECT
pm.id, pm.project_id, pm.user_id, pm.role, pm.created_at,
p.organization_id
FROM core.project_members pm
JOIN core.projects p ON p.id = pm.project_id
WHERE pm.project_id = $1
AND pm.user_id = $2
`
type GetProjectMembershipParams struct {
ProjectID uuid.UUID `json:"project_id"`
UserID uuid.UUID `json:"user_id"`
}
type GetProjectMembershipRow struct {
ID uuid.UUID `json:"id"`
ProjectID uuid.UUID `json:"project_id"`
UserID uuid.UUID `json:"user_id"`
Role string `json:"role"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
OrganizationID uuid.UUID `json:"organization_id"`
}
func (q *Queries) GetProjectMembership(ctx context.Context, arg GetProjectMembershipParams) (GetProjectMembershipRow, error) {
row := q.db.QueryRow(ctx, getProjectMembership, arg.ProjectID, arg.UserID)
var i GetProjectMembershipRow
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.UserID,
&i.Role,
&i.CreatedAt,
&i.OrganizationID,
)
return i, err
}
const getProjectOverview = `-- name: GetProjectOverview :one
SELECT
p.id AS project_id,
p.organization_id,
p.slug AS project_slug,
p.name AS project_name,
(
SELECT COUNT(*)::BIGINT
FROM core.project_members pm
WHERE pm.project_id = p.id
) AS member_count,
(
SELECT COUNT(*)::BIGINT
FROM core.api_keys ak
WHERE ak.project_id = p.id
AND ak.revoked_at IS NULL
) AS active_api_key_count,
(
SELECT COUNT(*)::BIGINT
FROM core.buckets b
WHERE b.project_id = p.id
) AS bucket_count,
(
SELECT COUNT(*)::BIGINT
FROM core.bucket_objects bo
JOIN core.buckets b ON b.id = bo.bucket_id
WHERE b.project_id = p.id
) AS object_count,
(
SELECT COALESCE(SUM(bo.size_bytes), 0)::BIGINT
FROM core.bucket_objects bo
JOIN core.buckets b ON b.id = bo.bucket_id
WHERE b.project_id = p.id
) AS object_bytes_total,
(
SELECT COUNT(*)::BIGINT
FROM core.project_invitations pi
WHERE pi.organization_id = p.organization_id
AND (pi.project_id IS NULL OR pi.project_id = p.id)
AND pi.accepted_at IS NULL
AND pi.expires_at > NOW()
) AS pending_invitation_count,
(
SELECT COUNT(*)::BIGINT
FROM core.audit_logs al
WHERE al.project_id = p.id
AND al.created_at >= NOW() - INTERVAL '24 hours'
) AS audit_events_24h,
(
SELECT MAX(al.created_at)::TIMESTAMPTZ
FROM core.audit_logs al
WHERE al.project_id = p.id
) AS last_audit_at
FROM core.projects p
WHERE p.id = $1
`
type GetProjectOverviewRow struct {
ProjectID uuid.UUID `json:"project_id"`
OrganizationID uuid.UUID `json:"organization_id"`
ProjectSlug string `json:"project_slug"`
ProjectName string `json:"project_name"`
MemberCount int64 `json:"member_count"`
ActiveApiKeyCount int64 `json:"active_api_key_count"`
BucketCount int64 `json:"bucket_count"`
ObjectCount int64 `json:"object_count"`
ObjectBytesTotal int64 `json:"object_bytes_total"`
PendingInvitationCount int64 `json:"pending_invitation_count"`
AuditEvents24h int64 `json:"audit_events_24h"`
LastAuditAt pgtype.Timestamptz `json:"last_audit_at"`
}
func (q *Queries) GetProjectOverview(ctx context.Context, id uuid.UUID) (GetProjectOverviewRow, error) {
row := q.db.QueryRow(ctx, getProjectOverview, id)
var i GetProjectOverviewRow
err := row.Scan(
&i.ProjectID,
&i.OrganizationID,
&i.ProjectSlug,
&i.ProjectName,
&i.MemberCount,
&i.ActiveApiKeyCount,
&i.BucketCount,
&i.ObjectCount,
&i.ObjectBytesTotal,
&i.PendingInvitationCount,
&i.AuditEvents24h,
&i.LastAuditAt,
)
return i, err
}
const listProjectMembers = `-- name: ListProjectMembers :many
SELECT
pm.project_id,
pm.user_id,
pm.role,
pm.created_at,
u.email,
u.name,
u.email_verified
FROM core.project_members pm
JOIN core.users u ON u.id = pm.user_id
WHERE pm.project_id = $1
ORDER BY pm.created_at ASC
`
type ListProjectMembersRow struct {
ProjectID uuid.UUID `json:"project_id"`
UserID uuid.UUID `json:"user_id"`
Role string `json:"role"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
Email string `json:"email"`
Name string `json:"name"`
EmailVerified bool `json:"email_verified"`
}
func (q *Queries) ListProjectMembers(ctx context.Context, projectID uuid.UUID) ([]ListProjectMembersRow, error) {
rows, err := q.db.Query(ctx, listProjectMembers, projectID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListProjectMembersRow
for rows.Next() {
var i ListProjectMembersRow
if err := rows.Scan(
&i.ProjectID,
&i.UserID,
&i.Role,
&i.CreatedAt,
&i.Email,
&i.Name,
&i.EmailVerified,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listProjectsForOrganization = `-- name: ListProjectsForOrganization :many
SELECT
p.id, p.organization_id, p.slug, p.name, p.description, p.created_at,
pm.role AS membership_role
FROM core.projects p
LEFT JOIN core.project_members pm
ON pm.project_id = p.id
AND pm.user_id = $2
WHERE p.organization_id = $1
AND (
btrim($3) = ''
OR p.slug ILIKE '%' || btrim($3) || '%'
OR p.name ILIKE '%' || btrim($3) || '%'
OR COALESCE(p.description, '') ILIKE '%' || btrim($3) || '%'
)
ORDER BY p.created_at ASC
`
type ListProjectsForOrganizationParams struct {
OrganizationID uuid.UUID `json:"organization_id"`
UserID uuid.UUID `json:"user_id"`
Btrim string `json:"btrim"`
}
type ListProjectsForOrganizationRow struct {
ID uuid.UUID `json:"id"`
OrganizationID uuid.UUID `json:"organization_id"`
Slug string `json:"slug"`
Name string `json:"name"`
Description *string `json:"description"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
MembershipRole NullCoreProjectRole `json:"membership_role"`
}
func (q *Queries) ListProjectsForOrganization(ctx context.Context, arg ListProjectsForOrganizationParams) ([]ListProjectsForOrganizationRow, error) {
rows, err := q.db.Query(ctx, listProjectsForOrganization, arg.OrganizationID, arg.UserID, arg.Btrim)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListProjectsForOrganizationRow
for rows.Next() {
var i ListProjectsForOrganizationRow
if err := rows.Scan(
&i.ID,
&i.OrganizationID,
&i.Slug,
&i.Name,
&i.Description,
&i.CreatedAt,
&i.MembershipRole,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const removeProjectMember = `-- name: RemoveProjectMember :one
DELETE FROM core.project_members
WHERE project_id = $1
AND user_id = $2
RETURNING id, project_id, user_id, role, created_at
`
type RemoveProjectMemberParams struct {
ProjectID uuid.UUID `json:"project_id"`
UserID uuid.UUID `json:"user_id"`
}
func (q *Queries) RemoveProjectMember(ctx context.Context, arg RemoveProjectMemberParams) (CoreProjectMember, error) {
row := q.db.QueryRow(ctx, removeProjectMember, arg.ProjectID, arg.UserID)
var i CoreProjectMember
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.UserID,
&i.Role,
&i.CreatedAt,
)
return i, err
}
const updateProjectByID = `-- name: UpdateProjectByID :one
UPDATE core.projects
SET slug = $2,
name = $3,
description = $4
WHERE id = $1
RETURNING id, organization_id, slug, name, description, created_at
`
type UpdateProjectByIDParams struct {
ID uuid.UUID `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
Description *string `json:"description"`
}
func (q *Queries) UpdateProjectByID(ctx context.Context, arg UpdateProjectByIDParams) (CoreProject, error) {
row := q.db.QueryRow(ctx, updateProjectByID,
arg.ID,
arg.Slug,
arg.Name,
arg.Description,
)
var i CoreProject
err := row.Scan(
&i.ID,
&i.OrganizationID,
&i.Slug,
&i.Name,
&i.Description,
&i.CreatedAt,
)
return i, err
}
const updateProjectMemberRole = `-- name: UpdateProjectMemberRole :one
UPDATE core.project_members
SET role = $3
WHERE project_id = $1
AND user_id = $2
RETURNING id, project_id, user_id, role, created_at
`
type UpdateProjectMemberRoleParams struct {
ProjectID uuid.UUID `json:"project_id"`
UserID uuid.UUID `json:"user_id"`
Role string `json:"role"`
}
func (q *Queries) UpdateProjectMemberRole(ctx context.Context, arg UpdateProjectMemberRoleParams) (CoreProjectMember, error) {
row := q.db.QueryRow(ctx, updateProjectMemberRole, arg.ProjectID, arg.UserID, arg.Role)
var i CoreProjectMember
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.UserID,
&i.Role,
&i.CreatedAt,
)
return i, err
}