You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ai_synth/backend/migrations/20260321000005_create_sourc...

15 lines
659 B
SQL

-- Create the sources table.
-- Each user can save custom news sources (URLs) for their syntheses.
-- A unique constraint on (user_id, url) prevents duplicate URLs per user.
CREATE TABLE sources (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
title VARCHAR(200) NOT NULL CHECK (char_length(title) BETWEEN 1 AND 200),
url VARCHAR(1000) NOT NULL CHECK (char_length(url) <= 1000),
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_sources_user_id ON sources(user_id);
CREATE UNIQUE INDEX idx_sources_user_id_url ON sources(user_id, url);