Drop redundant schema prefixes from all sqlc-generated Go types. Since each module generates into its own package, the package already provides the namespace — billing.Account is unambiguous without billing.BillingAccount. Changes: - Add rename: blocks to all 6 sqlc.yaml files mapping schema-prefixed names to clean idiomatic names (e.g. BillingBillingAccount → Account, IdentityPerson → Person, OrganizationOrganization → Organization) - Rename billing.billing_accounts → billing.accounts (table name repeated the schema; the schema already provides that context) - Rename integration.integration_outbox → integration.outbox (same reason) - Regenerate all sqlc output across billing, identity, organization, entitlements, stripe, and fedwiki modules - Update all calling code (server, workflows, provisioning, tests) to use the new names - Add internal/db/sqlc_schemas.sql — sqlc-only schema declarations so every module can resolve schema-qualified names without including the full db migrations - Update docs/database-management.md with the naming convention and standard sqlc.yaml template Convention going forward: table names must not repeat the schema name; generated types carry no schema prefix; the Go package provides the namespace (like http.Request, not http.HttpRequest).
133 lines
3.6 KiB
Go
133 lines
3.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: roles.sql
|
|
|
|
package organization
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/lib/pq"
|
|
)
|
|
|
|
const createRoleAssignment = `-- name: CreateRoleAssignment :one
|
|
INSERT INTO organization.role_assignments (role_id, person_id, org_id, scope_type, scope_id)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING assignment_id, role_id, person_id, org_id, scope_type, scope_id, created_at, updated_at
|
|
`
|
|
|
|
type CreateRoleAssignmentParams struct {
|
|
RoleID string `json:"role_id"`
|
|
PersonID string `json:"person_id"`
|
|
OrgID string `json:"org_id"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID string `json:"scope_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateRoleAssignment(ctx context.Context, arg CreateRoleAssignmentParams) (RoleAssignment, error) {
|
|
row := q.db.QueryRowContext(ctx, createRoleAssignment,
|
|
arg.RoleID,
|
|
arg.PersonID,
|
|
arg.OrgID,
|
|
arg.ScopeType,
|
|
arg.ScopeID,
|
|
)
|
|
var i RoleAssignment
|
|
err := row.Scan(
|
|
&i.AssignmentID,
|
|
&i.RoleID,
|
|
&i.PersonID,
|
|
&i.OrgID,
|
|
&i.ScopeType,
|
|
&i.ScopeID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getRoleAssignmentsByPersonAndOrg = `-- name: GetRoleAssignmentsByPersonAndOrg :many
|
|
SELECT ra.assignment_id, ra.role_id, ra.person_id, ra.org_id, ra.scope_type, ra.scope_id, ra.created_at, ra.updated_at, r.role_name, r.display_name as role_display_name, r.permissions
|
|
FROM organization.role_assignments ra
|
|
JOIN organization.roles r ON r.role_id = ra.role_id
|
|
WHERE ra.person_id = $1 AND ra.org_id = $2
|
|
`
|
|
|
|
type GetRoleAssignmentsByPersonAndOrgParams struct {
|
|
PersonID string `json:"person_id"`
|
|
OrgID string `json:"org_id"`
|
|
}
|
|
|
|
type GetRoleAssignmentsByPersonAndOrgRow struct {
|
|
AssignmentID string `json:"assignment_id"`
|
|
RoleID string `json:"role_id"`
|
|
PersonID string `json:"person_id"`
|
|
OrgID string `json:"org_id"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID string `json:"scope_id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
RoleName string `json:"role_name"`
|
|
RoleDisplayName string `json:"role_display_name"`
|
|
Permissions []string `json:"permissions"`
|
|
}
|
|
|
|
func (q *Queries) GetRoleAssignmentsByPersonAndOrg(ctx context.Context, arg GetRoleAssignmentsByPersonAndOrgParams) ([]GetRoleAssignmentsByPersonAndOrgRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getRoleAssignmentsByPersonAndOrg, arg.PersonID, arg.OrgID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetRoleAssignmentsByPersonAndOrgRow{}
|
|
for rows.Next() {
|
|
var i GetRoleAssignmentsByPersonAndOrgRow
|
|
if err := rows.Scan(
|
|
&i.AssignmentID,
|
|
&i.RoleID,
|
|
&i.PersonID,
|
|
&i.OrgID,
|
|
&i.ScopeType,
|
|
&i.ScopeID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.RoleName,
|
|
&i.RoleDisplayName,
|
|
pq.Array(&i.Permissions),
|
|
); 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 getSystemRoleByName = `-- name: GetSystemRoleByName :one
|
|
SELECT role_id, org_id, role_name, display_name, description, is_system, permissions, created_at, updated_at FROM organization.roles
|
|
WHERE role_name = $1 AND is_system = TRUE
|
|
`
|
|
|
|
func (q *Queries) GetSystemRoleByName(ctx context.Context, roleName string) (Role, error) {
|
|
row := q.db.QueryRowContext(ctx, getSystemRoleByName, roleName)
|
|
var i Role
|
|
err := row.Scan(
|
|
&i.RoleID,
|
|
&i.OrgID,
|
|
&i.RoleName,
|
|
&i.DisplayName,
|
|
&i.Description,
|
|
&i.IsSystem,
|
|
pq.Array(&i.Permissions),
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|