umami/sql/schema.postgresql.sql

71 lines
2.5 KiB
MySQL
Raw Normal View History

drop table if exists event;
drop table if exists pageview;
drop table if exists session;
drop table if exists website;
drop table if exists account;
2020-07-23 05:45:09 +02:00
create table account (
user_id serial primary key,
username varchar(255) unique not null,
password varchar(60) not null,
is_admin bool not null default false,
created_at timestamp with time zone default current_timestamp,
updated_at timestamp with time zone default current_timestamp
);
2020-07-17 10:03:38 +02:00
create table website (
2020-07-19 08:54:25 +02:00
website_id serial primary key,
website_uuid uuid unique not null,
2020-07-23 05:45:09 +02:00
user_id int not null references account(user_id) on delete cascade,
name varchar(100) not null,
domain varchar(500),
2020-07-17 10:03:38 +02:00
created_at timestamp with time zone default current_timestamp
);
create table session (
2020-07-19 08:54:25 +02:00
session_id serial primary key,
session_uuid uuid unique not null,
website_id int not null references website(website_id) on delete cascade,
2020-07-17 10:03:38 +02:00
created_at timestamp with time zone default current_timestamp,
hostname varchar(100),
2020-07-17 10:03:38 +02:00
browser varchar(20),
os varchar(20),
2020-08-07 04:14:44 +02:00
device varchar(20),
2020-07-17 10:03:38 +02:00
screen varchar(11),
language varchar(35),
country char(2)
);
create table pageview (
view_id serial primary key,
website_id int not null references website(website_id) on delete cascade,
2020-07-19 08:54:25 +02:00
session_id int not null references session(session_id) on delete cascade,
2020-07-17 10:03:38 +02:00
created_at timestamp with time zone default current_timestamp,
url varchar(500) not null,
referrer varchar(500)
);
create table event (
event_id serial primary key,
website_id int not null references website(website_id) on delete cascade,
2020-07-19 08:54:25 +02:00
session_id int not null references session(session_id) on delete cascade,
2020-07-17 10:03:38 +02:00
created_at timestamp with time zone default current_timestamp,
url varchar(500) not null,
event_type varchar(50) not null,
2020-07-19 11:23:15 +02:00
event_value varchar(50) not null
2020-07-18 04:33:40 +02:00
);
create index website_user_id_idx on website(user_id);
2020-08-12 05:05:40 +02:00
create index session_created_at_idx on session(created_at);
create index session_website_id_idx on session(website_id);
2020-07-23 05:45:09 +02:00
2020-08-12 05:05:40 +02:00
create index pageview_created_at_idx on pageview(created_at);
create index pageview_website_id_idx on pageview(website_id);
create index pageview_session_id_idx on pageview(session_id);
2020-07-21 04:24:33 +02:00
2020-08-12 05:05:40 +02:00
create index event_created_at_idx on event(created_at);
create index event_website_id_idx on event(website_id);
create index event_session_id_idx on event(session_id);
2020-07-21 04:24:33 +02:00
2020-08-12 05:05:40 +02:00
insert into account (username, password, is_admin) values ('admin', '$2a$10$BXHPV7APlV1I6WrKJt1igeJAyVsvbhMTaTAi3nHkUJFGPsYmfZq3y', true);