Skip to content

Commit

Permalink
DB migration rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Jul 2, 2020
1 parent 5049a30 commit d1b78e3
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 13 deletions.
50 changes: 45 additions & 5 deletions db/schema.pgsql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ create table sites (
code varchar not null check(length(code) >= 2 and length(code) <= 50),
link_domain varchar not null default '' check(link_domain = '' or (length(link_domain) >= 4 and length(link_domain) <= 255)),
cname varchar null check(cname is null or (length(cname) >= 4 and length(cname) <= 255)),
cname_setup_at timestamp default null,
plan varchar not null check(plan in ('personal', 'personalplus', 'business', 'businessplus', 'child', 'custom')),
stripe varchar null,
settings json not null,
Expand All @@ -35,6 +36,8 @@ create table users (
email varchar not null check(length(email) > 5 and length(email) <= 255),
email_verified integer not null default 0,
password bytea default null,
totp_enabled integer not null default 0,
totp_secret bytea,
role varchar not null default '' check(role in ('', 'a')),
login_at timestamp null,
login_request varchar null,
Expand All @@ -52,6 +55,20 @@ create table users (
create index "users#site" on users(site);
create unique index "users#site#email" on users(site, lower(email));

create table api_tokens (
api_token_id serial primary key,
site_id integer not null,
user_id integer not null,
name varchar not null,
token varchar not null check(length(token) > 10),
permissions jsonb not null,
created_at timestamp not null,

foreign key (site_id) references sites(id) on delete restrict on update restrict,
foreign key (user_id) references users(id) on delete restrict on update restrict
);
create unique index "api_tokens#site_id#token" on api_tokens(site_id, token);

create table hits (
id serial primary key,
site integer not null check(site > 0),
Expand Down Expand Up @@ -524,6 +541,25 @@ create table botlog (
foreign key (ip) references botlog_ips(id)
);

create table exports (
export_id serial primary key,
site_id integer not null,
start_from_hit_id integer not null,

path varchar not null,
created_at timestamp not null,

finished_at timestamp,
last_hit_id integer,
num_rows integer,
size varchar,
hash varchar,
error varchar,

foreign key (site_id) references sites(id) on delete restrict on update restrict
);
create index "exports#site_id#created_at" on exports(site_id, created_at);

create table version (name varchar);
insert into version values
('2019-10-16-1-geoip'),
Expand Down Expand Up @@ -572,11 +608,15 @@ insert into version values
('2020-05-17-1-rm-user-name'),
('2020-05-16-1-os_stats'),
('2020-05-18-1-domain-count'),
('2020-05-21-1-ref-count'),
('2020-05-23-1-botlog'),
('2020-05-23-1-event'),
('2020-05-23-1-index'),
('2020-05-23-2-drop-ref-stats'),
('2020-06-03-1-cname-setup'),
('2020-06-18-1-totp'),
('2020-06-26-1-api-tokens'),
('2020-06-26-1-record-export');

('2020-05-21-1-ref-count'),
('2020-05-23-1-botlog'),
('2020-05-23-1-event'),
('2020-05-23-1-index'),
('2020-05-23-2-drop-ref-stats');

-- vim:ft=sql
42 changes: 41 additions & 1 deletion db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ create table sites (
code varchar not null check(length(code) >= 2 and length(code) <= 50),
link_domain varchar not null default '' check(link_domain = '' or (length(link_domain) >= 4 and length(link_domain) <= 255)),
cname varchar null check(cname is null or (length(cname) >= 4 and length(cname) <= 255)),
cname_setup_at timestamp default null check(cname_setup_at = strftime('%Y-%m-%d %H:%M:%S', cname_setup_at)),
plan varchar not null check(plan in ('personal', 'personalplus', 'business', 'businessplus', 'child', 'custom')),
stripe varchar null,
settings varchar not null,
Expand All @@ -21,6 +22,8 @@ create table users (
site integer not null check(site > 0),

password blob default null,
totp_enabled integer not null default 0,
totp_secret blob,
email varchar not null check(length(email) > 5 and length(email) <= 255),
email_verified int not null default 0,
role varchar not null default '' check(role in ('', 'a')),
Expand All @@ -40,6 +43,20 @@ create table users (
create index "users#site" on users(site);
create unique index "users#site#email" on users(site, lower(email));

create table api_tokens (
api_token_id integer primary key autoincrement,
site_id integer not null,
user_id integer not null,
name varchar not null,
token varchar not null check(length(token) > 10),
permissions jsonb not null,
created_at timestamp not null check(created_at = strftime('%Y-%m-%d %H:%M:%S', created_at)),

foreign key (site_id) references sites(id) on delete restrict on update restrict,
foreign key (user_id) references users(id) on delete restrict on update restrict
);
create unique index "api_tokens#site_id#token" on api_tokens(site_id, token);

create table hits (
id integer primary key autoincrement,
site integer not null check(site > 0),
Expand Down Expand Up @@ -485,6 +502,25 @@ create table updates (
);
create index "updates#show_at" on updates(show_at);

create table exports (
export_id integer primary key autoincrement,
site_id integer not null,
start_from_hit_id integer not null,

path varchar not null,
created_at timestamp not null check(created_at = strftime('%Y-%m-%d %H:%M:%S', created_at)),

finished_at timestamp check(finished_at is null or finished_at = strftime('%Y-%m-%d %H:%M:%S', created_at)),
last_hit_id integer,
num_rows integer,
size varchar,
hash varchar,
error varchar,

foreign key (site_id) references sites(id) on delete restrict on update restrict
);
create index "exports#site_id#created_at" on exports(site_id, created_at);

create table version (name varchar);
insert into version values
('2019-10-16-1-geoip'),
Expand Down Expand Up @@ -526,4 +562,8 @@ insert into version values
('2020-05-21-1-ref-count'),
('2020-05-23-1-event'),
('2020-05-23-1-index'),
('2020-05-23-2-drop-ref-stats');
('2020-05-23-2-drop-ref-stats'),
('2020-06-03-1-cname-setup'),
('2020-06-18-1-totp'),
('2020-06-26-1-api-tokens'),
('2020-06-26-1-record-export');
94 changes: 87 additions & 7 deletions pack/pack.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d1b78e3

Please sign in to comment.