oswilno/migrations/20220630202317_add_local_services.sql

50 lines
1.3 KiB
MySQL
Raw Normal View History

2022-07-04 08:31:12 +02:00
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE accounts (
2022-07-06 22:24:59 +02:00
id serial unique not null primary key,
login text not null,
pass text not null
2022-07-04 08:31:12 +02:00
);
CREATE TYPE "Role" AS ENUM (
2022-07-06 22:24:59 +02:00
'User',
'Admin'
2022-07-04 08:31:12 +02:00
);
CREATE TYPE "LocalServiceState" AS ENUM (
2022-07-06 22:24:59 +02:00
'Pending',
'Approved',
'Banned',
'Pinned',
'Internal'
2022-07-04 08:31:12 +02:00
);
CREATE TABLE tokens (
2022-07-06 22:24:59 +02:00
id serial unique not null primary key,
claims jsonb not null,
iss text not null default 'oswilno', /* issuer */
sub int references accounts (id), /* subject */
aud text not null default 'public', /* audience */
exp timestamp not null, /* expiration time */
nbt timestamp not null default now(), /* not before time */
iat timestamp not null default now(), /* issued at time */
jti uuid not null unique, /* JWT ID - unique */
role "Role" not null default 'User'
2022-07-04 08:31:12 +02:00
);
CREATE TABLE local_services (
2022-07-06 22:24:59 +02:00
id serial unique not null primary key,
owner_id int references accounts (id) not null,
name text not null,
description text not null,
state "LocalServiceState" not null default 'Pending'
2022-07-04 08:31:12 +02:00
);
CREATE TABLE local_service_items (
2022-07-06 22:24:59 +02:00
id serial unique not null primary key,
local_service_id int references local_services (id) not null,
name text not null,
price bigint not null,
item_order int not null
2022-07-04 08:31:12 +02:00
);