50 lines
1.3 KiB
SQL
50 lines
1.3 KiB
SQL
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
|
|
CREATE TABLE accounts (
|
|
id serial unique not null primary key,
|
|
login text not null,
|
|
pass text not null
|
|
);
|
|
|
|
CREATE TYPE "Role" AS ENUM (
|
|
'User',
|
|
'Admin'
|
|
);
|
|
|
|
CREATE TYPE "LocalBusinessState" AS ENUM (
|
|
'Pending',
|
|
'Approved',
|
|
'Banned',
|
|
'Pinned',
|
|
'Internal'
|
|
);
|
|
|
|
CREATE TABLE tokens (
|
|
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'
|
|
);
|
|
|
|
CREATE TABLE local_businesses (
|
|
id serial unique not null primary key,
|
|
owner_id int references accounts (id) not null,
|
|
name text not null,
|
|
description text not null,
|
|
state "LocalBusinessState" not null default 'Pending'
|
|
);
|
|
|
|
CREATE TABLE local_business_items (
|
|
id serial unique not null primary key,
|
|
local_business_id int references local_businesses (id) not null,
|
|
name text not null,
|
|
price bigint not null,
|
|
item_order int not null
|
|
);
|