CREATE TABLE `Printer` (
  `id` int UNIQUE PRIMARY KEY,
  `name` text,
  `description` text,
  `status` int COMMENT '0: OPERATIONAL
1: OUT_OF_ORDER',
  `created_at` timestamp,
  `updated_at` timestamp
);

CREATE TABLE `PrintJob` (
  `id` int UNIQUE PRIMARY KEY,
  `printer_id` int,
  `user_id` int,
  `start_at` timestamp,
  `duration_in_minutes` int,
  `comments` text,
  `aborted` boolean DEFAULT false,
  `abort_reason` text COMMENT 'Error code displayed on printer'
);

CREATE TABLE `Account` (
  `id` text UNIQUE PRIMARY KEY,
  `userId` text,
  `type` text,
  `provider` text,
  `providerAccountId` text,
  `refresh_token` text,
  `access_token` text,
  `expires_at` int,
  `token_type` text,
  `scope` text,
  `id_token` text,
  `session_state` text
);

CREATE TABLE `Session` (
  `id` text UNIQUE PRIMARY KEY,
  `sessionToken` text UNIQUE,
  `userId` text,
  `expires` datetime
);

CREATE TABLE `User` (
  `id` text PRIMARY KEY,
  `name` text,
  `email` text UNIQUE,
  `role` text COMMENT 'ADMIN,USER,GUEST'
);

ALTER TABLE `User` ADD FOREIGN KEY (`id`) REFERENCES `PrintJob` (`user_id`);

ALTER TABLE `User` ADD FOREIGN KEY (`id`) REFERENCES `Account` (`userId`);

ALTER TABLE `User` ADD FOREIGN KEY (`id`) REFERENCES `Session` (`userId`);

ALTER TABLE `Printer` ADD FOREIGN KEY (`id`) REFERENCES `PrintJob` (`printer_id`);
