241b38d7d7c2d87b58bda44be3297008287696ef
[pharext/pharext.org] / config / sql / 001.sql
1 drop table if exists authorities cascade;
2 drop table if exists accounts cascade;
3 drop table if exists tokens cascade;
4 drop table if exists owners cascade;
5
6 create table authorities (
7 authority text not null primary key
8 );
9
10 insert into authorities values('github');
11
12 create table accounts (
13 account uuid not null default uuid_generate_v4() primary key
14 );
15
16 create table tokens (
17 token text not null primary key
18 ,account uuid not null references accounts on update cascade on delete cascade
19 ,authority text not null references authorities on update cascade on delete cascade
20 ,oauth jsonb
21 );
22
23 create table owners (
24 account uuid not null references accounts on update cascade on delete cascade
25 ,authority text not null references authorities on update cascade on delete cascade
26 ,login text not null
27 ,owner jsonb
28 ,primary key (account,authority)
29 ,unique key (login,authority)
30 );