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