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
382 lines
10 KiB
Go
382 lines
10 KiB
Go
//go:build postgres
|
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: channels.sql
|
|
|
|
package pgdbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const adminUpdateChannel = `-- name: AdminUpdateChannel :exec
|
|
UPDATE channels
|
|
SET name = $1, topic = $2, slow_mode = $3, position = $4, archived = $5
|
|
WHERE id = $6
|
|
`
|
|
|
|
type AdminUpdateChannelParams struct {
|
|
Name string `json:"name"`
|
|
Topic *string `json:"topic"`
|
|
SlowMode int32 `json:"slowMode"`
|
|
Position int32 `json:"position"`
|
|
Archived bool `json:"archived"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) AdminUpdateChannel(ctx context.Context, arg AdminUpdateChannelParams) error {
|
|
_, err := q.db.Exec(ctx, adminUpdateChannel,
|
|
arg.Name,
|
|
arg.Topic,
|
|
arg.SlowMode,
|
|
arg.Position,
|
|
arg.Archived,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const archiveChannel = `-- name: ArchiveChannel :exec
|
|
UPDATE channels SET archived = $1 WHERE id = $2
|
|
`
|
|
|
|
type ArchiveChannelParams struct {
|
|
Archived bool `json:"archived"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) ArchiveChannel(ctx context.Context, arg ArchiveChannelParams) error {
|
|
_, err := q.db.Exec(ctx, archiveChannel, arg.Archived, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const createChannel = `-- name: CreateChannel :one
|
|
INSERT INTO channels (name, type, category, topic, position)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING id
|
|
`
|
|
|
|
type CreateChannelParams struct {
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Category *string `json:"category"`
|
|
Topic *string `json:"topic"`
|
|
Position int32 `json:"position"`
|
|
}
|
|
|
|
func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, createChannel,
|
|
arg.Name,
|
|
arg.Type,
|
|
arg.Category,
|
|
arg.Topic,
|
|
arg.Position,
|
|
)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const deleteChannel = `-- name: DeleteChannel :exec
|
|
DELETE FROM channels WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteChannel(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, deleteChannel, id)
|
|
return err
|
|
}
|
|
|
|
const deleteChannelPermission = `-- name: DeleteChannelPermission :exec
|
|
DELETE FROM channel_overrides WHERE channel_id = $1 AND role_id = $2
|
|
`
|
|
|
|
type DeleteChannelPermissionParams struct {
|
|
ChannelID int64 `json:"channelId"`
|
|
RoleID int64 `json:"roleId"`
|
|
}
|
|
|
|
func (q *Queries) DeleteChannelPermission(ctx context.Context, arg DeleteChannelPermissionParams) error {
|
|
_, err := q.db.Exec(ctx, deleteChannelPermission, arg.ChannelID, arg.RoleID)
|
|
return err
|
|
}
|
|
|
|
const getChannel = `-- name: GetChannel :one
|
|
SELECT id, name, type, COALESCE(category, '') AS category, COALESCE(topic, '') AS topic,
|
|
position, slow_mode, archived, created_at,
|
|
COALESCE(voice_max_users, 0) AS voice_max_users,
|
|
voice_quality,
|
|
mixing_threshold,
|
|
COALESCE(voice_max_video, 0) AS voice_max_video
|
|
FROM channels WHERE id = $1
|
|
`
|
|
|
|
type GetChannelRow struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Category string `json:"category"`
|
|
Topic string `json:"topic"`
|
|
Position int32 `json:"position"`
|
|
SlowMode int32 `json:"slowMode"`
|
|
Archived bool `json:"archived"`
|
|
CreatedAt pgtype.Timestamptz `json:"createdAt"`
|
|
VoiceMaxUsers int32 `json:"voiceMaxUsers"`
|
|
VoiceQuality *string `json:"voiceQuality"`
|
|
MixingThreshold *int32 `json:"mixingThreshold"`
|
|
VoiceMaxVideo int32 `json:"voiceMaxVideo"`
|
|
}
|
|
|
|
func (q *Queries) GetChannel(ctx context.Context, id int64) (GetChannelRow, error) {
|
|
row := q.db.QueryRow(ctx, getChannel, id)
|
|
var i GetChannelRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Type,
|
|
&i.Category,
|
|
&i.Topic,
|
|
&i.Position,
|
|
&i.SlowMode,
|
|
&i.Archived,
|
|
&i.CreatedAt,
|
|
&i.VoiceMaxUsers,
|
|
&i.VoiceQuality,
|
|
&i.MixingThreshold,
|
|
&i.VoiceMaxVideo,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getChannelPermission = `-- name: GetChannelPermission :one
|
|
SELECT allow, deny FROM channel_overrides WHERE channel_id = $1 AND role_id = $2
|
|
`
|
|
|
|
type GetChannelPermissionParams struct {
|
|
ChannelID int64 `json:"channelId"`
|
|
RoleID int64 `json:"roleId"`
|
|
}
|
|
|
|
type GetChannelPermissionRow struct {
|
|
Allow int64 `json:"allow"`
|
|
Deny int64 `json:"deny"`
|
|
}
|
|
|
|
func (q *Queries) GetChannelPermission(ctx context.Context, arg GetChannelPermissionParams) (GetChannelPermissionRow, error) {
|
|
row := q.db.QueryRow(ctx, getChannelPermission, arg.ChannelID, arg.RoleID)
|
|
var i GetChannelPermissionRow
|
|
err := row.Scan(&i.Allow, &i.Deny)
|
|
return i, err
|
|
}
|
|
|
|
const getRoleChannelPermissions = `-- name: GetRoleChannelPermissions :many
|
|
SELECT channel_id, allow, deny FROM channel_overrides WHERE role_id = $1
|
|
`
|
|
|
|
type GetRoleChannelPermissionsRow struct {
|
|
ChannelID int64 `json:"channelId"`
|
|
Allow int64 `json:"allow"`
|
|
Deny int64 `json:"deny"`
|
|
}
|
|
|
|
func (q *Queries) GetRoleChannelPermissions(ctx context.Context, roleID int64) ([]GetRoleChannelPermissionsRow, error) {
|
|
rows, err := q.db.Query(ctx, getRoleChannelPermissions, roleID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetRoleChannelPermissionsRow{}
|
|
for rows.Next() {
|
|
var i GetRoleChannelPermissionsRow
|
|
if err := rows.Scan(&i.ChannelID, &i.Allow, &i.Deny); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listChannels = `-- name: ListChannels :many
|
|
|
|
SELECT id, name, type, COALESCE(category, '') AS category, COALESCE(topic, '') AS topic,
|
|
position, slow_mode, archived, created_at,
|
|
COALESCE(voice_max_users, 0) AS voice_max_users,
|
|
voice_quality,
|
|
mixing_threshold,
|
|
COALESCE(voice_max_video, 0) AS voice_max_video
|
|
FROM channels ORDER BY position ASC, id ASC
|
|
`
|
|
|
|
type ListChannelsRow struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Category string `json:"category"`
|
|
Topic string `json:"topic"`
|
|
Position int32 `json:"position"`
|
|
SlowMode int32 `json:"slowMode"`
|
|
Archived bool `json:"archived"`
|
|
CreatedAt pgtype.Timestamptz `json:"createdAt"`
|
|
VoiceMaxUsers int32 `json:"voiceMaxUsers"`
|
|
VoiceQuality *string `json:"voiceQuality"`
|
|
MixingThreshold *int32 `json:"mixingThreshold"`
|
|
VoiceMaxVideo int32 `json:"voiceMaxVideo"`
|
|
}
|
|
|
|
// PostgreSQL variants of the sqlite channels queries.
|
|
func (q *Queries) ListChannels(ctx context.Context) ([]ListChannelsRow, error) {
|
|
rows, err := q.db.Query(ctx, listChannels)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListChannelsRow{}
|
|
for rows.Next() {
|
|
var i ListChannelsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Type,
|
|
&i.Category,
|
|
&i.Topic,
|
|
&i.Position,
|
|
&i.SlowMode,
|
|
&i.Archived,
|
|
&i.CreatedAt,
|
|
&i.VoiceMaxUsers,
|
|
&i.VoiceQuality,
|
|
&i.MixingThreshold,
|
|
&i.VoiceMaxVideo,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const setChannelMixingThreshold = `-- name: SetChannelMixingThreshold :exec
|
|
UPDATE channels SET mixing_threshold = $1 WHERE id = $2
|
|
`
|
|
|
|
type SetChannelMixingThresholdParams struct {
|
|
MixingThreshold *int32 `json:"mixingThreshold"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SetChannelMixingThreshold(ctx context.Context, arg SetChannelMixingThresholdParams) error {
|
|
_, err := q.db.Exec(ctx, setChannelMixingThreshold, arg.MixingThreshold, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const setChannelSlowMode = `-- name: SetChannelSlowMode :exec
|
|
UPDATE channels SET slow_mode = $1 WHERE id = $2
|
|
`
|
|
|
|
type SetChannelSlowModeParams struct {
|
|
SlowMode int32 `json:"slowMode"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SetChannelSlowMode(ctx context.Context, arg SetChannelSlowModeParams) error {
|
|
_, err := q.db.Exec(ctx, setChannelSlowMode, arg.SlowMode, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const setChannelVoiceMaxUsers = `-- name: SetChannelVoiceMaxUsers :exec
|
|
UPDATE channels SET voice_max_users = $1 WHERE id = $2
|
|
`
|
|
|
|
type SetChannelVoiceMaxUsersParams struct {
|
|
VoiceMaxUsers int32 `json:"voiceMaxUsers"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SetChannelVoiceMaxUsers(ctx context.Context, arg SetChannelVoiceMaxUsersParams) error {
|
|
_, err := q.db.Exec(ctx, setChannelVoiceMaxUsers, arg.VoiceMaxUsers, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const setChannelVoiceMaxVideo = `-- name: SetChannelVoiceMaxVideo :exec
|
|
UPDATE channels SET voice_max_video = $1 WHERE id = $2
|
|
`
|
|
|
|
type SetChannelVoiceMaxVideoParams struct {
|
|
VoiceMaxVideo int32 `json:"voiceMaxVideo"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SetChannelVoiceMaxVideo(ctx context.Context, arg SetChannelVoiceMaxVideoParams) error {
|
|
_, err := q.db.Exec(ctx, setChannelVoiceMaxVideo, arg.VoiceMaxVideo, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const setChannelVoiceQuality = `-- name: SetChannelVoiceQuality :exec
|
|
UPDATE channels SET voice_quality = $1 WHERE id = $2
|
|
`
|
|
|
|
type SetChannelVoiceQualityParams struct {
|
|
VoiceQuality *string `json:"voiceQuality"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SetChannelVoiceQuality(ctx context.Context, arg SetChannelVoiceQualityParams) error {
|
|
_, err := q.db.Exec(ctx, setChannelVoiceQuality, arg.VoiceQuality, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const updateChannel = `-- name: UpdateChannel :exec
|
|
UPDATE channels SET name = $1, topic = $2, slow_mode = $3 WHERE id = $4
|
|
`
|
|
|
|
type UpdateChannelParams struct {
|
|
Name string `json:"name"`
|
|
Topic *string `json:"topic"`
|
|
SlowMode int32 `json:"slowMode"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateChannel(ctx context.Context, arg UpdateChannelParams) error {
|
|
_, err := q.db.Exec(ctx, updateChannel,
|
|
arg.Name,
|
|
arg.Topic,
|
|
arg.SlowMode,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const upsertChannelPermission = `-- name: UpsertChannelPermission :exec
|
|
INSERT INTO channel_overrides (channel_id, role_id, allow, deny)
|
|
VALUES ($1, $2, $3, $4)
|
|
ON CONFLICT (channel_id, role_id) DO UPDATE SET
|
|
allow = EXCLUDED.allow,
|
|
deny = EXCLUDED.deny
|
|
`
|
|
|
|
type UpsertChannelPermissionParams struct {
|
|
ChannelID int64 `json:"channelId"`
|
|
RoleID int64 `json:"roleId"`
|
|
Allow int64 `json:"allow"`
|
|
Deny int64 `json:"deny"`
|
|
}
|
|
|
|
func (q *Queries) UpsertChannelPermission(ctx context.Context, arg UpsertChannelPermissionParams) error {
|
|
_, err := q.db.Exec(ctx, upsertChannelPermission,
|
|
arg.ChannelID,
|
|
arg.RoleID,
|
|
arg.Allow,
|
|
arg.Deny,
|
|
)
|
|
return err
|
|
}
|