summaryrefslogtreecommitdiffstats
path: root/raddb/mods-config/sql/cui/postgresql/schema.sql
blob: 3b24401de81f9cc1b929a01d2e4e98bebe236db8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
CREATE TABLE cui (
  clientipaddress INET NOT NULL DEFAULT '0.0.0.0',
  callingstationid varchar(50) NOT NULL DEFAULT '',
  username varchar(64) NOT NULL DEFAULT '',
  cui varchar(32) NOT NULL DEFAULT '',
  creationdate TIMESTAMP with time zone NOT NULL default 'now()',
  lastaccounting TIMESTAMP with time zone NOT NULL default '-infinity'::timestamp,
  PRIMARY KEY  (username, clientipaddress, callingstationid)
);

CREATE RULE postauth_query AS ON INSERT TO cui
	WHERE EXISTS(SELECT 1 FROM cui WHERE (username, clientipaddress, callingstationid)=(NEW.username, NEW.clientipaddress, NEW.callingstationid))
	DO INSTEAD UPDATE cui SET lastaccounting ='-infinity'::timestamp with time zone, cui=NEW.cui WHERE (username, clientipaddress, callingstationid)=(NEW.username, NEW.clientipaddress, NEW.callingstationid);