diff --git a/migrations/2024-11-25-232658_init/up.sql b/migrations/2024-11-25-232658_init/up.sql index 2706c40..feb78ae 100644 --- a/migrations/2024-11-25-232658_init/up.sql +++ b/migrations/2024-11-25-232658_init/up.sql @@ -7,7 +7,7 @@ CREATE INDEX ON users (uid); CREATE TABLE IF NOT EXISTS csrf_tokens ( id UUID NOT NULL PRIMARY KEY, - user_id UUID REFERENCES users(id), + user_id UUID REFERENCES users(id) ON DELETE CASCADE, created_at TIMESTAMPTZ NOT NULL ); CREATE INDEX ON csrf_tokens (created_at); @@ -18,9 +18,9 @@ CREATE TABLE teams ( ); CREATE TABLE team_memberships ( - team_id UUID NOT NULL REFERENCES teams(id), - user_id UUID NOT NULL REFERENCES users(id), roles TEXT[] NOT NULL DEFAULT '{}', + team_id UUID NOT NULL REFERENCES teams(id) ON DELETE CASCADE, + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, PRIMARY KEY (team_id, user_id) ); CREATE INDEX ON team_memberships (team_id); @@ -28,7 +28,7 @@ CREATE INDEX ON team_memberships (user_id); CREATE TABLE api_keys ( id UUID NOT NULL PRIMARY KEY, - team_id UUID NOT NULL REFERENCES teams(id), + team_id UUID NOT NULL REFERENCES teams(id) ON DELETE CASCADE, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), last_used_at TIMESTAMPTZ ); @@ -44,15 +44,15 @@ CREATE INDEX ON projects(team_id); CREATE TABLE IF NOT EXISTS channels ( id UUID NOT NULL PRIMARY KEY, - team_id UUID NOT NULL REFERENCES teams(id), + team_id UUID NOT NULL REFERENCES teams(id) ON DELETE CASCADE, name TEXT NOT NULL, enable_by_default BOOLEAN NOT NULL DEFAULT FALSE, backend_config JSONB NOT NULL DEFAULT '{}'::JSONB ); CREATE TABLE IF NOT EXISTS channel_selections ( - project_id UUID NOT NULL REFERENCES projects(id), - channel_id UUID NOT NULL REFERENCES channels(id), + project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE, + channel_id UUID NOT NULL REFERENCES channels(id) ON DELETE CASCADE, PRIMARY KEY (project_id, channel_id) ); CREATE INDEX ON channel_selections (project_id); diff --git a/migrations/2025-01-31-045014_messages/up.sql b/migrations/2025-01-31-045014_messages/up.sql index 95c628a..f03c60f 100644 --- a/migrations/2025-01-31-045014_messages/up.sql +++ b/migrations/2025-01-31-045014_messages/up.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS messages ( id UUID PRIMARY KEY NOT NULL, - channel_id UUID NOT NULL REFERENCES channels (id), + channel_id UUID NOT NULL REFERENCES channels (id) ON DELETE RESTRICT, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), sent_at TIMESTAMPTZ, message TEXT NOT NULL