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
170 lines
4.6 KiB
Go
170 lines
4.6 KiB
Go
//go:build postgres
|
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: attachments.sql
|
|
|
|
package pgdbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createAttachment = `-- name: CreateAttachment :exec
|
|
|
|
INSERT INTO attachments (id, uploader_id, filename, stored_as, mime_type, size, width, height)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
`
|
|
|
|
type CreateAttachmentParams struct {
|
|
ID string `json:"id"`
|
|
UploaderID *int64 `json:"uploaderId"`
|
|
Filename string `json:"filename"`
|
|
StoredAs string `json:"storedAs"`
|
|
MimeType string `json:"mimeType"`
|
|
Size int64 `json:"size"`
|
|
Width *int32 `json:"width"`
|
|
Height *int32 `json:"height"`
|
|
}
|
|
|
|
// PostgreSQL variants of the sqlite attachments queries.
|
|
func (q *Queries) CreateAttachment(ctx context.Context, arg CreateAttachmentParams) error {
|
|
_, err := q.db.Exec(ctx, createAttachment,
|
|
arg.ID,
|
|
arg.UploaderID,
|
|
arg.Filename,
|
|
arg.StoredAs,
|
|
arg.MimeType,
|
|
arg.Size,
|
|
arg.Width,
|
|
arg.Height,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const deleteAttachment = `-- name: DeleteAttachment :exec
|
|
DELETE FROM attachments WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteAttachment(ctx context.Context, id string) error {
|
|
_, err := q.db.Exec(ctx, deleteAttachment, id)
|
|
return err
|
|
}
|
|
|
|
const deleteOrphanedAttachments = `-- name: DeleteOrphanedAttachments :many
|
|
DELETE FROM attachments WHERE message_id IS NULL AND uploaded_at < $1 RETURNING stored_as
|
|
`
|
|
|
|
// Postgres timestamptz comparison — the caller passes a wall-clock time.
|
|
func (q *Queries) DeleteOrphanedAttachments(ctx context.Context, uploadedAt pgtype.Timestamptz) ([]string, error) {
|
|
rows, err := q.db.Query(ctx, deleteOrphanedAttachments, uploadedAt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []string{}
|
|
for rows.Next() {
|
|
var stored_as string
|
|
if err := rows.Scan(&stored_as); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, stored_as)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getAttachmentByID = `-- name: GetAttachmentByID :one
|
|
SELECT id, message_id, filename, stored_as, mime_type, size, uploaded_at, uploader_id
|
|
FROM attachments WHERE id = $1
|
|
`
|
|
|
|
type GetAttachmentByIDRow struct {
|
|
ID string `json:"id"`
|
|
MessageID *int64 `json:"messageId"`
|
|
Filename string `json:"filename"`
|
|
StoredAs string `json:"storedAs"`
|
|
MimeType string `json:"mimeType"`
|
|
Size int64 `json:"size"`
|
|
UploadedAt pgtype.Timestamptz `json:"uploadedAt"`
|
|
UploaderID *int64 `json:"uploaderId"`
|
|
}
|
|
|
|
func (q *Queries) GetAttachmentByID(ctx context.Context, id string) (GetAttachmentByIDRow, error) {
|
|
row := q.db.QueryRow(ctx, getAttachmentByID, id)
|
|
var i GetAttachmentByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.MessageID,
|
|
&i.Filename,
|
|
&i.StoredAs,
|
|
&i.MimeType,
|
|
&i.Size,
|
|
&i.UploadedAt,
|
|
&i.UploaderID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getAttachmentWithChannel = `-- name: GetAttachmentWithChannel :one
|
|
SELECT a.id, a.message_id, a.filename, a.stored_as, a.mime_type, a.size,
|
|
a.uploaded_at, a.uploader_id, m.channel_id, c.type
|
|
FROM attachments a
|
|
LEFT JOIN messages m ON m.id = a.message_id
|
|
LEFT JOIN channels c ON c.id = m.channel_id
|
|
WHERE a.id = $1
|
|
`
|
|
|
|
type GetAttachmentWithChannelRow struct {
|
|
ID string `json:"id"`
|
|
MessageID *int64 `json:"messageId"`
|
|
Filename string `json:"filename"`
|
|
StoredAs string `json:"storedAs"`
|
|
MimeType string `json:"mimeType"`
|
|
Size int64 `json:"size"`
|
|
UploadedAt pgtype.Timestamptz `json:"uploadedAt"`
|
|
UploaderID *int64 `json:"uploaderId"`
|
|
ChannelID *int64 `json:"channelId"`
|
|
Type *string `json:"type"`
|
|
}
|
|
|
|
func (q *Queries) GetAttachmentWithChannel(ctx context.Context, id string) (GetAttachmentWithChannelRow, error) {
|
|
row := q.db.QueryRow(ctx, getAttachmentWithChannel, id)
|
|
var i GetAttachmentWithChannelRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.MessageID,
|
|
&i.Filename,
|
|
&i.StoredAs,
|
|
&i.MimeType,
|
|
&i.Size,
|
|
&i.UploadedAt,
|
|
&i.UploaderID,
|
|
&i.ChannelID,
|
|
&i.Type,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const linkAttachmentToMessage = `-- name: LinkAttachmentToMessage :execrows
|
|
UPDATE attachments SET message_id = $1 WHERE id = $2 AND message_id IS NULL
|
|
`
|
|
|
|
type LinkAttachmentToMessageParams struct {
|
|
MessageID *int64 `json:"messageId"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) LinkAttachmentToMessage(ctx context.Context, arg LinkAttachmentToMessageParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, linkAttachmentToMessage, arg.MessageID, arg.ID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|