28 lines
979 B
SQL
28 lines
979 B
SQL
CREATE TABLE IF NOT EXISTS lists (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
name VARCHAR(255) NOT NULL,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS list_users (
|
|
list_id UUID REFERENCES lists(id) ON DELETE CASCADE,
|
|
user_id UUID NOT NULL,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
PRIMARY KEY (list_id, user_id)
|
|
);
|
|
|
|
CREATE UNIQUE INDEX idx_list_users_list_id_user_id ON list_users(list_id, user_id);
|
|
CREATE INDEX idx_list_users_user_id ON list_users(user_id);
|
|
|
|
CREATE TABLE IF NOT EXISTS list_items (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
list_id UUID REFERENCES lists(id) ON DELETE CASCADE,
|
|
title VARCHAR(255) NOT NULL,
|
|
is_completed BOOLEAN NOT NULL DEFAULT FALSE,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE INDEX idx_list_items_list_id ON list_items(list_id);
|