1 | -- |
---|
2 | -- PyKota - Print Quotas for CUPS and LPRng |
---|
3 | -- |
---|
4 | -- (c) 2003, 2004, 2005 Jerome Alet <alet@librelogiciel.com> |
---|
5 | -- This program is free software; you can redistribute it and/or modify |
---|
6 | -- it under the terms of the GNU General Public License as published by |
---|
7 | -- the Free Software Foundation; either version 2 of the License, or |
---|
8 | -- (at your option) any later version. |
---|
9 | -- |
---|
10 | -- This program is distributed in the hope that it will be useful, |
---|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | -- GNU General Public License for more details. |
---|
14 | -- |
---|
15 | -- You should have received a copy of the GNU General Public License |
---|
16 | -- along with this program; if not, write to the Free Software |
---|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
18 | -- |
---|
19 | -- $Id$ |
---|
20 | -- |
---|
21 | -- $Log$ |
---|
22 | -- Revision 1.15 2005/01/23 10:58:22 jalet |
---|
23 | -- Added a few indexes for the database |
---|
24 | -- |
---|
25 | -- Revision 1.14 2005/01/17 08:44:24 jalet |
---|
26 | -- Modified copyright years |
---|
27 | -- |
---|
28 | -- Revision 1.13 2005/01/10 23:23:25 jalet |
---|
29 | -- Added the billing code to the history |
---|
30 | -- |
---|
31 | -- Revision 1.12 2004/12/23 18:40:18 jalet |
---|
32 | -- Added the coefficient table, and many columns to existing tables |
---|
33 | -- |
---|
34 | -- Revision 1.11 2004/06/20 16:15:21 jalet |
---|
35 | -- Added "description" attribute for printers |
---|
36 | -- |
---|
37 | -- Revision 1.10 2004/06/03 23:14:09 jalet |
---|
38 | -- Now stores the job's size in bytes in the database. |
---|
39 | -- Preliminary work on payments storage : database schemas are OK now, |
---|
40 | -- but no code to store payments yet. |
---|
41 | -- Removed schema picture, not relevant anymore. |
---|
42 | -- |
---|
43 | -- Revision 1.9 2004/05/13 11:15:29 jalet |
---|
44 | -- Added hostname field in job history |
---|
45 | -- |
---|
46 | -- Revision 1.8 2004/01/08 14:10:32 jalet |
---|
47 | -- Copyright year changed. |
---|
48 | -- |
---|
49 | -- Revision 1.7 2003/12/27 16:49:25 uid67467 |
---|
50 | -- Should be ok now. |
---|
51 | -- |
---|
52 | -- Revision 1.6 2003/11/23 19:01:36 jalet |
---|
53 | -- Job price added to history |
---|
54 | -- |
---|
55 | -- Revision 1.5 2003/11/21 14:28:45 jalet |
---|
56 | -- More complete job history. |
---|
57 | -- |
---|
58 | -- Revision 1.4 2003/07/16 21:53:07 jalet |
---|
59 | -- Really big modifications wrt new configuration file's location and content. |
---|
60 | -- |
---|
61 | -- Revision 1.3 2003/07/09 20:17:07 jalet |
---|
62 | -- Email field added to PostgreSQL schema |
---|
63 | -- |
---|
64 | -- Revision 1.2 2003/06/10 16:37:54 jalet |
---|
65 | -- Deletion of the second user which is not needed anymore. |
---|
66 | -- Added a debug configuration field in /etc/pykota.conf |
---|
67 | -- All queries can now be sent to the logger in debug mode, this will |
---|
68 | -- greatly help improve performance when time for this will come. |
---|
69 | -- |
---|
70 | -- Revision 1.1 2003/06/05 07:12:31 jalet |
---|
71 | -- Reorganization of directories |
---|
72 | -- |
---|
73 | -- |
---|
74 | -- |
---|
75 | |
---|
76 | -- |
---|
77 | -- PyKota Database creation script for PostgreSQL |
---|
78 | -- |
---|
79 | -- Launch this as PostgreSQL administrator with \i |
---|
80 | -- |
---|
81 | |
---|
82 | |
---|
83 | -- |
---|
84 | -- Create the print quota database |
---|
85 | -- |
---|
86 | CREATE DATABASE pykota; |
---|
87 | |
---|
88 | -- |
---|
89 | -- Create the print quota database users |
---|
90 | -- |
---|
91 | CREATE USER pykotaadmin; |
---|
92 | CREATE USER pykotauser; |
---|
93 | |
---|
94 | -- |
---|
95 | -- Now connect to the new database |
---|
96 | -- |
---|
97 | \connect pykota |
---|
98 | |
---|
99 | -- |
---|
100 | -- Create the users table |
---|
101 | -- |
---|
102 | CREATE TABLE users(id SERIAL PRIMARY KEY NOT NULL, |
---|
103 | username TEXT UNIQUE NOT NULL, |
---|
104 | email TEXT, |
---|
105 | balance FLOAT DEFAULT 0.0, |
---|
106 | lifetimepaid FLOAT DEFAULT 0.0, |
---|
107 | limitby TEXT DEFAULT 'quota', |
---|
108 | coefficient FLOAT NOT NULL DEFAULT 1.0); |
---|
109 | |
---|
110 | -- |
---|
111 | -- Create the groups table |
---|
112 | -- |
---|
113 | CREATE TABLE groups(id SERIAL PRIMARY KEY NOT NULL, |
---|
114 | groupname TEXT UNIQUE NOT NULL, |
---|
115 | limitby TEXT DEFAULT 'quota'); |
---|
116 | |
---|
117 | -- |
---|
118 | -- Create the printers table |
---|
119 | -- |
---|
120 | CREATE TABLE printers(id SERIAL PRIMARY KEY NOT NULL, |
---|
121 | printername TEXT UNIQUE NOT NULL, |
---|
122 | description TEXT, |
---|
123 | priceperpage FLOAT DEFAULT 0.0, |
---|
124 | priceperjob FLOAT DEFAULT 0.0); |
---|
125 | |
---|
126 | -- |
---|
127 | -- Create the print quota table for users |
---|
128 | -- |
---|
129 | CREATE TABLE userpquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
130 | userid INT4 REFERENCES users(id), |
---|
131 | printerid INT4 REFERENCES printers(id), |
---|
132 | lifepagecounter INT4 DEFAULT 0, |
---|
133 | pagecounter INT4 DEFAULT 0, |
---|
134 | softlimit INT4, |
---|
135 | hardlimit INT4, |
---|
136 | datelimit TIMESTAMP, |
---|
137 | warned INT4 DEFAULT 0); -- not a boolean, will help stats |
---|
138 | CREATE INDEX userpquota_u_id_ix ON userpquota (userid); |
---|
139 | CREATE INDEX userpquota_p_id_ix ON userpquota (printerid); |
---|
140 | CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); |
---|
141 | |
---|
142 | -- |
---|
143 | -- Create the job history table |
---|
144 | -- |
---|
145 | CREATE TABLE jobhistory(id SERIAL PRIMARY KEY NOT NULL, |
---|
146 | jobid TEXT, |
---|
147 | userid INT4, |
---|
148 | printerid INT4, |
---|
149 | pagecounter INT4 DEFAULT 0, |
---|
150 | jobsizebytes INT8, |
---|
151 | jobsize INT4, |
---|
152 | jobprice FLOAT, |
---|
153 | action TEXT, |
---|
154 | filename TEXT, |
---|
155 | title TEXT, |
---|
156 | copies INT4, |
---|
157 | options TEXT, |
---|
158 | hostname TEXT, |
---|
159 | md5sum TEXT, |
---|
160 | pages TEXT, |
---|
161 | billingcode TEXT, |
---|
162 | jobdate TIMESTAMP DEFAULT now(), |
---|
163 | CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota(userid, printerid)); |
---|
164 | CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid); |
---|
165 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
166 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
167 | CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); |
---|
168 | |
---|
169 | -- |
---|
170 | -- Create the print quota table for groups |
---|
171 | -- |
---|
172 | CREATE TABLE grouppquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
173 | groupid INT4 REFERENCES groups(id), |
---|
174 | printerid INT4 REFERENCES printers(id), |
---|
175 | softlimit INT4, |
---|
176 | hardlimit INT4, |
---|
177 | datelimit TIMESTAMP); |
---|
178 | CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); |
---|
179 | |
---|
180 | -- |
---|
181 | -- Create the groups/members relationship |
---|
182 | -- |
---|
183 | CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id), |
---|
184 | userid INT4 REFERENCES users(id), |
---|
185 | PRIMARY KEY (groupid, userid)); |
---|
186 | |
---|
187 | -- |
---|
188 | -- Create the printer groups relationship |
---|
189 | -- |
---|
190 | CREATE TABLE printergroupsmembers(groupid INT4 REFERENCES printers(id), |
---|
191 | printerid INT4 REFERENCES printers(id), |
---|
192 | PRIMARY KEY (groupid, printerid)); |
---|
193 | -- |
---|
194 | -- Create the table for payments |
---|
195 | -- |
---|
196 | CREATE TABLE payments (id SERIAL PRIMARY KEY NOT NULL, |
---|
197 | userid INT4 REFERENCES users(id), |
---|
198 | amount FLOAT, |
---|
199 | date TIMESTAMP DEFAULT now()); |
---|
200 | CREATE INDEX payments_date_ix ON payments (date); |
---|
201 | |
---|
202 | -- |
---|
203 | -- Create the table for coefficients wrt paper sizes and the like |
---|
204 | -- |
---|
205 | CREATE TABLE coefficients (id SERIAL PRIMARY KEY NOT NULL, |
---|
206 | printerid INTEGER NOT NULL REFERENCES printers(id), |
---|
207 | label TEXT NOT NULL, |
---|
208 | coefficient FLOAT NOT NULL DEFAULT 1.0, |
---|
209 | CONSTRAINT coeffconstraint UNIQUE (printerid, label)); |
---|
210 | |
---|
211 | -- |
---|
212 | -- Set some ACLs |
---|
213 | -- |
---|
214 | REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments FROM public; |
---|
215 | REVOKE ALL ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq, payments_id_seq FROM public; |
---|
216 | |
---|
217 | GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients TO pykotaadmin; |
---|
218 | GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq, payments_id_seq, coefficients_id_seq TO pykotaadmin; |
---|
219 | GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients TO pykotauser; |
---|