summaryrefslogtreecommitdiffstats
path: root/migrations/20250713161354_account.sql
blob: 1b967b8d5659d0f9843dbb22b34bc94e1f1318e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
create table account (
    id uuid primary key,
    username varchar(30) not null,
    inbox text not null,
    outbox text,
    local boolean not null,
    ap_id text not null unique,
    private_key text,
    avatar_url text,
    description text,
    user_type text not null check (
        user_type IN ('PERSON', 'APPLICATION', 'GROUP', 'ORGANIZATION', 'SERVICE')
    ),
    created_at timestamptz not null default now(),
    updated_at timestamptz not null default now(),
    public_key text not null
);

create table following (
    id uuid primary key,
    follower text references account(ap_id) on delete cascade,
    followee text references account(ap_id) on delete cascade,
    created_at timestamptz not null default now(),
    constraint unique_following unique (follower, followee)
);
create index "following_pagination" on "following" ("created_at" asc);

create unique index unique_username_local
    on account (username)
    where local = true;

create or replace function set_updated_at()
returns trigger as $$
begin
  new.updated_at := now();
  return new;
end;
$$ language plpgsql;

create trigger trigger_set_updated_at
before update on account
for each row
execute function set_updated_at();