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