Squash the pre-production migration history into fresh core, fedwiki, and stripe baselines and reduce the canonical source list to those three streams. Update sqlc configs, generated queries, raw SQL, tests, and docs while keeping provider tables schema-qualified. BREAKING: existing local database volumes must be wiped because goose version history restarts from the new baselines.
157 lines
4.0 KiB
Go
157 lines
4.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: workspaces.sql
|
|
|
|
package organization
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const countWorkspacesByOrgID = `-- name: CountWorkspacesByOrgID :one
|
|
SELECT COUNT(*) FROM core.workspaces
|
|
WHERE org_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountWorkspacesByOrgID(ctx context.Context, orgID string) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countWorkspacesByOrgID, orgID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createWorkspace = `-- name: CreateWorkspace :one
|
|
INSERT INTO core.workspaces (org_id, name, slug)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING workspace_id, org_id, name, slug, description, status, created_at, updated_at
|
|
`
|
|
|
|
type CreateWorkspaceParams struct {
|
|
OrgID string `json:"org_id"`
|
|
Name string `json:"name"`
|
|
Slug string `json:"slug"`
|
|
}
|
|
|
|
func (q *Queries) CreateWorkspace(ctx context.Context, arg CreateWorkspaceParams) (Workspace, error) {
|
|
row := q.db.QueryRowContext(ctx, createWorkspace, arg.OrgID, arg.Name, arg.Slug)
|
|
var i Workspace
|
|
err := row.Scan(
|
|
&i.WorkspaceID,
|
|
&i.OrgID,
|
|
&i.Name,
|
|
&i.Slug,
|
|
&i.Description,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ensureSystemWorkspace = `-- name: EnsureSystemWorkspace :exec
|
|
INSERT INTO core.workspaces (org_id, name, slug)
|
|
VALUES ($1, $2, $3)
|
|
ON CONFLICT (org_id, slug) DO NOTHING
|
|
`
|
|
|
|
type EnsureSystemWorkspaceParams struct {
|
|
OrgID string `json:"org_id"`
|
|
Name string `json:"name"`
|
|
Slug string `json:"slug"`
|
|
}
|
|
|
|
// Idempotently insert the System tenant's workspace (keyed on the unique
|
|
// org_id+slug). Only called when the system org has no workspace yet.
|
|
func (q *Queries) EnsureSystemWorkspace(ctx context.Context, arg EnsureSystemWorkspaceParams) error {
|
|
_, err := q.db.ExecContext(ctx, ensureSystemWorkspace, arg.OrgID, arg.Name, arg.Slug)
|
|
return err
|
|
}
|
|
|
|
const getSystemOrgWorkspace = `-- name: GetSystemOrgWorkspace :one
|
|
SELECT w.workspace_id, w.org_id, w.name, w.slug, w.description, w.status, w.created_at, w.updated_at FROM core.workspaces w
|
|
JOIN core.organizations o ON o.org_id = w.org_id
|
|
WHERE o.org_type = 'system'
|
|
ORDER BY w.created_at
|
|
LIMIT 1
|
|
`
|
|
|
|
// Natural-key resolver: the workspace of the singleton organization whose
|
|
// org_type is 'system'. Returns the oldest workspace so a pre-existing
|
|
// workspace (e.g. an ad-hoc seed using a different slug) is adopted rather
|
|
// than duplicated.
|
|
func (q *Queries) GetSystemOrgWorkspace(ctx context.Context) (Workspace, error) {
|
|
row := q.db.QueryRowContext(ctx, getSystemOrgWorkspace)
|
|
var i Workspace
|
|
err := row.Scan(
|
|
&i.WorkspaceID,
|
|
&i.OrgID,
|
|
&i.Name,
|
|
&i.Slug,
|
|
&i.Description,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getWorkspaceByID = `-- name: GetWorkspaceByID :one
|
|
SELECT workspace_id, org_id, name, slug, description, status, created_at, updated_at FROM core.workspaces
|
|
WHERE workspace_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetWorkspaceByID(ctx context.Context, workspaceID string) (Workspace, error) {
|
|
row := q.db.QueryRowContext(ctx, getWorkspaceByID, workspaceID)
|
|
var i Workspace
|
|
err := row.Scan(
|
|
&i.WorkspaceID,
|
|
&i.OrgID,
|
|
&i.Name,
|
|
&i.Slug,
|
|
&i.Description,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getWorkspacesByOrgID = `-- name: GetWorkspacesByOrgID :many
|
|
SELECT workspace_id, org_id, name, slug, description, status, created_at, updated_at FROM core.workspaces
|
|
WHERE org_id = $1
|
|
ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) GetWorkspacesByOrgID(ctx context.Context, orgID string) ([]Workspace, error) {
|
|
rows, err := q.db.QueryContext(ctx, getWorkspacesByOrgID, orgID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Workspace{}
|
|
for rows.Next() {
|
|
var i Workspace
|
|
if err := rows.Scan(
|
|
&i.WorkspaceID,
|
|
&i.OrgID,
|
|
&i.Name,
|
|
&i.Slug,
|
|
&i.Description,
|
|
&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
|
|
}
|