-- noinspection SqlNoDataSourceInspectionForFile

CREATE TABLE `invites` (
    `token` TEXT NOT NULL,
    `creator` TEXT NOT NULL,
    `server` TEXT NOT NULL,
    `uses` INT NOT NULL,
    `unlimited` INTEGER NOT NULL,
    PRIMARY KEY (`token`),
    FOREIGN KEY (`server`) REFERENCES servers(`id`),
    FOREIGN KEY (`creator`) REFERENCES users(`id`)
) STRICT;

CREATE TABLE `servers` (
    `id` TEXT NOT NULL,
    `name` TEXT NOT NULL,
    `address` TEXT NOT NULL,
    `rcon_address` TEXT NOT NULL,
    `rcon_password` TEXT NOT NULL,
    `owner` TEXT NOT NULL,
    PRIMARY KEY (`id`)
) STRICT;

CREATE TABLE `users` (
    `id` TEXT NOT NULL,
    `token` TEXT NOT NULL,
    `display_name` TEXT NOT NULL,
    `refresh_token` TEXT NOT NULL,
    `token_expiry` TEXT NOT NULL,
    PRIMARY KEY (`id`)
) STRICT;

CREATE TABLE `sessions` (
    `token` TEXT NOT NULL,
    `uid` TEXT NOT NULL,
    `expiry` TEXT NOT NULL,
    PRIMARY KEY (`token`),
    FOREIGN KEY (`uid`) REFERENCES users(`id`)
) STRICT;

CREATE TABLE `invite_log` (
    `entry_id` TEXT NOT NULL,
    `invite` TEXT NOT NULL,
    `user` TEXT NOT NULL,
    PRIMARY KEY (`entry_id`),
    FOREIGN KEY (`invite`) REFERENCES invites(`token`)
) STRICT;

CREATE TABLE `oauth_states` (
    `state_id` TEXT NOT NULL,
    `origin` TEXT NOT NULL,
    `state` TEXT NOT NULL,
    PRIMARY KEY (`state_id`)
) STRICT;