20230907114200_add_channel_messages.sql

 1CREATE TABLE IF NOT EXISTS "channel_messages" (
 2    "id" SERIAL PRIMARY KEY,
 3    "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
 4    "sender_id" INTEGER NOT NULL REFERENCES users (id),
 5    "body" TEXT NOT NULL,
 6    "sent_at" TIMESTAMP,
 7    "nonce" UUID NOT NULL
 8);
 9CREATE INDEX "index_channel_messages_on_channel_id" ON "channel_messages" ("channel_id");
10CREATE UNIQUE INDEX "index_channel_messages_on_nonce" ON "channel_messages" ("nonce");
11
12CREATE TABLE IF NOT EXISTS "channel_chat_participants" (
13    "id" SERIAL PRIMARY KEY,
14    "user_id" INTEGER NOT NULL REFERENCES users (id),
15    "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
16    "connection_id" INTEGER NOT NULL,
17    "connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE
18);
19CREATE INDEX "index_channel_chat_participants_on_channel_id" ON "channel_chat_participants" ("channel_id");