Initial commit
CI and release / Detect release commit (push) Successful in 2m42s
CI and release / Run tests (push) Successful in 7m18s
CI and release / Build and publish container (push) Failing after 5m12s
CI and release / Create release (push) Skipped

This commit is contained in:
Elias Wendland committed 2026-08-07 11:54:42 +02:00
commit 5a5f817df7
55 files changed
+3919

No files matched your search

+149
View File
@@ -0,0 +1,149 @@
CREATE TABLE IF NOT EXISTS guilds (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
guild_id BIGINT NOT NULL UNIQUE,
guild_name TEXT NOT NULL,
guild_icon_url TEXT
);
CREATE TABLE IF NOT EXISTS channels (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
guild_id BIGINT NOT NULL,
channel_id BIGINT NOT NULL UNIQUE,
channel_name TEXT NOT NULL,
FOREIGN KEY (guild_id)
REFERENCES guilds(guild_id)
);
CREATE TABLE IF NOT EXISTS discord_users (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
discord_id BIGINT NOT NULL UNIQUE,
discord_username TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS discord_roles (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
guild_id BIGINT NOT NULL,
discord_id BIGINT NOT NULL,
discord_role_name TEXT NOT NULL,
UNIQUE (guild_id, discord_id),
FOREIGN KEY (guild_id)
REFERENCES guilds(guild_id)
);
CREATE TABLE IF NOT EXISTS messages (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
guild_id BIGINT NOT NULL,
channel_id BIGINT NOT NULL,
message_id BIGINT NOT NULL UNIQUE,
author_id BIGINT NOT NULL,
author_username TEXT NOT NULL,
content TEXT,
timestamp TIMESTAMPTZ NOT NULL,
FOREIGN KEY (guild_id)
REFERENCES guilds(guild_id),
FOREIGN KEY (channel_id)
REFERENCES channels(channel_id),
FOREIGN KEY (author_id)
REFERENCES discord_users(discord_id)
);
CREATE TABLE IF NOT EXISTS attachments (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
attachment_id BIGINT NOT NULL UNIQUE,
message_id BIGINT NOT NULL,
filename TEXT NOT NULL,
description TEXT,
content_type TEXT,
size BIGINT NOT NULL,
width INTEGER,
height INTEGER,
data BYTEA NOT NULL,
FOREIGN KEY (message_id)
REFERENCES messages(message_id)
ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS embeds (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
message_id BIGINT NOT NULL,
embed_index INTEGER NOT NULL,
embed_type TEXT,
title TEXT,
description TEXT,
url TEXT,
timestamp TIMESTAMPTZ,
color INTEGER,
footer_text TEXT,
footer_icon_url TEXT,
image_url TEXT,
image_proxy_url TEXT,
image_width INTEGER,
image_height INTEGER,
thumbnail_url TEXT,
thumbnail_proxy_url TEXT,
thumbnail_width INTEGER,
thumbnail_height INTEGER,
video_url TEXT,
video_proxy_url TEXT,
video_width INTEGER,
video_height INTEGER,
provider_name TEXT,
provider_url TEXT,
author_name TEXT,
author_url TEXT,
author_icon_url TEXT,
author_proxy_icon_url TEXT,
UNIQUE (message_id, embed_index),
FOREIGN KEY (message_id)
REFERENCES messages(message_id)
ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS embed_fields (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
embed_uuid UUID NOT NULL,
field_index INTEGER NOT NULL,
name TEXT NOT NULL,
value TEXT NOT NULL,
inline BOOLEAN NOT NULL DEFAULT FALSE,
UNIQUE (embed_uuid, field_index),
FOREIGN KEY (embed_uuid)
REFERENCES embeds(uuid)
ON DELETE CASCADE
);
@@ -0,0 +1,41 @@
CREATE TABLE message_versions (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
message_id BIGINT NOT NULL,
version BIGINT NOT NULL,
content TEXT,
archived_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE (message_id, version),
FOREIGN KEY (message_id)
REFERENCES messages(message_id)
ON DELETE CASCADE
);
INSERT INTO message_versions (message_id, version, content)
SELECT message_id, 1, content
FROM messages;
ALTER TABLE attachments
ADD COLUMN message_version BIGINT NOT NULL DEFAULT 1;
ALTER TABLE attachments
DROP CONSTRAINT attachments_attachment_id_key;
ALTER TABLE attachments
ADD UNIQUE (message_id, message_version, attachment_id),
ADD FOREIGN KEY (message_id, message_version)
REFERENCES message_versions(message_id, version)
ON DELETE CASCADE;
ALTER TABLE embeds
ADD COLUMN message_version BIGINT NOT NULL DEFAULT 1;
ALTER TABLE embeds
DROP CONSTRAINT embeds_message_id_embed_index_key;
ALTER TABLE embeds
ADD UNIQUE (message_id, message_version, embed_index),
ADD FOREIGN KEY (message_id, message_version)
REFERENCES message_versions(message_id, version)
ON DELETE CASCADE;
@@ -0,0 +1,77 @@
CREATE TABLE guild_history (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
guild_id BIGINT NOT NULL,
guild_name TEXT NOT NULL,
guild_icon_url TEXT,
first_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
last_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE NULLS NOT DISTINCT (guild_id, guild_name, guild_icon_url),
FOREIGN KEY (guild_id)
REFERENCES guilds(guild_id)
ON DELETE CASCADE
);
CREATE TABLE channel_history (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
channel_id BIGINT NOT NULL,
channel_name TEXT NOT NULL,
first_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
last_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE (channel_id, channel_name),
FOREIGN KEY (channel_id)
REFERENCES channels(channel_id)
ON DELETE CASCADE
);
CREATE TABLE discord_user_history (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
discord_id BIGINT NOT NULL,
discord_username TEXT NOT NULL,
discord_avatar_url TEXT,
first_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
last_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE NULLS NOT DISTINCT (discord_id, discord_username, discord_avatar_url),
FOREIGN KEY (discord_id)
REFERENCES discord_users(discord_id)
ON DELETE CASCADE
);
CREATE TABLE guild_users (
guild_id BIGINT NOT NULL,
discord_id BIGINT NOT NULL,
first_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
last_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (guild_id, discord_id),
FOREIGN KEY (guild_id)
REFERENCES guilds(guild_id)
ON DELETE CASCADE,
FOREIGN KEY (discord_id)
REFERENCES discord_users(discord_id)
ON DELETE CASCADE
);
INSERT INTO guild_history (guild_id, guild_name, guild_icon_url)
SELECT guild_id, guild_name, guild_icon_url
FROM guilds;
INSERT INTO channel_history (channel_id, channel_name)
SELECT channel_id, channel_name
FROM channels;
INSERT INTO discord_user_history (discord_id, discord_username, discord_avatar_url)
SELECT discord_id, discord_username, NULL
FROM discord_users;
INSERT INTO guild_users (guild_id, discord_id)
SELECT guild_id, author_id
FROM messages
GROUP BY guild_id, author_id;