Refactor: Implement database queue infrastructure

This commit is contained in:
gpt-engineer-app[bot]
2025-10-06 14:34:11 +00:00
parent a340985f32
commit 93a99432ec
2 changed files with 51 additions and 0 deletions

View File

@@ -208,55 +208,79 @@ export type Database = {
content_submissions: { content_submissions: {
Row: { Row: {
approval_mode: string | null approval_mode: string | null
assigned_at: string | null
assigned_to: string | null
content: Json content: Json
created_at: string created_at: string
escalated: boolean | null escalated: boolean | null
escalated_at: string | null escalated_at: string | null
escalated_by: string | null escalated_by: string | null
escalation_reason: string | null escalation_reason: string | null
first_reviewed_at: string | null
id: string id: string
locked_until: string | null
original_submission_id: string | null original_submission_id: string | null
priority: number
resolved_at: string | null
review_count: number | null
reviewed_at: string | null reviewed_at: string | null
reviewer_id: string | null reviewer_id: string | null
reviewer_notes: string | null reviewer_notes: string | null
status: string status: string
submission_type: string submission_type: string
submitted_at: string
updated_at: string updated_at: string
user_id: string user_id: string
} }
Insert: { Insert: {
approval_mode?: string | null approval_mode?: string | null
assigned_at?: string | null
assigned_to?: string | null
content: Json content: Json
created_at?: string created_at?: string
escalated?: boolean | null escalated?: boolean | null
escalated_at?: string | null escalated_at?: string | null
escalated_by?: string | null escalated_by?: string | null
escalation_reason?: string | null escalation_reason?: string | null
first_reviewed_at?: string | null
id?: string id?: string
locked_until?: string | null
original_submission_id?: string | null original_submission_id?: string | null
priority?: number
resolved_at?: string | null
review_count?: number | null
reviewed_at?: string | null reviewed_at?: string | null
reviewer_id?: string | null reviewer_id?: string | null
reviewer_notes?: string | null reviewer_notes?: string | null
status?: string status?: string
submission_type: string submission_type: string
submitted_at?: string
updated_at?: string updated_at?: string
user_id: string user_id: string
} }
Update: { Update: {
approval_mode?: string | null approval_mode?: string | null
assigned_at?: string | null
assigned_to?: string | null
content?: Json content?: Json
created_at?: string created_at?: string
escalated?: boolean | null escalated?: boolean | null
escalated_at?: string | null escalated_at?: string | null
escalated_by?: string | null escalated_by?: string | null
escalation_reason?: string | null escalation_reason?: string | null
first_reviewed_at?: string | null
id?: string id?: string
locked_until?: string | null
original_submission_id?: string | null original_submission_id?: string | null
priority?: number
resolved_at?: string | null
review_count?: number | null
reviewed_at?: string | null reviewed_at?: string | null
reviewer_id?: string | null reviewer_id?: string | null
reviewer_notes?: string | null reviewer_notes?: string | null
status?: string status?: string
submission_type?: string submission_type?: string
submitted_at?: string
updated_at?: string updated_at?: string
user_id?: string user_id?: string
} }

View File

@@ -0,0 +1,27 @@
-- Create moderation queue in pgmq
SELECT pgmq.create('moderation_queue');
-- Add queue management columns to content_submissions
ALTER TABLE content_submissions
ADD COLUMN IF NOT EXISTS priority INTEGER NOT NULL DEFAULT 3,
ADD COLUMN IF NOT EXISTS assigned_to UUID REFERENCES auth.users(id),
ADD COLUMN IF NOT EXISTS assigned_at TIMESTAMP WITH TIME ZONE,
ADD COLUMN IF NOT EXISTS locked_until TIMESTAMP WITH TIME ZONE,
ADD COLUMN IF NOT EXISTS submitted_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
ADD COLUMN IF NOT EXISTS first_reviewed_at TIMESTAMP WITH TIME ZONE,
ADD COLUMN IF NOT EXISTS resolved_at TIMESTAMP WITH TIME ZONE,
ADD COLUMN IF NOT EXISTS review_count INTEGER DEFAULT 0;
-- Create indexes for queue operations
CREATE INDEX IF NOT EXISTS idx_submissions_queue_status
ON content_submissions(status, priority DESC, submitted_at ASC)
WHERE status IN ('pending', 'partially_approved');
CREATE INDEX IF NOT EXISTS idx_submissions_assigned
ON content_submissions(assigned_to, locked_until)
WHERE assigned_to IS NOT NULL;
-- Simple index on locked_until for expired lock cleanup
CREATE INDEX IF NOT EXISTS idx_submissions_locked_until
ON content_submissions(locked_until)
WHERE locked_until IS NOT NULL;