[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, |
---|
[2817] | 91 | FOREIGN KEY (userid) REFERENCES users(id), |
---|
| 92 | FOREIGN KEY (printerid) REFERENCES printers(id)) |
---|
| 93 | TYPE=INNODB; |
---|
[2638] | 94 | CREATE INDEX userpquota_u_id_ix ON userpquota (userid); |
---|
| 95 | CREATE INDEX userpquota_p_id_ix ON userpquota (printerid); |
---|
[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, |
---|
[2647] | 120 | jobdate TIMESTAMP DEFAULT now(), |
---|
| 121 | CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota (userid, printerid) |
---|
[2817] | 122 | ) TYPE=INNODB; |
---|
[2638] | 123 | CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid); |
---|
[1558] | 124 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
| 125 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
| 126 | CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); |
---|
| 127 | |
---|
| 128 | -- |
---|
| 129 | -- Create the print quota table for groups |
---|
| 130 | -- |
---|
[2694] | 131 | CREATE TABLE grouppquota(id INT8 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
[2638] | 132 | groupid INT4, |
---|
| 133 | printerid INT4, |
---|
[1558] | 134 | softlimit INT4, |
---|
| 135 | hardlimit INT4, |
---|
[2817] | 136 | maxjobsize INT4, |
---|
[2638] | 137 | datelimit TIMESTAMP, |
---|
[2817] | 138 | FOREIGN KEY (groupid) REFERENCES groups(id), |
---|
| 139 | FOREIGN KEY (printerid) REFERENCES printers(id)) |
---|
| 140 | TYPE=INNODB; |
---|
[2638] | 141 | CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid); |
---|
| 142 | CREATE INDEX grouppquota_p_id_ix ON grouppquota (printerid); |
---|
[1558] | 143 | CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); |
---|
| 144 | |
---|
| 145 | -- |
---|
| 146 | -- Create the groups/members relationship |
---|
| 147 | -- |
---|
[2638] | 148 | CREATE TABLE groupsmembers(groupid INT4, |
---|
| 149 | userid INT4, |
---|
[2817] | 150 | FOREIGN KEY (groupid) REFERENCES groups(id), |
---|
| 151 | FOREIGN KEY (userid) REFERENCES users(id), |
---|
[2638] | 152 | PRIMARY KEY (groupid, userid)) TYPE=INNODB; |
---|
[1558] | 153 | |
---|
| 154 | -- |
---|
| 155 | -- Create the printer groups relationship |
---|
| 156 | -- |
---|
[2638] | 157 | CREATE TABLE printergroupsmembers(groupid INT4, |
---|
| 158 | printerid INT4, |
---|
[2817] | 159 | FOREIGN KEY (groupid) REFERENCES groups(id), |
---|
| 160 | FOREIGN KEY (printerid) REFERENCES printers(id), |
---|
[2638] | 161 | PRIMARY KEY (groupid, printerid)) TYPE=INNODB; |
---|
[1558] | 162 | -- |
---|
| 163 | -- Create the table for payments |
---|
| 164 | -- |
---|
| 165 | CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
[2638] | 166 | userid INT4, |
---|
[1558] | 167 | amount FLOAT, |
---|
[2817] | 168 | description TEXT, |
---|
[2638] | 169 | date TIMESTAMP DEFAULT now(), |
---|
[2817] | 170 | FOREIGN KEY (userid) REFERENCES users(id)) TYPE=INNODB; |
---|
[1558] | 171 | CREATE INDEX payments_date_ix ON payments (date); |
---|
| 172 | |
---|
[2638] | 173 | -- |
---|
| 174 | -- Create the table for coefficients wrt paper sizes and the like |
---|
| 175 | -- |
---|
| 176 | CREATE TABLE coefficients (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
[2817] | 177 | printerid INT4 NOT NULL, |
---|
| 178 | label VARCHAR(255) NOT NULL, |
---|
| 179 | coefficient FLOAT DEFAULT 1.0, |
---|
| 180 | FOREIGN KEY (printerid) REFERENCES printers(id), |
---|
| 181 | CONSTRAINT coeffconstraint UNIQUE (printerid, label) |
---|
| 182 | ) TYPE=INNODB; |
---|
[2638] | 183 | |
---|
| 184 | -- |
---|
| 185 | -- Create the table for the billing codes |
---|
| 186 | -- |
---|
[2691] | 187 | CREATE TABLE billingcodes (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
[2638] | 188 | billingcode VARCHAR(255) UNIQUE NOT NULL, |
---|
| 189 | description TEXT, |
---|
| 190 | balance FLOAT DEFAULT 0.0, |
---|
| 191 | pagecounter INT4 DEFAULT 0) TYPE=INNODB; |
---|
[1558] | 192 | -- |
---|
| 193 | -- Set some ACLs |
---|
| 194 | -- |
---|
[2638] | 195 | GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'localhost'; |
---|
| 196 | GRANT SELECT ON `pykota`.* TO 'pykotauser'@'localhost'; |
---|