CREATE TABLE radacct (
        RadAcctId               BIGSERIAL PRIMARY KEY,
        AcctSessionId           VARCHAR(32) NOT NULL,
        AcctUniqueId            VARCHAR(32) NOT NULL,
        UserName                VARCHAR(253),
        Realm                   VARCHAR(64),
        NASIPAddress            INET NOT NULL,
        NASPortId               VARCHAR(15),
        NASPortType             VARCHAR(32),
        AcctStartTime           TIMESTAMP with time zone,
        AcctStopTime            TIMESTAMP with time zone,
        AcctSessionTime         BIGINT,
        AcctAuthentic           VARCHAR(32),
        ConnectInfo_start       VARCHAR(50),
        ConnectInfo_stop        VARCHAR(50),
        AcctInputOctets         BIGINT,
        AcctOutputOctets        BIGINT,
        CalledStationId         VARCHAR(50),
        CallingStationId        VARCHAR(50),
        AcctTerminateCause      VARCHAR(32),
        ServiceType             VARCHAR(32),
        XAscendSessionSvrKey    VARCHAR(10),
        FramedProtocol          VARCHAR(32),
        FramedIPAddress         INET,
        AcctStartDelay          BIGINT,
        AcctStopDelay           BIGINT
);

CREATE TABLE radcheck (
        id              SERIAL PRIMARY KEY,
        UserName        VARCHAR(64) NOT NULL DEFAULT '',
        Attribute       VARCHAR(64) NOT NULL DEFAULT '',
        op              VARCHAR(2) NOT NULL DEFAULT '==',
        Value           VARCHAR(253) NOT NULL DEFAULT ''
);

CREATE TABLE radgroupcheck (
        id              SERIAL PRIMARY KEY,
        GroupName       VARCHAR(64) NOT NULL DEFAULT '',
        Attribute       VARCHAR(64) NOT NULL DEFAULT '',
        op              VARCHAR(2) NOT NULL DEFAULT '==',
        Value           VARCHAR(253) NOT NULL DEFAULT ''
);

CREATE TABLE radgroupreply (
        id              SERIAL PRIMARY KEY,
        GroupName       VARCHAR(64) NOT NULL DEFAULT '',
        Attribute       VARCHAR(64) NOT NULL DEFAULT '',
        op              VARCHAR(2) NOT NULL DEFAULT '=',
        Value           VARCHAR(253) NOT NULL DEFAULT ''
);

CREATE TABLE radreply (
        id              SERIAL PRIMARY KEY,
        UserName        VARCHAR(64) NOT NULL DEFAULT '',
        Attribute       VARCHAR(64) NOT NULL DEFAULT '',
        op              VARCHAR(2) NOT NULL DEFAULT '=',
        Value           VARCHAR(253) NOT NULL DEFAULT ''
);

CREATE TABLE usergroup (
        UserName        VARCHAR(64) NOT NULL DEFAULT '',
        GroupName       VARCHAR(64) NOT NULL DEFAULT '',
        priority        INTEGER NOT NULL DEFAULT 0
);

CREATE TABLE nas (
        id              SERIAL PRIMARY KEY,
        nasname         VARCHAR(128) NOT NULL,
        shortname       VARCHAR(32) NOT NULL,
        type            VARCHAR(30) NOT NULL DEFAULT 'other',
        ports           int4,
        secret          VARCHAR(60) NOT NULL,
        community       VARCHAR(50),
        description     VARCHAR(200)
);

CREATE TABLE radpostauth (
        id              BIGSERIAL PRIMARY KEY,
        username        VARCHAR(253) NOT NULL,
        pass            VARCHAR(128),
        reply           VARCHAR(32),
        authdate        TIMESTAMP with time zone NOT NULL default 'now'
) ;

CREATE TABLE radippool (
        id                      BIGSERIAL PRIMARY KEY,
        pool_name               text NOT NULL,
        FramedIPAddress         INET,
        NASIPAddress            text NOT NULL,
        CalledStationId         VARCHAR(64),
        CallingStationId        text NOT NULL DEFAULT ''::text,
        expiry_time             TIMESTAMP(0) without time zone NOT NULL,
        username                text DEFAULT ''::text,
        pool_key                VARCHAR(30) NOT NULL
);

create index radacct_UserName on radacct (UserName);
create index radacct_AcctSessionId on radacct (AcctSessionId);
create index radacct_AcctUniqueId on radacct (AcctUniqueId);
create index radacct_FramedIPAddress on radacct (FramedIPAddress);
create index radacct_NASIPAddress on radacct (NASIPAddress);
create index radacct_AcctStartTime on radacct (AcctStartTime);
create index radacct_AcctStopTime on radacct (AcctStopTime);

create index radcheck_UserName on radcheck (UserName);

create index radgroupcheck_GroupName on radgroupcheck (GroupName);

create index radgroupreply_GroupName on radgroupreply (GroupName);

create index radreply_UserName on radreply (UserName);

create index usergroup_UserName on usergroup (UserName);

create index nas_nasname on nas (nasname);
