gitdataai/libs/migrate/sql/m20260508_000004_create_ai_shared_conversation.sql

17 lines
668 B
SQL

CREATE TABLE IF NOT EXISTS ai_shared_conversation (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
conversation_id UUID NOT NULL,
share_token VARCHAR(128) UNIQUE NOT NULL,
created_by UUID NOT NULL,
view_count INT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
expires_at TIMESTAMPTZ
);
CREATE INDEX IF NOT EXISTS idx_ai_share_conv ON ai_shared_conversation (conversation_id);
CREATE INDEX IF NOT EXISTS idx_ai_share_token ON ai_shared_conversation (share_token);
ALTER TABLE ai_shared_conversation
ADD CONSTRAINT fk_ai_share_conv
FOREIGN KEY (conversation_id) REFERENCES ai_conversation(id) ON DELETE CASCADE;