-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy path000012_create_topic_agenda_selections.sql
More file actions
47 lines (38 loc) · 2.14 KB
/
000012_create_topic_agenda_selections.sql
File metadata and controls
47 lines (38 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- Migration: Create topic_agenda_selections table for storing user topic selections
-- This table stores archetypal comment selections that persist across Delphi runs
CREATE TABLE IF NOT EXISTS topic_agenda_selections (
-- Primary key
zid INTEGER NOT NULL,
pid INTEGER NOT NULL,
-- Selection data stored as JSONB for flexibility
archetypal_selections JSONB NOT NULL DEFAULT '[]'::jsonb,
-- Dedicated columns for metadata
delphi_job_id TEXT,
total_selections INTEGER NOT NULL DEFAULT 0,
-- Timestamps
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
-- Composite primary key on conversation and participant
PRIMARY KEY (zid, pid),
-- Foreign key constraints
CONSTRAINT fk_conversation
FOREIGN KEY (zid)
REFERENCES conversations(zid)
ON DELETE CASCADE,
CONSTRAINT fk_participant
FOREIGN KEY (zid, pid)
REFERENCES participants(zid, pid)
ON DELETE CASCADE
);
-- Create indexes for better query performance
CREATE INDEX idx_topic_agenda_selections_zid ON topic_agenda_selections(zid);
CREATE INDEX idx_topic_agenda_selections_pid ON topic_agenda_selections(pid);
CREATE INDEX idx_topic_agenda_selections_delphi_job_id ON topic_agenda_selections(delphi_job_id);
CREATE INDEX idx_topic_agenda_selections_created_at ON topic_agenda_selections(created_at);
-- Add comments for documentation
COMMENT ON TABLE topic_agenda_selections IS 'Stores user topic agenda selections as archetypal comments that persist across Delphi runs';
COMMENT ON COLUMN topic_agenda_selections.zid IS 'Conversation ID (foreign key to conversations)';
COMMENT ON COLUMN topic_agenda_selections.pid IS 'Participant ID (foreign key to participants)';
COMMENT ON COLUMN topic_agenda_selections.archetypal_selections IS 'JSON array of selected topics with their archetypal comments';
COMMENT ON COLUMN topic_agenda_selections.delphi_job_id IS 'ID of the Delphi job that generated the topics';
COMMENT ON COLUMN topic_agenda_selections.total_selections IS 'Total number of topics selected by the user';