Files
member-console/internal/organization/organizations.sql.go
T
cgalo5758 257955c9d3 Add operator list-scale contract and People directory
Governed operator lists (organizations, grants, people, billing×4) gain
server-side search, status filters, and 50-row pages with true totals
from count(*) OVER(); state is URL-addressable, out-of-range pages
clamp,
and no-match is distinct from true-empty.

People is the eighth flat sidebar entry: /operator/persons lists persons
newest-joined first (excluding the reserved system person), rows linking
to the existing detail.

Billing gains an operator invoice detail at
/operator/billing/invoices/{invoiceID} reusing the member projection;
open invoices past due present as Overdue (derived, filterable, stored
status untouched); all four views lead with the linked organization and
mute object IDs.

Grants filter over the derived Live/Superseded/Inactive state, the SQL
HAVING predicate pinned to the Go derivation by test. Embedded lists
(org composite ledger, Tier changes) adopt the shared controls under
namespaced params with sibling-state-preserving URLs and scoped htmx
swaps that hold the viewport.

Review corrections: blocked ladder Delete renders disabled with tooltip
and mutations fire toasts; collapse triggers paint their open state;
sections use outside headings; plan topology drops the orphan-product
check; domains policy collapses behind a disclosure.
2026-08-24 03:58:18 -05:00

