mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
- Generate Server/db/dbgen/{events,plugins}.sql.go and full Server/db/pgdbgen/ (//go:build postgres gated)
- Implement PostgresStore EventStore and PluginStore methods in store/postgres.go
- Wire plugin host_events.go EventSink into hub broadcast path (SetPluginEventSink)
- Wire host_commands.go slash-command dispatcher: chat_command V1 handler + hub.SetPluginRegistry
- Add handlers_command.go + handlers_command_test.go for plugin slash-command dispatch
- Add reconnect_db_test.go: TestReconnect_BufferMiss_FallsBackToDBTier (cold-tier DB replay)
- Add otel-up/otel-down Makefile targets; docker-compose.otel.yml + prometheus.dev.yml
- Update PHASE_BC_LOCAL_TODO.md: mark in-session items complete; document remaining network-blocked steps
- Minor fixes: channel_handler access-control, router plugin handler wiring, service span instrumentation
220 lines
5.4 KiB
Go
220 lines
5.4 KiB
Go
//go:build postgres
|
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: users.sql
|
|
|
|
package pgdbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const banUser = `-- name: BanUser :exec
|
|
UPDATE users SET banned = TRUE, ban_reason = $1, ban_expires = $2 WHERE id = $3
|
|
`
|
|
|
|
type BanUserParams struct {
|
|
BanReason *string `json:"banReason"`
|
|
BanExpires pgtype.Timestamptz `json:"banExpires"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) BanUser(ctx context.Context, arg BanUserParams) error {
|
|
_, err := q.db.Exec(ctx, banUser, arg.BanReason, arg.BanExpires, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const countUsers = `-- name: CountUsers :one
|
|
SELECT COUNT(*) FROM users
|
|
`
|
|
|
|
func (q *Queries) CountUsers(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countUsers)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countUsersWithoutTOTP = `-- name: CountUsersWithoutTOTP :one
|
|
SELECT COUNT(*) FROM users WHERE banned = FALSE AND totp_secret IS NULL
|
|
`
|
|
|
|
func (q *Queries) CountUsersWithoutTOTP(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countUsersWithoutTOTP)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users (username, password, role_id)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING id
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
RoleID int64 `json:"roleId"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, createUser, arg.Username, arg.Password, arg.RoleID)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const getUserByID = `-- name: GetUserByID :one
|
|
SELECT id, username, password, avatar, role_id, totp_secret, status,
|
|
created_at, last_seen, banned, ban_reason, ban_expires
|
|
FROM users WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetUserByID(ctx context.Context, id int64) (User, error) {
|
|
row := q.db.QueryRow(ctx, getUserByID, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Password,
|
|
&i.Avatar,
|
|
&i.RoleID,
|
|
&i.TotpSecret,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.LastSeen,
|
|
&i.Banned,
|
|
&i.BanReason,
|
|
&i.BanExpires,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByUsername = `-- name: GetUserByUsername :one
|
|
|
|
SELECT id, username, password, avatar, role_id, totp_secret, status,
|
|
created_at, last_seen, banned, ban_reason, ban_expires
|
|
FROM users WHERE username = $1
|
|
`
|
|
|
|
// PostgreSQL variants of the sqlite users queries.
|
|
// Differences from sqlite:
|
|
// - `?` -> `$1`, `$2`, …
|
|
// - `COLLATE NOCASE` -> removed; the `username` column is CITEXT.
|
|
// - `datetime('now')` -> `NOW()`
|
|
// - `banned = 0/1` -> `banned = FALSE/TRUE` (column is BOOLEAN)
|
|
// - `:execresult INSERT` -> `:one ... RETURNING id` (pgx has no LastInsertId)
|
|
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) {
|
|
row := q.db.QueryRow(ctx, getUserByUsername, username)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Password,
|
|
&i.Avatar,
|
|
&i.RoleID,
|
|
&i.TotpSecret,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.LastSeen,
|
|
&i.Banned,
|
|
&i.BanReason,
|
|
&i.BanExpires,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listMembers = `-- name: ListMembers :many
|
|
SELECT u.id, u.username, u.avatar, u.status, LOWER(r.name)
|
|
FROM users u
|
|
JOIN roles r ON u.role_id = r.id
|
|
WHERE u.banned = FALSE
|
|
ORDER BY u.username ASC
|
|
LIMIT 1000
|
|
`
|
|
|
|
type ListMembersRow struct {
|
|
ID int64 `json:"id"`
|
|
Username string `json:"username"`
|
|
Avatar *string `json:"avatar"`
|
|
Status string `json:"status"`
|
|
Lower string `json:"lower"`
|
|
}
|
|
|
|
func (q *Queries) ListMembers(ctx context.Context) ([]ListMembersRow, error) {
|
|
rows, err := q.db.Query(ctx, listMembers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListMembersRow{}
|
|
for rows.Next() {
|
|
var i ListMembersRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Status,
|
|
&i.Lower,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const resetAllUserStatuses = `-- name: ResetAllUserStatuses :exec
|
|
UPDATE users SET status = 'offline' WHERE status != 'offline'
|
|
`
|
|
|
|
func (q *Queries) ResetAllUserStatuses(ctx context.Context) error {
|
|
_, err := q.db.Exec(ctx, resetAllUserStatuses)
|
|
return err
|
|
}
|
|
|
|
const unbanUser = `-- name: UnbanUser :exec
|
|
UPDATE users SET banned = FALSE, ban_reason = NULL, ban_expires = NULL WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) UnbanUser(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, unbanUser, id)
|
|
return err
|
|
}
|
|
|
|
const updateUserStatus = `-- name: UpdateUserStatus :exec
|
|
UPDATE users SET status = $1, last_seen = NOW() WHERE id = $2
|
|
`
|
|
|
|
type UpdateUserStatusParams struct {
|
|
Status string `json:"status"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserStatus(ctx context.Context, arg UpdateUserStatusParams) error {
|
|
_, err := q.db.Exec(ctx, updateUserStatus, arg.Status, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const updateUserTOTPSecret = `-- name: UpdateUserTOTPSecret :exec
|
|
UPDATE users SET totp_secret = $1 WHERE id = $2
|
|
`
|
|
|
|
type UpdateUserTOTPSecretParams struct {
|
|
TotpSecret *string `json:"totpSecret"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserTOTPSecret(ctx context.Context, arg UpdateUserTOTPSecretParams) error {
|
|
_, err := q.db.Exec(ctx, updateUserTOTPSecret, arg.TotpSecret, arg.ID)
|
|
return err
|
|
}
|