feat: add tenant and user management with migrations, handlers, and tests
- Implemented tenant and user management features including: - Tenant creation and management with associated migrations. - User creation and management with associated migrations. - Tenant membership management with associated migrations. - Platform user roles management with associated migrations. - Quota management with associated migrations. - Article and template management with associated migrations. - Added HTTP handlers for templates and workspaces. - Created tests for protected and public routes. - Introduced a script to check tenant scope in SQL queries. - Documented task plan for backend completion and frontend foundation.
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: template.sql
|
||||
|
||||
package generated
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getTemplateByID = `-- name: GetTemplateByID :one
|
||||
SELECT id, scope, tenant_id, origin_type, template_key, template_name,
|
||||
schema_json, prompt_template, prompt_visibility, protected_prompt_asset_key,
|
||||
card_config_json, status, version_no, created_at, updated_at
|
||||
FROM article_templates
|
||||
WHERE id = $1
|
||||
AND (scope = 'platform' OR tenant_id = $2::bigint)
|
||||
AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetTemplateByIDParams struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
}
|
||||
|
||||
type GetTemplateByIDRow struct {
|
||||
ID int64 `json:"id"`
|
||||
Scope string `json:"scope"`
|
||||
TenantID pgtype.Int8 `json:"tenant_id"`
|
||||
OriginType string `json:"origin_type"`
|
||||
TemplateKey string `json:"template_key"`
|
||||
TemplateName string `json:"template_name"`
|
||||
SchemaJson []byte `json:"schema_json"`
|
||||
PromptTemplate pgtype.Text `json:"prompt_template"`
|
||||
PromptVisibility string `json:"prompt_visibility"`
|
||||
ProtectedPromptAssetKey pgtype.Text `json:"protected_prompt_asset_key"`
|
||||
CardConfigJson []byte `json:"card_config_json"`
|
||||
Status string `json:"status"`
|
||||
VersionNo int32 `json:"version_no"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTemplateByID(ctx context.Context, arg GetTemplateByIDParams) (GetTemplateByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, getTemplateByID, arg.ID, arg.TenantID)
|
||||
var i GetTemplateByIDRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Scope,
|
||||
&i.TenantID,
|
||||
&i.OriginType,
|
||||
&i.TemplateKey,
|
||||
&i.TemplateName,
|
||||
&i.SchemaJson,
|
||||
&i.PromptTemplate,
|
||||
&i.PromptVisibility,
|
||||
&i.ProtectedPromptAssetKey,
|
||||
&i.CardConfigJson,
|
||||
&i.Status,
|
||||
&i.VersionNo,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getTemplateSchema = `-- name: GetTemplateSchema :one
|
||||
SELECT id, template_name, schema_json
|
||||
FROM article_templates
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetTemplateSchemaRow struct {
|
||||
ID int64 `json:"id"`
|
||||
TemplateName string `json:"template_name"`
|
||||
SchemaJson []byte `json:"schema_json"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTemplateSchema(ctx context.Context, id int64) (GetTemplateSchemaRow, error) {
|
||||
row := q.db.QueryRow(ctx, getTemplateSchema, id)
|
||||
var i GetTemplateSchemaRow
|
||||
err := row.Scan(&i.ID, &i.TemplateName, &i.SchemaJson)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listTemplates = `-- name: ListTemplates :many
|
||||
SELECT id, scope, tenant_id, origin_type, template_key, template_name,
|
||||
schema_json, prompt_template, prompt_visibility, card_config_json,
|
||||
status, version_no, created_at, updated_at
|
||||
FROM article_templates
|
||||
WHERE (scope = 'platform' OR tenant_id = $1::bigint)
|
||||
AND status = 'active' AND deleted_at IS NULL
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
type ListTemplatesRow struct {
|
||||
ID int64 `json:"id"`
|
||||
Scope string `json:"scope"`
|
||||
TenantID pgtype.Int8 `json:"tenant_id"`
|
||||
OriginType string `json:"origin_type"`
|
||||
TemplateKey string `json:"template_key"`
|
||||
TemplateName string `json:"template_name"`
|
||||
SchemaJson []byte `json:"schema_json"`
|
||||
PromptTemplate pgtype.Text `json:"prompt_template"`
|
||||
PromptVisibility string `json:"prompt_visibility"`
|
||||
CardConfigJson []byte `json:"card_config_json"`
|
||||
Status string `json:"status"`
|
||||
VersionNo int32 `json:"version_no"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTemplates(ctx context.Context, tenantID int64) ([]ListTemplatesRow, error) {
|
||||
rows, err := q.db.Query(ctx, listTemplates, tenantID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListTemplatesRow
|
||||
for rows.Next() {
|
||||
var i ListTemplatesRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Scope,
|
||||
&i.TenantID,
|
||||
&i.OriginType,
|
||||
&i.TemplateKey,
|
||||
&i.TemplateName,
|
||||
&i.SchemaJson,
|
||||
&i.PromptTemplate,
|
||||
&i.PromptVisibility,
|
||||
&i.CardConfigJson,
|
||||
&i.Status,
|
||||
&i.VersionNo,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
Reference in New Issue
Block a user