1 | -- |
---|
2 | -- PyKota - Print Quotas for CUPS and LPRng |
---|
3 | -- |
---|
4 | -- (c) 2003, 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
18 | -- |
---|
19 | -- $Id$ |
---|
20 | -- |
---|
21 | -- |
---|
22 | |
---|
23 | -- |
---|
24 | -- PyKota Database creation script for MySQL |
---|
25 | -- |
---|
26 | -- Launch this as MySQL administrator with \. |
---|
27 | -- |
---|
28 | |
---|
29 | |
---|
30 | -- |
---|
31 | -- Create the print quota database |
---|
32 | -- |
---|
33 | CREATE DATABASE pykota; |
---|
34 | |
---|
35 | -- |
---|
36 | -- Create the print quota database users |
---|
37 | -- NOTE: Change the "IDENTIFIED BY" strings to the passwords you would like. |
---|
38 | -- |
---|
39 | GRANT USAGE ON *.* TO 'pykotauser'@'localhost' IDENTIFIED BY 'readonlypw'; |
---|
40 | GRANT USAGE ON *.* TO 'pykotaadmin'@'localhost' IDENTIFIED BY 'readwritepw'; |
---|
41 | |
---|
42 | -- |
---|
43 | -- If necessary activate the lines below (and keep the preceding ones |
---|
44 | -- activated at the same time) |
---|
45 | -- |
---|
46 | -- GRANT USAGE ON *.* TO 'pykotauser'@'%' IDENTIFIED BY 'readonlypw'; |
---|
47 | -- GRANT USAGE ON *.* TO 'pykotaadmin'@'%' IDENTIFIED BY 'readwritepw'; |
---|
48 | |
---|
49 | -- |
---|
50 | -- Now connect to the new database |
---|
51 | -- |
---|
52 | USE pykota; |
---|
53 | |
---|
54 | -- |
---|
55 | -- Create the users table |
---|
56 | -- |
---|
57 | CREATE TABLE users (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
58 | username VARCHAR(255) UNIQUE NOT NULL, |
---|
59 | email TEXT, |
---|
60 | balance FLOAT DEFAULT 0.0, |
---|
61 | lifetimepaid FLOAT DEFAULT 0.0, |
---|
62 | limitby VARCHAR(30) DEFAULT 'quota', |
---|
63 | description TEXT, |
---|
64 | overcharge FLOAT NOT NULL DEFAULT 1.0) TYPE=INNODB; |
---|
65 | |
---|
66 | -- |
---|
67 | -- Create the groups table |
---|
68 | -- |
---|
69 | CREATE TABLE groups (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
70 | groupname VARCHAR(255) UNIQUE NOT NULL, |
---|
71 | description TEXT, |
---|
72 | limitby VARCHAR(30) DEFAULT 'quota') TYPE=INNODB; |
---|
73 | |
---|
74 | -- |
---|
75 | -- Create the printers table |
---|
76 | -- |
---|
77 | CREATE TABLE printers (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
78 | printername VARCHAR(255) UNIQUE NOT NULL, |
---|
79 | description TEXT, |
---|
80 | priceperpage FLOAT DEFAULT 0.0, |
---|
81 | priceperjob FLOAT DEFAULT 0.0, |
---|
82 | passthrough ENUM('t','f') DEFAULT 'f', |
---|
83 | maxjobsize INT4) TYPE=INNODB; |
---|
84 | |
---|
85 | -- |
---|
86 | -- Create the print quota table for users |
---|
87 | -- |
---|
88 | CREATE TABLE userpquota (id INT8 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
89 | userid INT4, |
---|
90 | printerid INT4, |
---|
91 | lifepagecounter INT4 DEFAULT 0, |
---|
92 | pagecounter INT4 DEFAULT 0, |
---|
93 | softlimit INT4, |
---|
94 | hardlimit INT4, |
---|
95 | datelimit DATETIME, |
---|
96 | maxjobsize INT4, |
---|
97 | warncount INT4 DEFAULT 0, |
---|
98 | INDEX (userid), |
---|
99 | FOREIGN KEY (userid) REFERENCES users(id), |
---|
100 | INDEX (printerid), |
---|
101 | FOREIGN KEY (printerid) REFERENCES printers(id)) |
---|
102 | TYPE=INNODB; |
---|
103 | CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); |
---|
104 | |
---|
105 | -- |
---|
106 | -- Create the job history table |
---|
107 | -- |
---|
108 | CREATE TABLE jobhistory(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
109 | jobid TEXT, |
---|
110 | userid INT4, |
---|
111 | printerid INT4, |
---|
112 | pagecounter INT4 DEFAULT 0, |
---|
113 | jobsizebytes INT8, |
---|
114 | jobsize INT4, |
---|
115 | jobprice FLOAT, |
---|
116 | action TEXT, |
---|
117 | filename TEXT, |
---|
118 | title TEXT, |
---|
119 | copies INT4, |
---|
120 | options TEXT, |
---|
121 | hostname VARCHAR(255), |
---|
122 | md5sum TEXT, |
---|
123 | pages TEXT, |
---|
124 | billingcode TEXT, |
---|
125 | precomputedjobsize INT4, |
---|
126 | precomputedjobprice FLOAT, |
---|
127 | jobdate TIMESTAMP, |
---|
128 | INDEX (userid, printerid), |
---|
129 | CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota (userid, printerid) |
---|
130 | ) TYPE=INNODB; |
---|
131 | CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid); |
---|
132 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
133 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
134 | CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); |
---|
135 | |
---|
136 | -- |
---|
137 | -- Create the print quota table for groups |
---|
138 | -- |
---|
139 | CREATE TABLE grouppquota(id INT8 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
140 | groupid INT4, |
---|
141 | printerid INT4, |
---|
142 | softlimit INT4, |
---|
143 | hardlimit INT4, |
---|
144 | maxjobsize INT4, |
---|
145 | datelimit DATETIME, |
---|
146 | INDEX (groupid), |
---|
147 | FOREIGN KEY (groupid) REFERENCES groups(id), |
---|
148 | INDEX (printerid), |
---|
149 | FOREIGN KEY (printerid) REFERENCES printers(id)) |
---|
150 | TYPE=INNODB; |
---|
151 | CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); |
---|
152 | |
---|
153 | -- |
---|
154 | -- Create the groups/members relationship |
---|
155 | -- |
---|
156 | CREATE TABLE groupsmembers(groupid INT4 NOT NULL, |
---|
157 | userid INT4 NOT NULL, |
---|
158 | INDEX (groupid), |
---|
159 | FOREIGN KEY (groupid) REFERENCES groups(id), |
---|
160 | INDEX (userid), |
---|
161 | FOREIGN KEY (userid) REFERENCES users(id), |
---|
162 | PRIMARY KEY (groupid, userid)) TYPE=INNODB; |
---|
163 | |
---|
164 | -- |
---|
165 | -- Create the printer groups relationship |
---|
166 | -- |
---|
167 | CREATE TABLE printergroupsmembers(groupid INT4 NOT NULL, |
---|
168 | printerid INT4 NOT NULL, |
---|
169 | INDEX (groupid), |
---|
170 | FOREIGN KEY (groupid) REFERENCES groups(id), |
---|
171 | INDEX (printerid), |
---|
172 | FOREIGN KEY (printerid) REFERENCES printers(id), |
---|
173 | PRIMARY KEY (groupid, printerid)) TYPE=INNODB; |
---|
174 | -- |
---|
175 | -- Create the table for payments |
---|
176 | -- |
---|
177 | CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
178 | userid INT4, |
---|
179 | amount FLOAT, |
---|
180 | description TEXT, |
---|
181 | date TIMESTAMP, |
---|
182 | INDEX (userid), |
---|
183 | FOREIGN KEY (userid) REFERENCES users(id)) TYPE=INNODB; |
---|
184 | CREATE INDEX payments_date_ix ON payments (date); |
---|
185 | |
---|
186 | -- |
---|
187 | -- Create the table for coefficients wrt paper sizes and the like |
---|
188 | -- |
---|
189 | CREATE TABLE coefficients (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
190 | printerid INT4 NOT NULL, |
---|
191 | label VARCHAR(255) NOT NULL, |
---|
192 | coefficient FLOAT DEFAULT 1.0, |
---|
193 | INDEX (printerid), |
---|
194 | FOREIGN KEY (printerid) REFERENCES printers(id), |
---|
195 | CONSTRAINT coeffconstraint UNIQUE (printerid, label) |
---|
196 | ) TYPE=INNODB; |
---|
197 | |
---|
198 | -- |
---|
199 | -- Create the table for the billing codes |
---|
200 | -- |
---|
201 | CREATE TABLE billingcodes (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
202 | billingcode VARCHAR(255) UNIQUE NOT NULL, |
---|
203 | description TEXT, |
---|
204 | balance FLOAT DEFAULT 0.0, |
---|
205 | pagecounter INT4 DEFAULT 0) TYPE=INNODB; |
---|
206 | -- |
---|
207 | -- Set some ACLs |
---|
208 | -- |
---|
209 | GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'localhost'; |
---|
210 | GRANT SELECT ON `pykota`.* TO 'pykotauser'@'localhost'; |
---|
211 | |
---|
212 | -- |
---|
213 | -- If necessary activate the lines below (and keep the preceding ones |
---|
214 | -- activated at the same time) |
---|
215 | -- |
---|
216 | -- GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'%'; |
---|
217 | -- GRANT SELECT ON `pykota`.* TO 'pykotauser'@'%'; |
---|