make quote nicks case insensitive

This commit is contained in:
jkhsjdhjs 2019-03-31 18:32:44 +00:00
parent 7255dd4735
commit 32c106fc90
Signed by: jkhsjdhjs
GPG Key ID: BAC6ADBAB7D576CC
2 changed files with 17 additions and 1 deletions

View File

@ -12,6 +12,8 @@ Create a user with password, allowed to login and a database:
CREATE ROLE nxy WITH ENCRYPTED PASSWORD 'your-password';
ALTER ROLE nxy LOGIN;
CREATE DATABASE nxy_prod OWNER nxy;
\c nxy_prod
CREATE EXTENSION citext;
\q
```

View File

@ -1,6 +1,6 @@
create table if not exists quotes (
id serial primary key,
nick varchar(30) not null,
nick citext not null,
item text not null,
channel varchar(32) not null,
created_by varchar(30) not null,
@ -72,3 +72,17 @@ create table if not exists last_messages (
item text not null,
unique (nick, channel)
);
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();