make quote nicks case insensitive
This commit is contained in:
		@@ -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
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user