CREATE TABLE cdr (
        AcctId		BIGSERIAL PRIMARY KEY,
	calldate	TIMESTAMP with time zone NOT NULL DEFAULT now(),
	clid		VARCHAR(80) NOT NULL default '',
	src		VARCHAR(80) NOT NULL default '',
	dst		VARCHAR(80) NOT NULL default '',
	dcontext	VARCHAR(80) NOT NULL default '',
	channel		VARCHAR(80) NOT NULL default '',
	dstchannel	VARCHAR(80) NOT NULL default '',
	lastapp		VARCHAR(80) NOT NULL default '',
	lastdata	VARCHAR(80) NOT NULL default '',
	duration	INTEGER NOT NULL default '0',
	billsec		INTEGER NOT NULL default '0',
	disposition	VARCHAR(45) NOT NULL default '',
	amaflags	INTEGER NOT NULL default '0',
	accountcode	VARCHAR(20) NOT NULL default '',
	uniqueid	VARCHAR(32) NOT NULL default '',
	userfield	VARCHAR(255) NOT NULL default ''
);

grant all on cdr to asterisk;
grant all on cdr_acctid_seq to asterisk;

create table t1_directorio (id bigserial, extension character varying(20) primary key, nombre character varying(200), fecha timestamp without time zone default now(),  empresa integer, userfield character varying(255));

GRANT ALL on t1_directorio_id_seq to asterisk ;
GRANT ALL on t1_directorio_interno_id_seGRANT ALL on t1_directorio to asterisk ;

create table t1_directorio_interno (id bigserial, extension character varying(20) primary key, usuariosip character varying(20), nombre character varying(200), fecha timestamp without time zone default now());

GRANT ALL on t1_directorio_interno_id_seq to asterisk ;
GRANT ALL on t1_directorio_interno to asterisk ;


CREATE TABLE t1_eventos (uniqueid character varying primary key, fecha timestamp without time zone not null default now(), comentario1 character varying, comentario2 character varying, userfield character varying(255), complementarias character varying, responsable character varying(255));

GRANT ALL on t1_eventos TO asterisk ;

CREATE TABLE t1_clientescampos (idcampo bigserial, nombre  character varying(200), userfield character varying(200) );

GRANT ALL on t1_clientescampos_idcampo_seq to asterisk ;
GRANT ALL on t1_clientescampos to asterisk ;

CREATE TABLE t1_tiposeventos (id bigserial, nombre character varying(255), userfield character varying(255) not null);

GRANT ALL ON t1_tiposeventos_id_seq to asterisk ;
GRANT ALL ON t1_tiposeventos to asterisk ;

GRANT ALL on t1_directorio to asterisk ;
GRANT ALL on t1_directorio_id_seq TO asterisk ;
