mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
- migrations/postgres/: consolidated pg schema with tsvector FTS, CITEXT usernames, native CHECK constraints, native BOOLEAN/TIMESTAMPTZ types - db/queries/postgres/: 14 sqlc query files dialect-translated from sqlite ($N placeholders, NOW(), TRUE/FALSE, ON CONFLICT DO UPDATE, RETURNING id, :execrows for mutations needing row count) - sqlc.yaml: second engine entry -> pgdbgen package under pgx/v5 - Makefile: sqlc-verify covers both dbgen + pgdbgen - store/postgres.go: PostgresStore behind //go:build postgres, full Store interface (112 methods). Connection lifecycle real; query methods stub ErrPostgresNotImplemented awaiting pgdbgen wrappers - config: DatabaseConfig.Type/Host/Port/User/Password/Name/SSLMode/MaxConns - main.go: explicit dispatch on database.type; postgres errors with clear pointer at remaining work until pgdbgen + boundary refactor land - phase-a-foundation.md: implementation status + actionable TODO checklist including forward-only sqlite->postgres data migration design
30 lines
981 B
SQL
30 lines
981 B
SQL
-- PostgreSQL variants of the sqlite roles queries.
|
|
-- `is_default = 1` becomes `is_default = TRUE` since the column is BOOLEAN.
|
|
|
|
-- name: GetRoleByID :one
|
|
SELECT id, name, color, permissions, position, is_default
|
|
FROM roles WHERE id = $1;
|
|
|
|
-- name: ListRoles :many
|
|
SELECT id, name, color, permissions, position, is_default
|
|
FROM roles ORDER BY position DESC;
|
|
|
|
-- name: GetRoleForUser :one
|
|
SELECT r.id, r.name, r.color, r.permissions, r.position, r.is_default
|
|
FROM users u
|
|
JOIN roles r ON u.role_id = r.id
|
|
WHERE u.id = $1;
|
|
|
|
-- name: GetUserWithRole :one
|
|
SELECT u.id, u.username, u.password, u.avatar, u.role_id,
|
|
u.totp_secret, u.status, u.created_at, u.last_seen,
|
|
u.banned, u.ban_reason, u.ban_expires,
|
|
r.id, r.name, r.color, r.permissions, r.position, r.is_default
|
|
FROM users u
|
|
JOIN roles r ON r.id = u.role_id
|
|
WHERE u.id = $1;
|
|
|
|
-- name: GetDefaultRole :one
|
|
SELECT id, name, color, permissions, position, is_default
|
|
FROM roles WHERE is_default = TRUE LIMIT 1;
|