rudemaps/scripts/db/postgresql/schema.sql

35 lines
933 B
PL/PgSQL

create type user_role as enum ('USER','ADMIN','EDITOR');
create table users(
id serial primary key,
username text unique not null,
name text,
surname text,
email text,
createts timestamptz not null default now(),
password text,
salt text,
updatets timestamptz not null default now(),
role_list user_role[] not null default ARRAY['USER'::user_role],
user_data jsonb
);
create table maps(
id bigserial primary key,
name text not null,
description text,
owner integer not null references users(id),
createts timestamptz not null default now(),
updatets timestamptz not null default now(),
map_data jsonb
);
create or replace function update_ts_tg() returns trigger as $$
begin
new.updatets:=now();
return new;
end;
$$
language plpgsql;
create trigger tg_update_ts before update on users for each row execute procedure update_ts_tg();
create trigger tg_update_ts before update on maps for each row execute procedure update_ts_tg();