Updated queries and schema, based on a patch sent to the list.
[freeradius.git] / src / modules / rlm_sql / drivers / rlm_sql_postgresql / db_postgresql.sql
1 /*
2  * --- David Nicklay [ Wed Nov  3 23:18:46 EST 1999 ]
3  */
4
5 /*
6  * - Postgres wants C style comments.
7  * - not sure how to do sequences without using SERIAL
8  *   (i.e. these below are limited to int4 right now)
9  *   numeric(10) doesn't seem to work for sequences...
10  *   haven't tried int8 yet as a sequence type yet
11  * - datetimeOS DEFAULT '0000-00-00 00:00:00' should be
12  *   DEFAULT now() in postgres
13  * - postgres apparently creates an index for each
14  *   column specified as UNIQUE 
15  *   Consider implicit creation of <tablename_id_seq> for each SERIAL field!
16  */
17
18
19
20 /*
21  * Table structure for table 'dictionary'
22  */
23 CREATE TABLE dictionary (
24   id SERIAL,
25   Type VARCHAR(30),
26   Attribute VARCHAR(32),
27   Value VARCHAR(32),
28   Format VARCHAR(20),
29   Vendor VARCHAR(32),
30   PRIMARY KEY (id)
31 );
32
33 /*
34  * Table structure for table 'nas'
35  */
36 CREATE TABLE nas (
37   id SERIAL,
38   nasname VARCHAR(128),
39   shortname VARCHAR(32),
40   ipaddr VARCHAR(15),
41   type VARCHAR(30),
42   ports int4,
43   secret VARCHAR(60),
44   community VARCHAR(50),
45   snmp VARCHAR(10),
46   PRIMARY KEY (id)
47 );
48
49 /*
50  * Table structure for table 'radacct'
51  */
52 CREATE TABLE radacct (
53   RadAcctId SERIAL,
54   AcctSessionId VARCHAR(32) DEFAULT '' NOT NULL,
55   AcctUniqueId VARCHAR(32) DEFAULT '' NOT NULL,
56   UserName VARCHAR(32) DEFAULT '' NOT NULL,
57   Realm VARCHAR(30) DEFAULT '',
58   NASIPAddress VARCHAR(15) DEFAULT '' NOT NULL,
59   NASPortId NUMERIC(12),
60   NASPortType VARCHAR(32),
61   AcctStartTime datetime,
62   AcctStopTime datetime,
63   AcctSessionTime NUMERIC(12),
64   AcctAuthentic VARCHAR(32),
65   ConnectInfo_start VARCHAR(32),
66   ConnectInfo_stop VARCHAR(32),
67   AcctInputOctets NUMERIC(12),
68   AcctOutputOctets NUMERIC(12),
69   CalledStationId VARCHAR(10) DEFAULT '' NOT NULL,
70   CallingStationId VARCHAR(10) DEFAULT '' NOT NULL,
71   AcctTerminateCause VARCHAR(32) DEFAULT '' NOT NULL,
72   ServiceType VARCHAR(32),
73   FramedProtocol VARCHAR(32),
74   FramedIPAddress VARCHAR(15) DEFAULT '' NOT NULL,
75   AcctStartDelay NUMERIC(12),
76   AcctStopDelay NUMERIC(12),
77   PRIMARY KEY (RadAcctId)
78 );
79 create index radacct_UserName on radacct (UserName);
80 create index radacct_AcctSessionId on radacct (AcctSessionId);
81 create index radacct_AcctUniqueId on radacct (AcctUniqueId);
82 create index radacct_FramedIPAddress on radacct (FramedIPAddress);
83 create index radacct_NASIPAddress on radacct (NASIPAddress);
84 create index radacct_AcctStartTime on radacct (AcctStartTime);
85 create index radacct_AcctStopTime on radacct (AcctStopTime);
86
87 /*
88  * Table structure for table 'radcheck'
89  */
90 CREATE TABLE radcheck (
91   id SERIAL,
92   UserName VARCHAR(30) DEFAULT '' NOT NULL,
93   Attribute VARCHAR(30),
94   Value VARCHAR(40),
95   op VARCHAR(2),
96   PRIMARY KEY (id)
97 );
98 create index radcheck_UserName on radcheck (UserName,Attribute);
99
100 /*
101  * Table structure for table 'radgroupcheck'
102  */
103 CREATE TABLE radgroupcheck (
104   id SERIAL,
105   GroupName VARCHAR(20) DEFAULT '' NOT NULL,
106   Attribute VARCHAR(40),
107   Value VARCHAR(40),
108   op VARCHAR(2),
109   PRIMARY KEY (id)
110 );
111 create index radgroupcheck_GroupName on radgroupcheck (GroupName,Attribute);
112
113 /*
114  * Table structure for table 'radgroupreply'
115  */
116 CREATE TABLE radgroupreply (
117   id SERIAL,
118   GroupName VARCHAR(20) DEFAULT '' NOT NULL,
119   Attribute VARCHAR(40),
120   Value VARCHAR(40),
121   op VARCHAR(2),
122   PRIMARY KEY (id)
123 );
124 create index radgroupreply_GroupName on radgroupreply (GroupName,Attribute);
125
126 /*
127  * Table structure for table 'radreply'
128  */
129 CREATE TABLE radreply (
130   id SERIAL,
131   UserName VARCHAR(30) DEFAULT '' NOT NULL,
132   Attribute VARCHAR(30),
133   Value VARCHAR(40),
134   op VARCHAR(2),
135   PRIMARY KEY (id)
136 );
137 create index radreply_UserName on radreply (UserName,Attribute);
138
139 /*
140  * Table structure for table 'usergroup'
141  */
142 CREATE TABLE usergroup (
143   id SERIAL,
144   UserName VARCHAR(30) DEFAULT '' NOT NULL,
145   GroupName VARCHAR(30),
146   PRIMARY KEY (id)
147 );
148 create index usergroup_UserName on usergroup (UserName);
149
150 /*
151  * Table structure for table 'realmgroup'
152  */
153 CREATE TABLE realmgroup (
154   id SERIAL,
155   RealmName VARCHAR(30) DEFAULT '' NOT NULL,
156   GroupName VARCHAR(30),
157   PRIMARY KEY (id)
158 );
159 create index realmgroup_RealmName on realmgroup (RealmName);
160
161 CREATE TABLE realms (
162   id SERIAL,
163   realmname VARCHAR(64),
164   nas VARCHAR(128),
165   authport int4,
166   options VARCHAR(128) DEFAULT '',
167   PRIMARY KEY (id)
168 );
169
170