2017-05-16 05:45:10 +00:00
|
|
|
create table if not exists quotes (
|
2017-06-30 15:47:24 +00:00
|
|
|
id serial primary key,
|
2019-03-31 18:32:44 +00:00
|
|
|
nick citext not null,
|
2017-06-30 15:47:24 +00:00
|
|
|
item text not null,
|
|
|
|
channel varchar(32) not null,
|
|
|
|
created_by varchar(30) not null,
|
|
|
|
created_at timestamp not null default current_timestamp,
|
2017-05-29 16:44:26 +00:00
|
|
|
unique (nick, item)
|
2017-05-16 05:45:10 +00:00
|
|
|
);
|
|
|
|
|
2017-05-16 10:06:29 +00:00
|
|
|
create table if not exists mcmaniacs (
|
2017-06-29 20:56:32 +00:00
|
|
|
id serial primary key,
|
2021-01-06 19:44:19 +00:00
|
|
|
item citext not null,
|
2017-06-29 20:56:32 +00:00
|
|
|
unique (item)
|
2017-05-16 05:45:10 +00:00
|
|
|
);
|
2017-05-16 10:06:29 +00:00
|
|
|
|
|
|
|
create table if not exists timers (
|
2017-06-30 11:25:56 +00:00
|
|
|
id serial primary key,
|
|
|
|
mask varchar(255) not null,
|
|
|
|
target varchar(32) not null,
|
|
|
|
message text not null,
|
|
|
|
delay varchar(10) not null,
|
|
|
|
ends_at timestamp not null,
|
|
|
|
created_at timestamp not null default current_timestamp
|
2017-05-16 10:06:29 +00:00
|
|
|
);
|
2017-05-16 16:34:29 +00:00
|
|
|
|
|
|
|
create table if not exists tells (
|
2017-06-29 20:56:32 +00:00
|
|
|
id serial primary key,
|
|
|
|
from_nick varchar(30) not null,
|
|
|
|
to_nick varchar(30) not null,
|
|
|
|
message text not null,
|
|
|
|
created_at timestamp not null default current_timestamp,
|
|
|
|
unique (to_nick, message)
|
2017-05-16 16:34:29 +00:00
|
|
|
);
|
2017-05-29 12:39:48 +00:00
|
|
|
|
|
|
|
create table if not exists seens (
|
2017-06-30 15:47:24 +00:00
|
|
|
id serial primary key,
|
|
|
|
nick varchar(30) not null,
|
|
|
|
host varchar(255) not null,
|
|
|
|
channel varchar(32) not null,
|
|
|
|
message text not null,
|
|
|
|
seen_at timestamp not null default current_timestamp,
|
2017-06-29 20:56:32 +00:00
|
|
|
unique (nick)
|
2017-05-29 12:39:48 +00:00
|
|
|
);
|
2017-05-31 12:05:55 +00:00
|
|
|
|
2017-06-30 15:47:24 +00:00
|
|
|
create table if not exists users (
|
|
|
|
id serial primary key,
|
|
|
|
nick varchar(30) not null,
|
|
|
|
husbando varchar(255) null,
|
|
|
|
waifu varchar(255) null,
|
|
|
|
fines integer default 0,
|
2017-06-29 20:56:32 +00:00
|
|
|
unique (nick)
|
2017-05-31 12:05:55 +00:00
|
|
|
);
|
2017-06-30 15:47:24 +00:00
|
|
|
|
|
|
|
create table if not exists kills (
|
|
|
|
id serial primary key,
|
|
|
|
item text not null,
|
|
|
|
unique (item)
|
|
|
|
);
|
|
|
|
|
|
|
|
create table if not exists yiffs (
|
|
|
|
id serial primary key,
|
|
|
|
item text not null,
|
|
|
|
unique (item)
|
|
|
|
);
|
2017-07-04 13:22:20 +00:00
|
|
|
|
|
|
|
create table if not exists last_messages (
|
|
|
|
id serial primary key,
|
|
|
|
nick varchar(30) not null,
|
|
|
|
host varchar(255) not null,
|
|
|
|
channel varchar(32) not null,
|
|
|
|
item text not null,
|
|
|
|
unique (nick, channel)
|
|
|
|
);
|
2019-03-31 18:32:44 +00:00
|
|
|
|
|
|
|
create or replace function quotes_ci_nick_insert_fnc()
|
|
|
|
returns trigger as $$
|
|
|
|
begin
|
|
|
|
NEW.nick = coalesce((select nick from quotes where nick = NEW.nick limit 1), NEW.nick);
|
|
|
|
return NEW;
|
|
|
|
end $$ language 'plpgsql';
|
|
|
|
|
|
|
|
drop trigger if exists quotes_ci_nick_trigger on quotes;
|
|
|
|
|
|
|
|
create trigger quotes_ci_nick_trigger
|
|
|
|
before insert on quotes
|
|
|
|
for each row
|
|
|
|
execute procedure quotes_ci_nick_insert_fnc();
|