Add a goose migration to create core and fedwiki schemas and move existing domain tables using ALTER TABLE IF EXISTS. Set connection search_path to "core, public" after successful DB ping. Update FedWiki SQL and sqlc.yaml to use fedwiki.sites and include db migrations for schema awareness. Add design docs, specs, and tasks for schema-namespacing and the migration plan.
207 lines
4.9 KiB
Go
207 lines
4.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: sites.sql
|
|
|
|
package fedwiki
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const countSitesByWorkspace = `-- name: CountSitesByWorkspace :one
|
|
SELECT COUNT(*) AS count FROM fedwiki.sites
|
|
WHERE workspace_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountSitesByWorkspace(ctx context.Context, workspaceID string) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countSitesByWorkspace, workspaceID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createSite = `-- name: CreateSite :one
|
|
INSERT INTO fedwiki.sites (workspace_id, domain, is_custom_domain)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING site_id, workspace_id, domain, is_custom_domain, created_at, updated_at
|
|
`
|
|
|
|
type CreateSiteParams struct {
|
|
WorkspaceID string `json:"workspace_id"`
|
|
Domain string `json:"domain"`
|
|
IsCustomDomain bool `json:"is_custom_domain"`
|
|
}
|
|
|
|
func (q *Queries) CreateSite(ctx context.Context, arg CreateSiteParams) (Site, error) {
|
|
row := q.db.QueryRowContext(ctx, createSite, arg.WorkspaceID, arg.Domain, arg.IsCustomDomain)
|
|
var i Site
|
|
err := row.Scan(
|
|
&i.SiteID,
|
|
&i.WorkspaceID,
|
|
&i.Domain,
|
|
&i.IsCustomDomain,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteSite = `-- name: DeleteSite :exec
|
|
DELETE FROM fedwiki.sites
|
|
WHERE site_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteSite(ctx context.Context, siteID string) error {
|
|
_, err := q.db.ExecContext(ctx, deleteSite, siteID)
|
|
return err
|
|
}
|
|
|
|
const deleteSiteByDomain = `-- name: DeleteSiteByDomain :exec
|
|
DELETE FROM fedwiki.sites
|
|
WHERE domain = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteSiteByDomain(ctx context.Context, domain string) error {
|
|
_, err := q.db.ExecContext(ctx, deleteSiteByDomain, domain)
|
|
return err
|
|
}
|
|
|
|
const getSiteByDomain = `-- name: GetSiteByDomain :one
|
|
SELECT site_id, workspace_id, domain, is_custom_domain, created_at, updated_at FROM fedwiki.sites
|
|
WHERE domain = $1
|
|
`
|
|
|
|
func (q *Queries) GetSiteByDomain(ctx context.Context, domain string) (Site, error) {
|
|
row := q.db.QueryRowContext(ctx, getSiteByDomain, domain)
|
|
var i Site
|
|
err := row.Scan(
|
|
&i.SiteID,
|
|
&i.WorkspaceID,
|
|
&i.Domain,
|
|
&i.IsCustomDomain,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getSiteByID = `-- name: GetSiteByID :one
|
|
SELECT site_id, workspace_id, domain, is_custom_domain, created_at, updated_at FROM fedwiki.sites
|
|
WHERE site_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetSiteByID(ctx context.Context, siteID string) (Site, error) {
|
|
row := q.db.QueryRowContext(ctx, getSiteByID, siteID)
|
|
var i Site
|
|
err := row.Scan(
|
|
&i.SiteID,
|
|
&i.WorkspaceID,
|
|
&i.Domain,
|
|
&i.IsCustomDomain,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listAllSites = `-- name: ListAllSites :many
|
|
SELECT site_id, workspace_id, domain, is_custom_domain, created_at, updated_at FROM fedwiki.sites
|
|
ORDER BY domain ASC
|
|
`
|
|
|
|
func (q *Queries) ListAllSites(ctx context.Context) ([]Site, error) {
|
|
rows, err := q.db.QueryContext(ctx, listAllSites)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Site{}
|
|
for rows.Next() {
|
|
var i Site
|
|
if err := rows.Scan(
|
|
&i.SiteID,
|
|
&i.WorkspaceID,
|
|
&i.Domain,
|
|
&i.IsCustomDomain,
|
|
&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 listSitesByWorkspace = `-- name: ListSitesByWorkspace :many
|
|
SELECT site_id, workspace_id, domain, is_custom_domain, created_at, updated_at FROM fedwiki.sites
|
|
WHERE workspace_id = $1
|
|
ORDER BY domain ASC
|
|
`
|
|
|
|
func (q *Queries) ListSitesByWorkspace(ctx context.Context, workspaceID string) ([]Site, error) {
|
|
rows, err := q.db.QueryContext(ctx, listSitesByWorkspace, workspaceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Site{}
|
|
for rows.Next() {
|
|
var i Site
|
|
if err := rows.Scan(
|
|
&i.SiteID,
|
|
&i.WorkspaceID,
|
|
&i.Domain,
|
|
&i.IsCustomDomain,
|
|
&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 upsertSiteByDomain = `-- name: UpsertSiteByDomain :one
|
|
INSERT INTO fedwiki.sites (workspace_id, domain, is_custom_domain)
|
|
VALUES ($1, $2, $3)
|
|
ON CONFLICT(domain) DO UPDATE SET
|
|
workspace_id = excluded.workspace_id,
|
|
updated_at = NOW()
|
|
RETURNING site_id, workspace_id, domain, is_custom_domain, created_at, updated_at
|
|
`
|
|
|
|
type UpsertSiteByDomainParams struct {
|
|
WorkspaceID string `json:"workspace_id"`
|
|
Domain string `json:"domain"`
|
|
IsCustomDomain bool `json:"is_custom_domain"`
|
|
}
|
|
|
|
func (q *Queries) UpsertSiteByDomain(ctx context.Context, arg UpsertSiteByDomainParams) (Site, error) {
|
|
row := q.db.QueryRowContext(ctx, upsertSiteByDomain, arg.WorkspaceID, arg.Domain, arg.IsCustomDomain)
|
|
var i Site
|
|
err := row.Scan(
|
|
&i.SiteID,
|
|
&i.WorkspaceID,
|
|
&i.Domain,
|
|
&i.IsCustomDomain,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|