341 lines
9.5 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: organizations.sql
package organization
import (
"context"
"database/sql"
"time"
)
const countTeamOrganizations = `-- name: CountTeamOrganizations :one
SELECT COUNT(*) FROM core.organizations o
JOIN core.org_types t ON t.org_type = o.org_type
WHERE o.status = 'active' AND o.org_type <> 'personal' AND NOT t.is_reserved
`
// Operator overview headline. Personal orgs exist one-per-member by
// structural convention (design/organization/architecture.md §2), so an
// organizations count that includes them tracks the people count and reads
// as an error. Negative-space predicate instead of org_type = 'team':
// everything active that is neither the auto-created personal type nor a
// reserved type counts, so team, enterprise, and deployment-defined types
// need no code change here and the reserved system org never appears.
func (q *Queries) CountTeamOrganizations(ctx context.Context) (int64, error) {
row := q.db.QueryRowContext(ctx, countTeamOrganizations)
var count int64
err := row.Scan(&count)
return count, err
}
const createOrganization = `-- name: CreateOrganization :one
INSERT INTO core.organizations (name, slug, org_type, owner_person_id)
VALUES ($1, $2, $3, $4)
RETURNING org_id, name, slug, org_type, owner_person_id, status, created_at, updated_at
`
type CreateOrganizationParams struct {
Name string `json:"name"`
Slug string `json:"slug"`
OrgType string `json:"org_type"`
OwnerPersonID string `json:"owner_person_id"`
}
func (q *Queries) CreateOrganization(ctx context.Context, arg CreateOrganizationParams) (Organization, error) {
row := q.db.QueryRowContext(ctx, createOrganization,
arg.Name,
arg.Slug,
arg.OrgType,
arg.OwnerPersonID,
)
var i Organization
err := row.Scan(
&i.OrgID,
&i.Name,
&i.Slug,
&i.OrgType,
&i.OwnerPersonID,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const ensureSystemOrganization = `-- name: EnsureSystemOrganization :exec
INSERT INTO core.organizations (name, slug, org_type, owner_person_id)
VALUES ($1, $2, $3, $4)
ON CONFLICT (slug) DO NOTHING
`
type EnsureSystemOrganizationParams struct {
Name string `json:"name"`
Slug string `json:"slug"`
OrgType string `json:"org_type"`
OwnerPersonID string `json:"owner_person_id"`
}
// Idempotently insert the singleton System organization (keyed on the unique
// slug). Read back with GetOrganizationBySlug.
func (q *Queries) EnsureSystemOrganization(ctx context.Context, arg EnsureSystemOrganizationParams) error {
_, err := q.db.ExecContext(ctx, ensureSystemOrganization,
arg.Name,
arg.Slug,
arg.OrgType,
arg.OwnerPersonID,
)
return err
}
const getOrganizationByID = `-- name: GetOrganizationByID :one
SELECT org_id, name, slug, org_type, owner_person_id, status, created_at, updated_at FROM core.organizations
WHERE org_id = $1
`
func (q *Queries) GetOrganizationByID(ctx context.Context, orgID string) (Organization, error) {
row := q.db.QueryRowContext(ctx, getOrganizationByID, orgID)
var i Organization
err := row.Scan(
&i.OrgID,
&i.Name,
&i.Slug,
&i.OrgType,
&i.OwnerPersonID,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getOrganizationBySlug = `-- name: GetOrganizationBySlug :one
SELECT org_id, name, slug, org_type, owner_person_id, status, created_at, updated_at FROM core.organizations
WHERE slug = $1
`
func (q *Queries) GetOrganizationBySlug(ctx context.Context, slug string) (Organization, error) {
row := q.db.QueryRowContext(ctx, getOrganizationBySlug, slug)
var i Organization
err := row.Scan(
&i.OrgID,
&i.Name,
&i.Slug,
&i.OrgType,
&i.OwnerPersonID,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getOrganizationsByOwner = `-- name: GetOrganizationsByOwner :many
SELECT org_id, name, slug, org_type, owner_person_id, status, created_at, updated_at FROM core.organizations
WHERE owner_person_id = $1
ORDER BY name
`
func (q *Queries) GetOrganizationsByOwner(ctx context.Context, ownerPersonID string) ([]Organization, error) {
rows, err := q.db.QueryContext(ctx, getOrganizationsByOwner, ownerPersonID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Organization{}
for rows.Next() {
var i Organization
if err := rows.Scan(
&i.OrgID,
&i.Name,
&i.Slug,
&i.OrgType,
&i.OwnerPersonID,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listOrganizations = `-- name: ListOrganizations :many
SELECT org_id, name, slug, org_type, owner_person_id, status, created_at, updated_at FROM core.organizations
ORDER BY name
`
func (q *Queries) ListOrganizations(ctx context.Context) ([]Organization, error) {
rows, err := q.db.QueryContext(ctx, listOrganizations)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Organization{}
for rows.Next() {
var i Organization
if err := rows.Scan(
&i.OrgID,
&i.Name,
&i.Slug,
&i.OrgType,
&i.OwnerPersonID,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listOrganizationsByType = `-- name: ListOrganizationsByType :many
SELECT org_id, name, slug, org_type, owner_person_id, status, created_at, updated_at FROM core.organizations
WHERE org_type = $1
ORDER BY name
`
func (q *Queries) ListOrganizationsByType(ctx context.Context, orgType string) ([]Organization, error) {
rows, err := q.db.QueryContext(ctx, listOrganizationsByType, orgType)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Organization{}
for rows.Next() {
var i Organization
if err := rows.Scan(
&i.OrgID,
&i.Name,
&i.Slug,
&i.OrgType,
&i.OwnerPersonID,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listOrganizationsPage = `-- name: ListOrganizationsPage :many
SELECT o.org_id, o.name, o.slug, o.org_type, o.owner_person_id, o.status, o.created_at, o.updated_at,
p.display_name AS owner_display_name,
count(*) OVER() AS total_count
FROM core.organizations o
LEFT JOIN core.persons p ON p.person_id = o.owner_person_id
WHERE ($1::text IS NULL
OR o.name ILIKE '%' || $1::text || '%'
OR o.slug ILIKE '%' || $1::text || '%'
OR p.display_name ILIKE '%' || $1::text || '%'
OR p.primary_email ILIKE '%' || $1::text || '%')
AND ($2::text IS NULL OR o.org_type = $2::text)
ORDER BY o.name
LIMIT $4::int OFFSET $3::int
`
type ListOrganizationsPageParams struct {
Q sql.NullString `json:"q"`
OrgType sql.NullString `json:"org_type"`
PageOffset int32 `json:"page_offset"`
PageLimit int32 `json:"page_limit"`
}
type ListOrganizationsPageRow struct {
OrgID string `json:"org_id"`
Name string `json:"name"`
Slug string `json:"slug"`
OrgType string `json:"org_type"`
OwnerPersonID string `json:"owner_person_id"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
OwnerDisplayName sql.NullString `json:"owner_display_name"`
TotalCount int64 `json:"total_count"`
}
// Organizations list operator surface (operator-list-scale UX-4): the
// paged, searched, org-type-filtered successor to ListOrganizationsWithOwner
// -- each row still carries its owner's display name so no organization can
// read as unowned (ux-honest-surfaces UX-16). owner_person_id is NOT NULL
// (every organization has an owner person, the System tenant included --
// 00001_init.sql), so the LEFT JOIN is defensive rather than expected to
// ever drop the owner's name.
//
// sqlc.narg(q): NULL matches every row; set, a case-insensitive substring
// match against the organization's name or slug, or its owner's display
// name or primary email (operator-list-scale: "carries a scoped
// server-side search" -- "organizations: name, slug, and owner name or
// email").
// sqlc.narg(org_type): NULL matches every org type; set, an exact facet
// match (operator-list-scale: "Status filters exist ... organizations: org
// type").
// count(*) OVER() carries the true total for the filtered set alongside
// the page's rows (design D2), so the stated total never reflects only the
// page.
func (q *Queries) ListOrganizationsPage(ctx context.Context, arg ListOrganizationsPageParams) ([]ListOrganizationsPageRow, error) {
rows, err := q.db.QueryContext(ctx, listOrganizationsPage,
arg.Q,
arg.OrgType,
arg.PageOffset,
arg.PageLimit,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListOrganizationsPageRow{}
for rows.Next() {
var i ListOrganizationsPageRow
if err := rows.Scan(
&i.OrgID,
&i.Name,
&i.Slug,
&i.OrgType,
&i.OwnerPersonID,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
&i.OwnerDisplayName,
&i.TotalCount,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}