CREATE TABLE IF NOT EXISTS users (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    username TEXT NOT NULL,
    token TEXT NOT NULL,
    joined_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS user_connections (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    user_id BIGINT NOT NULL REFERENCES users(id),
    user_alias_id TEXT NOT NULL,
    user_alias_name TEXT NOT NULL,
    platform TEXT NOT NULL,
    connected_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP,
    UNIQUE (platform, user_id)
);

CREATE TABLE IF NOT EXISTS sounds (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    code TEXT NOT NULL,
    uploaded_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP,
    uploaded_by BIGINT REFERENCES users(id)
);

CREATE TABLE IF NOT EXISTS added_sounds (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    sound_id BIGINT NOT NULL REFERENCES sounds(id),
    emote_id TEXT NOT NULL,
    added_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP,
    UNIQUE (sound_id, emote_id)
);