feat(store): add users and org memberships with single owner per org

Refs #1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-21 23:48:02 +01:00
1 parent c615c21af1
commit 95da376ac1
9 files changed
+356

No files matched your search

+61
View File
@@ -7,6 +7,8 @@ package store
import (
"context"
"github.com/google/uuid"
)
const createOrg = `-- name: CreateOrg :one
@@ -32,6 +34,35 @@ func (q *Queries) CreateOrg(ctx context.Context, arg CreateOrgParams) (Org, erro
return i, err
}
const deleteOrg = `-- name: DeleteOrg :execrows
DELETE FROM orgs WHERE id = $1
`
func (q *Queries) DeleteOrg(ctx context.Context, id uuid.UUID) (int64, error) {
result, err := q.db.Exec(ctx, deleteOrg, id)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getOrg = `-- name: GetOrg :one
SELECT id, slug, name, created_at, updated_at FROM orgs WHERE id = $1
`
func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
row := q.db.QueryRow(ctx, getOrg, id)
var i Org
err := row.Scan(
&i.ID,
&i.Slug,
&i.Name,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getOrgBySlug = `-- name: GetOrgBySlug :one
SELECT id, slug, name, created_at, updated_at FROM orgs WHERE slug = $1
`
@@ -48,3 +79,33 @@ func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
)
return i, err
}
const listOrgs = `-- name: ListOrgs :many
SELECT id, slug, name, created_at, updated_at FROM orgs ORDER BY name
`
func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
rows, err := q.db.Query(ctx, listOrgs)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Org{}
for rows.Next() {
var i Org
if err := rows.Scan(
&i.ID,
&i.Slug,
&i.Name,
&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
}