create table profile ( id text primary key, username varchar(30) not null, inbox text not null, outbox text not null, local boolean not null, avatar text, email 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 unique index unique_username_local on profile (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 profile for each row execute function set_updated_at();