--
--


SELECT pg_catalog.set_config('search_path', '', false);

--
-- Name: curdate(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.curdate() RETURNS date
    LANGUAGE plpgsql
    AS $$
BEGIN
RETURN current_date;
END; $$;


ALTER FUNCTION public.curdate() OWNER TO postgres;

--
-- Name: fr_new_data_usage_period(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.fr_new_data_usage_period() RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE v_start timestamp;
DECLARE v_end timestamp;
BEGIN

    SELECT COALESCE(MAX(period_start), TO_TIMESTAMP(0)) INTO v_start FROM data_usage_by_period;
    SELECT DATE_TRUNC('second',CURRENT_TIMESTAMP) INTO v_end;

    --
    -- Add the data usage for the sessions that were active in the current
    -- period to the table. Include all sessions that finished since the start
    -- of this period as well as those still ongoing.
    --
    INSERT INTO data_usage_by_period (username, period_start, period_end, acctinputoctets, acctoutputoctets)
    SELECT *
    FROM (
        SELECT
            username,
            v_start,
            v_end,
            SUM(acctinputoctets) AS acctinputoctets,
            SUM(acctoutputoctets) AS acctoutputoctets
        FROM
            radacct
        WHERE
            acctstoptime > v_start OR
            acctstoptime IS NULL
        GROUP BY
            username
    ) AS s
    ON CONFLICT ON CONSTRAINT data_usage_by_period_pkey
    DO UPDATE
        SET
            acctinputoctets = data_usage_by_period.acctinputoctets + EXCLUDED.acctinputoctets,
            acctoutputoctets = data_usage_by_period.acctoutputoctets + EXCLUDED.acctoutputoctets,
            period_end = v_end;

    --
    -- Create an open-ended "next period" for all ongoing sessions and carry a
    -- negative value of their data usage to avoid double-accounting when we
    -- process the next period. Their current data usage has already been
    -- allocated to the current and possibly previous periods.
    --
    INSERT INTO data_usage_by_period (username, period_start, period_end, acctinputoctets, acctoutputoctets)
    SELECT *
    FROM (
        SELECT
            username,
            v_end + INTERVAL '1 SECOND',
            NULL::timestamp,
            0 - SUM(acctinputoctets),
            0 - SUM(acctoutputoctets)
        FROM
            radacct
        WHERE
            acctstoptime IS NULL
        GROUP BY
            username
    ) AS s;

END
$$;


ALTER FUNCTION public.fr_new_data_usage_period() OWNER TO postgres;



--
-- Name: data_usage_by_period; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.data_usage_by_period (
    username text NOT NULL,
    period_start timestamp with time zone NOT NULL,
    period_end timestamp with time zone,
    acctinputoctets bigint,
    acctoutputoctets bigint
);


ALTER TABLE public.data_usage_by_period OWNER TO postgres;

--
-- Name: nas; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.nas (
    id integer NOT NULL,
    nasname text NOT NULL,
    shortname text NOT NULL,
    type text DEFAULT 'other'::text NOT NULL,
    ports integer,
    secret text NOT NULL,
    server text,
    community text,
    description text
);


ALTER TABLE public.nas OWNER TO postgres;

--
-- Name: nas_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.nas_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.nas_id_seq OWNER TO postgres;

--
-- Name: nas_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.nas_id_seq OWNED BY public.nas.id;


--
-- Name: radacct; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.radacct (
    radacctid bigint NOT NULL,
    acctsessionid text NOT NULL,
    acctuniqueid text NOT NULL,
    username text,
    realm text,
    nasipaddress inet NOT NULL,
    nasportid text,
    nasporttype text,
    acctstarttime timestamp with time zone,
    acctupdatetime timestamp with time zone,
    acctstoptime timestamp with time zone,
    acctinterval bigint,
    acctsessiontime bigint,
    acctauthentic text,
    connectinfo_start text,
    connectinfo_stop text,
    acctinputoctets bigint,
    acctoutputoctets bigint,
    calledstationid text,
    callingstationid text,
    acctterminatecause text,
    servicetype text,
    framedprotocol text,
    framedipaddress inet,
    framedipv6address inet,
    framedipv6prefix inet,
    framedinterfaceid text,
    delegatedipv6prefix inet
);


ALTER TABLE public.radacct OWNER TO postgres;

--
-- Name: radacct_radacctid_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.radacct_radacctid_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.radacct_radacctid_seq OWNER TO postgres;

--
-- Name: radacct_radacctid_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.radacct_radacctid_seq OWNED BY public.radacct.radacctid;


--
-- Name: radcheck; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.radcheck (
    id integer NOT NULL,
    username text DEFAULT ''::text NOT NULL,
    attribute text DEFAULT ''::text NOT NULL,
    op character varying(2) DEFAULT '=='::character varying NOT NULL,
    value text DEFAULT ''::text NOT NULL
);


ALTER TABLE public.radcheck OWNER TO postgres;

--
-- Name: radcheck_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.radcheck_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.radcheck_id_seq OWNER TO postgres;

--
-- Name: radcheck_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.radcheck_id_seq OWNED BY public.radcheck.id;


--
-- Name: radgroupcheck; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.radgroupcheck (
    id integer NOT NULL,
    groupname text DEFAULT ''::text NOT NULL,
    attribute text DEFAULT ''::text NOT NULL,
    op character varying(2) DEFAULT '=='::character varying NOT NULL,
    value text DEFAULT ''::text NOT NULL
);


ALTER TABLE public.radgroupcheck OWNER TO postgres;

--
-- Name: radgroupcheck_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.radgroupcheck_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.radgroupcheck_id_seq OWNER TO postgres;

--
-- Name: radgroupcheck_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.radgroupcheck_id_seq OWNED BY public.radgroupcheck.id;


--
-- Name: radgroupreply; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.radgroupreply (
    id integer NOT NULL,
    groupname text DEFAULT ''::text NOT NULL,
    attribute text DEFAULT ''::text NOT NULL,
    op character varying(2) DEFAULT '='::character varying NOT NULL,
    value text DEFAULT ''::text NOT NULL
);


ALTER TABLE public.radgroupreply OWNER TO postgres;

--
-- Name: radgroupreply_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.radgroupreply_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.radgroupreply_id_seq OWNER TO postgres;

--
-- Name: radgroupreply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.radgroupreply_id_seq OWNED BY public.radgroupreply.id;


--
-- Name: radpostauth; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.radpostauth (
    id bigint NOT NULL,
    username text NOT NULL,
    pass text,
    reply text,
    calledstationid text,
    callingstationid text,
    authdate timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.radpostauth OWNER TO postgres;

--
-- Name: radpostauth_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.radpostauth_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.radpostauth_id_seq OWNER TO postgres;

--
-- Name: radpostauth_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.radpostauth_id_seq OWNED BY public.radpostauth.id;


--
-- Name: radreply; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.radreply (
    id integer NOT NULL,
    username text DEFAULT ''::text NOT NULL,
    attribute text DEFAULT ''::text NOT NULL,
    op character varying(2) DEFAULT '='::character varying NOT NULL,
    value text DEFAULT ''::text NOT NULL
);


ALTER TABLE public.radreply OWNER TO postgres;

--
-- Name: radreply_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.radreply_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.radreply_id_seq OWNER TO postgres;

--
-- Name: radreply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.radreply_id_seq OWNED BY public.radreply.id;


--
-- Name: radusergroup; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.radusergroup (
    id integer NOT NULL,
    username text DEFAULT ''::text NOT NULL,
    groupname text DEFAULT ''::text NOT NULL,
    priority integer DEFAULT 0 NOT NULL
);


ALTER TABLE public.radusergroup OWNER TO postgres;

--
-- Name: radusergroup_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.radusergroup_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.radusergroup_id_seq OWNER TO postgres;

--
-- Name: radusergroup_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.radusergroup_id_seq OWNED BY public.radusergroup.id;


--
-- Name: recharge; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.recharge (
    id integer NOT NULL,
    app_recharges_id uuid NOT NULL,
    mac character varying(20) NOT NULL
);


ALTER TABLE public.recharge OWNER TO postgres;

--
-- Name: recharge_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.recharge_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.recharge_id_seq OWNER TO postgres;

--
-- Name: recharge_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.recharge_id_seq OWNED BY public.recharge.id;


--
-- Name: nas id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.nas ALTER COLUMN id SET DEFAULT nextval('public.nas_id_seq'::regclass);


--
-- Name: radacct radacctid; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radacct ALTER COLUMN radacctid SET DEFAULT nextval('public.radacct_radacctid_seq'::regclass);


--
-- Name: radcheck id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radcheck ALTER COLUMN id SET DEFAULT nextval('public.radcheck_id_seq'::regclass);


--
-- Name: radgroupcheck id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radgroupcheck ALTER COLUMN id SET DEFAULT nextval('public.radgroupcheck_id_seq'::regclass);


--
-- Name: radgroupreply id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radgroupreply ALTER COLUMN id SET DEFAULT nextval('public.radgroupreply_id_seq'::regclass);


--
-- Name: radpostauth id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radpostauth ALTER COLUMN id SET DEFAULT nextval('public.radpostauth_id_seq'::regclass);


--
-- Name: radreply id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radreply ALTER COLUMN id SET DEFAULT nextval('public.radreply_id_seq'::regclass);


--
-- Name: radusergroup id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radusergroup ALTER COLUMN id SET DEFAULT nextval('public.radusergroup_id_seq'::regclass);


--
-- Name: recharge id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.recharge ALTER COLUMN id SET DEFAULT nextval('public.recharge_id_seq'::regclass);


--
-- Data for Name: data_usage_by_period; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.data_usage_by_period (username, period_start, period_end, acctinputoctets, acctoutputoctets) FROM stdin;
\.


--
-- Data for Name: nas; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.nas (id, nasname, shortname, type, ports, secret, server, community, description) FROM stdin;
\.


--
-- Data for Name: radacct; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.radacct (radacctid, acctsessionid, acctuniqueid, username, realm, nasipaddress, nasportid, nasporttype, acctstarttime, acctupdatetime, acctstoptime, acctinterval, acctsessiontime, acctauthentic, connectinfo_start, connectinfo_stop, acctinputoctets, acctoutputoctets, calledstationid, callingstationid, acctterminatecause, servicetype, framedprotocol, framedipaddress, framedipv6address, framedipv6prefix, framedinterfaceid, delegatedipv6prefix) FROM stdin;
1	LIM-ITX00000000000000b6e525015104	7c10fc9c2514b0ae937e4e350af02040		\N	10.20.129.1	\N		2020-04-23 16:11:50-05	2020-04-23 16:11:50-05	2020-04-23 16:11:50-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
2	LIM-ITX00000000000000f44805015104	aec6d4f21eadba1b806b74d3f407596c		\N	10.20.129.1	\N		2020-04-23 16:12:15-05	2020-04-23 16:12:15-05	2020-04-23 16:12:15-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
3	LIM-ITX0000000000000016dca7015104	b442a72abac933f943de1b101dd9693e		\N	10.20.129.1	\N		2020-04-23 16:13:32-05	2020-04-23 16:13:32-05	2020-04-23 16:13:32-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
4	LIM-ITX00000000000000bff6f8015104	7ff238c2389a97025a130cd6e1d21d97		\N	10.20.129.1	\N		2020-04-23 16:13:58-05	2020-04-23 16:13:58-05	2020-04-23 16:13:58-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
5	LIM-ITX0000000000000098630c015104	c948e462f5759c710f39c23907f5184e		\N	10.20.129.1	\N		2020-04-23 16:14:54-05	2020-04-23 16:14:54-05	2020-04-23 16:14:54-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
6	LIM-ITX000000000000003b53b0015104	1360f18f736e4dde2811cd17d66146b2		\N	10.20.129.1	\N		2020-04-23 16:15:30-05	2020-04-23 16:15:30-05	2020-04-23 16:15:30-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
7	LIM-ITX000000000000002ad387015104	3ea73b7df091844f23bd3908c24123e6		\N	10.20.129.1	\N		2020-04-23 16:16:32-05	2020-04-23 16:16:32-05	2020-04-23 16:16:32-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
8	LIM-ITX0000000000000095b4e2015104	870c0c68ac63dbb927ea312333f2718c		\N	10.20.129.1	\N		2020-04-23 16:16:52-05	2020-04-23 16:16:52-05	2020-04-23 16:16:52-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
9	LIM-ITX00000000000000bae46c015104	490a47c0e2070d6582d69d0b07b31594		\N	10.20.129.1	\N		2020-04-23 16:17:37-05	2020-04-23 16:17:37-05	2020-04-23 16:17:37-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
10	LIM-ITX00000000000000948f9d015104	068dd3b02b95d9fa726dcbd34f1d5c4d		\N	10.20.129.1	\N		2020-04-23 16:18:57-05	2020-04-23 16:18:57-05	2020-04-23 16:18:57-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
11	LIM-ITX00000000000000462b8e015104	76fc184cfec18e42ca64bf565ddca396		\N	10.20.129.1	\N		2020-04-23 16:20:45-05	2020-04-23 16:20:45-05	2020-04-23 16:20:45-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
12	LIM-ITX00000000000000c4607b015104	1ce8765668022a0f24ebeaa255ee6947		\N	10.20.129.1	\N		2020-04-23 16:31:13-05	2020-04-23 16:31:13-05	2020-04-23 16:31:13-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
13	LIM-ITX00000000000000e9e69d015104	8b678c7f6ed89ed910523f078215108f		\N	190.108.83.113	\N		2020-04-23 16:50:22-05	2020-04-23 16:50:22-05	2020-04-23 16:50:22-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
14	LIM-ITX00000000000000aa59a5015104	16f8c6b9963b5fc63e291021220c24d8		\N	190.108.83.113	\N		2020-04-23 16:51:50-05	2020-04-23 16:51:50-05	2020-04-23 16:51:50-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
15	LIM-ITX00000000000000923a55015104	37d152ad7b56a9776fc13da77dbcdb18		\N	190.108.83.113	\N		2020-04-24 08:52:55-05	2020-04-24 08:52:55-05	2020-04-24 08:52:55-05	\N	\N			\N	0	0			User-Request			\N	\N	\N	\N	\N
\.


--
-- Data for Name: radcheck; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.radcheck (id, username, attribute, op, value) FROM stdin;
\.


--
-- Data for Name: radgroupcheck; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.radgroupcheck (id, groupname, attribute, op, value) FROM stdin;
\.


--
-- Data for Name: radgroupreply; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.radgroupreply (id, groupname, attribute, op, value) FROM stdin;
\.


--
-- Data for Name: radpostauth; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.radpostauth (id, username, pass, reply, calledstationid, callingstationid, authdate) FROM stdin;
\.


--
-- Data for Name: radreply; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.radreply (id, username, attribute, op, value) FROM stdin;
\.


--
-- Data for Name: radusergroup; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.radusergroup (id, username, groupname, priority) FROM stdin;
\.


--
-- Data for Name: recharge; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.recharge (id, app_recharges_id, mac) FROM stdin;
1	8454b760-bb4b-4eaf-9f53-68c28146e9fa	01020303AABC
\.


--
-- Name: nas_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.nas_id_seq', 1, false);


--
-- Name: radacct_radacctid_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.radacct_radacctid_seq', 15, true);


--
-- Name: radcheck_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.radcheck_id_seq', 1, false);


--
-- Name: radgroupcheck_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.radgroupcheck_id_seq', 1, false);


--
-- Name: radgroupreply_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.radgroupreply_id_seq', 1, false);


--
-- Name: radpostauth_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.radpostauth_id_seq', 1, false);


--
-- Name: radreply_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.radreply_id_seq', 1, false);


--
-- Name: radusergroup_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.radusergroup_id_seq', 1, false);


--
-- Name: recharge_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.recharge_id_seq', 2, true);


--
-- Name: data_usage_by_period data_usage_by_period_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.data_usage_by_period
    ADD CONSTRAINT data_usage_by_period_pkey PRIMARY KEY (username, period_start);


--
-- Name: nas nas_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.nas
    ADD CONSTRAINT nas_pkey PRIMARY KEY (id);


--
-- Name: radacct radacct_acctuniqueid_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radacct
    ADD CONSTRAINT radacct_acctuniqueid_key UNIQUE (acctuniqueid);


--
-- Name: radacct radacct_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radacct
    ADD CONSTRAINT radacct_pkey PRIMARY KEY (radacctid);


--
-- Name: radcheck radcheck_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radcheck
    ADD CONSTRAINT radcheck_pkey PRIMARY KEY (id);


--
-- Name: radgroupcheck radgroupcheck_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radgroupcheck
    ADD CONSTRAINT radgroupcheck_pkey PRIMARY KEY (id);


--
-- Name: radgroupreply radgroupreply_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radgroupreply
    ADD CONSTRAINT radgroupreply_pkey PRIMARY KEY (id);


--
-- Name: radpostauth radpostauth_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radpostauth
    ADD CONSTRAINT radpostauth_pkey PRIMARY KEY (id);


--
-- Name: radreply radreply_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radreply
    ADD CONSTRAINT radreply_pkey PRIMARY KEY (id);


--
-- Name: radusergroup radusergroup_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.radusergroup
    ADD CONSTRAINT radusergroup_pkey PRIMARY KEY (id);


--
-- Name: recharge recharge_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.recharge
    ADD CONSTRAINT recharge_pkey PRIMARY KEY (id);


--
-- Name: nas_nasname; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX nas_nasname ON public.nas USING btree (nasname);


--
-- Name: radacct_active_session_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX radacct_active_session_idx ON public.radacct USING btree (acctuniqueid) WHERE (acctstoptime IS NULL);


--
-- Name: radacct_bulk_close; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX radacct_bulk_close ON public.radacct USING btree (nasipaddress, acctstarttime) WHERE (acctstoptime IS NULL);


--
-- Name: radacct_start_user_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX radacct_start_user_idx ON public.radacct USING btree (acctstarttime, username);


--
-- Name: radcheck_username; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX radcheck_username ON public.radcheck USING btree (username, attribute);


--
-- Name: radgroupcheck_groupname; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX radgroupcheck_groupname ON public.radgroupcheck USING btree (groupname, attribute);


--
-- Name: radgroupreply_groupname; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX radgroupreply_groupname ON public.radgroupreply USING btree (groupname, attribute);


--
-- Name: radreply_username; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX radreply_username ON public.radreply USING btree (username, attribute);


--
-- Name: radusergroup_username; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX radusergroup_username ON public.radusergroup USING btree (username);


--
-- Name: TABLE nas; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT ON TABLE public.nas TO radius;


--
-- Name: SEQUENCE nas_id_seq; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,USAGE ON SEQUENCE public.nas_id_seq TO radius;


--
-- Name: TABLE radacct; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,INSERT,UPDATE ON TABLE public.radacct TO radius;


--
-- Name: SEQUENCE radacct_radacctid_seq; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,USAGE ON SEQUENCE public.radacct_radacctid_seq TO radius;


--
-- Name: TABLE radcheck; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT ON TABLE public.radcheck TO radius;


--
-- Name: SEQUENCE radcheck_id_seq; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,USAGE ON SEQUENCE public.radcheck_id_seq TO radius;


--
-- Name: TABLE radgroupcheck; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT ON TABLE public.radgroupcheck TO radius;


--
-- Name: SEQUENCE radgroupcheck_id_seq; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,USAGE ON SEQUENCE public.radgroupcheck_id_seq TO radius;


--
-- Name: TABLE radgroupreply; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT ON TABLE public.radgroupreply TO radius;


--
-- Name: SEQUENCE radgroupreply_id_seq; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,USAGE ON SEQUENCE public.radgroupreply_id_seq TO radius;


--
-- Name: TABLE radpostauth; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,INSERT,UPDATE ON TABLE public.radpostauth TO radius;


--
-- Name: SEQUENCE radpostauth_id_seq; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,USAGE ON SEQUENCE public.radpostauth_id_seq TO radius;


--
-- Name: TABLE radreply; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT ON TABLE public.radreply TO radius;


--
-- Name: SEQUENCE radreply_id_seq; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,USAGE ON SEQUENCE public.radreply_id_seq TO radius;


--
-- Name: TABLE radusergroup; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT ON TABLE public.radusergroup TO radius;


--
-- Name: SEQUENCE radusergroup_id_seq; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT,USAGE ON SEQUENCE public.radusergroup_id_seq TO radius;


--
--

