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
308 lines
7.3 KiB
Go
308 lines
7.3 KiB
Go
//go:build postgres
|
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: admin.sql
|
|
|
|
package pgdbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const countActiveInvites = `-- name: CountActiveInvites :one
|
|
SELECT COUNT(*) FROM invites WHERE revoked = FALSE
|
|
`
|
|
|
|
func (q *Queries) CountActiveInvites(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countActiveInvites)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countActiveMessages = `-- name: CountActiveMessages :one
|
|
SELECT COUNT(*) FROM messages WHERE deleted = FALSE
|
|
`
|
|
|
|
func (q *Queries) CountActiveMessages(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countActiveMessages)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countChannels = `-- name: CountChannels :one
|
|
SELECT COUNT(*) FROM channels
|
|
`
|
|
|
|
func (q *Queries) CountChannels(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countChannels)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const forceLogoutUser = `-- name: ForceLogoutUser :exec
|
|
DELETE FROM sessions WHERE user_id = $1
|
|
`
|
|
|
|
func (q *Queries) ForceLogoutUser(ctx context.Context, userID int64) error {
|
|
_, err := q.db.Exec(ctx, forceLogoutUser, userID)
|
|
return err
|
|
}
|
|
|
|
const getAllSettings = `-- name: GetAllSettings :many
|
|
SELECT key, value FROM settings
|
|
`
|
|
|
|
func (q *Queries) GetAllSettings(ctx context.Context) ([]Setting, error) {
|
|
rows, err := q.db.Query(ctx, getAllSettings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Setting{}
|
|
for rows.Next() {
|
|
var i Setting
|
|
if err := rows.Scan(&i.Key, &i.Value); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getAuditLog = `-- name: GetAuditLog :many
|
|
SELECT a.id, a.actor_id, COALESCE(u.username, '') AS actor_name, a.action,
|
|
a.target_type, a.target_id, a.detail, a.created_at
|
|
FROM audit_log a
|
|
LEFT JOIN users u ON u.id = a.actor_id
|
|
ORDER BY a.id DESC
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type GetAuditLogParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type GetAuditLogRow struct {
|
|
ID int64 `json:"id"`
|
|
ActorID int64 `json:"actorId"`
|
|
ActorName string `json:"actorName"`
|
|
Action string `json:"action"`
|
|
TargetType string `json:"targetType"`
|
|
TargetID int64 `json:"targetId"`
|
|
Detail string `json:"detail"`
|
|
CreatedAt pgtype.Timestamptz `json:"createdAt"`
|
|
}
|
|
|
|
func (q *Queries) GetAuditLog(ctx context.Context, arg GetAuditLogParams) ([]GetAuditLogRow, error) {
|
|
rows, err := q.db.Query(ctx, getAuditLog, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetAuditLogRow{}
|
|
for rows.Next() {
|
|
var i GetAuditLogRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ActorID,
|
|
&i.ActorName,
|
|
&i.Action,
|
|
&i.TargetType,
|
|
&i.TargetID,
|
|
&i.Detail,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getSetting = `-- name: GetSetting :one
|
|
SELECT value FROM settings WHERE key = $1
|
|
`
|
|
|
|
func (q *Queries) GetSetting(ctx context.Context, key string) (string, error) {
|
|
row := q.db.QueryRow(ctx, getSetting, key)
|
|
var value string
|
|
err := row.Scan(&value)
|
|
return value, err
|
|
}
|
|
|
|
const getUserSessions = `-- name: GetUserSessions :many
|
|
SELECT id, user_id, token, device, ip_address, created_at, last_used, expires_at
|
|
FROM sessions WHERE user_id = $1
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) GetUserSessions(ctx context.Context, userID int64) ([]Session, error) {
|
|
rows, err := q.db.Query(ctx, getUserSessions, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Session{}
|
|
for rows.Next() {
|
|
var i Session
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Token,
|
|
&i.Device,
|
|
&i.IpAddress,
|
|
&i.CreatedAt,
|
|
&i.LastUsed,
|
|
&i.ExpiresAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listAllUsers = `-- name: ListAllUsers :many
|
|
SELECT u.id, u.username, u.avatar, u.role_id,
|
|
u.status, u.created_at, u.last_seen, u.banned, u.ban_reason, u.ban_expires,
|
|
COALESCE(r.name, '') AS role_name
|
|
FROM users u
|
|
LEFT JOIN roles r ON r.id = u.role_id
|
|
ORDER BY u.id ASC
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type ListAllUsersParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ListAllUsersRow struct {
|
|
ID int64 `json:"id"`
|
|
Username string `json:"username"`
|
|
Avatar *string `json:"avatar"`
|
|
RoleID int64 `json:"roleId"`
|
|
Status string `json:"status"`
|
|
CreatedAt pgtype.Timestamptz `json:"createdAt"`
|
|
LastSeen pgtype.Timestamptz `json:"lastSeen"`
|
|
Banned bool `json:"banned"`
|
|
BanReason *string `json:"banReason"`
|
|
BanExpires pgtype.Timestamptz `json:"banExpires"`
|
|
RoleName string `json:"roleName"`
|
|
}
|
|
|
|
func (q *Queries) ListAllUsers(ctx context.Context, arg ListAllUsersParams) ([]ListAllUsersRow, error) {
|
|
rows, err := q.db.Query(ctx, listAllUsers, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListAllUsersRow{}
|
|
for rows.Next() {
|
|
var i ListAllUsersRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.RoleID,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.LastSeen,
|
|
&i.Banned,
|
|
&i.BanReason,
|
|
&i.BanExpires,
|
|
&i.RoleName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const logAudit = `-- name: LogAudit :exec
|
|
INSERT INTO audit_log (actor_id, action, target_type, target_id, detail)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
`
|
|
|
|
type LogAuditParams struct {
|
|
ActorID int64 `json:"actorId"`
|
|
Action string `json:"action"`
|
|
TargetType string `json:"targetType"`
|
|
TargetID int64 `json:"targetId"`
|
|
Detail string `json:"detail"`
|
|
}
|
|
|
|
func (q *Queries) LogAudit(ctx context.Context, arg LogAuditParams) error {
|
|
_, err := q.db.Exec(ctx, logAudit,
|
|
arg.ActorID,
|
|
arg.Action,
|
|
arg.TargetType,
|
|
arg.TargetID,
|
|
arg.Detail,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const setSetting = `-- name: SetSetting :exec
|
|
INSERT INTO settings (key, value) VALUES ($1, $2)
|
|
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value
|
|
`
|
|
|
|
type SetSettingParams struct {
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
func (q *Queries) SetSetting(ctx context.Context, arg SetSettingParams) error {
|
|
_, err := q.db.Exec(ctx, setSetting, arg.Key, arg.Value)
|
|
return err
|
|
}
|
|
|
|
const updateUserRole = `-- name: UpdateUserRole :exec
|
|
UPDATE users SET role_id = $1 WHERE id = $2
|
|
`
|
|
|
|
type UpdateUserRoleParams struct {
|
|
RoleID int64 `json:"roleId"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserRole(ctx context.Context, arg UpdateUserRoleParams) error {
|
|
_, err := q.db.Exec(ctx, updateUserRole, arg.RoleID, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const userCount = `-- name: UserCount :one
|
|
|
|
SELECT COUNT(*) FROM users
|
|
`
|
|
|
|
// PostgreSQL variants of the sqlite admin queries.
|
|
func (q *Queries) UserCount(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, userCount)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|