[1015] | 1 | -- |
---|
| 2 | -- PyKota - Print Quotas for CUPS and LPRng |
---|
| 3 | -- |
---|
[1257] | 4 | -- (c) 2003-2004 Jerome Alet <alet@librelogiciel.com> |
---|
[1015] | 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$ |
---|
[1994] | 22 | -- Revision 1.12 2004/12/23 18:40:18 jalet |
---|
| 23 | -- Added the coefficient table, and many columns to existing tables |
---|
| 24 | -- |
---|
[1556] | 25 | -- Revision 1.11 2004/06/20 16:15:21 jalet |
---|
| 26 | -- Added "description" attribute for printers |
---|
| 27 | -- |
---|
[1520] | 28 | -- Revision 1.10 2004/06/03 23:14:09 jalet |
---|
| 29 | -- Now stores the job's size in bytes in the database. |
---|
| 30 | -- Preliminary work on payments storage : database schemas are OK now, |
---|
| 31 | -- but no code to store payments yet. |
---|
| 32 | -- Removed schema picture, not relevant anymore. |
---|
| 33 | -- |
---|
[1473] | 34 | -- Revision 1.9 2004/05/13 11:15:29 jalet |
---|
| 35 | -- Added hostname field in job history |
---|
| 36 | -- |
---|
[1257] | 37 | -- Revision 1.8 2004/01/08 14:10:32 jalet |
---|
| 38 | -- Copyright year changed. |
---|
| 39 | -- |
---|
[1240] | 40 | -- Revision 1.7 2003/12/27 16:49:25 uid67467 |
---|
| 41 | -- Should be ok now. |
---|
| 42 | -- |
---|
[1203] | 43 | -- Revision 1.6 2003/11/23 19:01:36 jalet |
---|
| 44 | -- Job price added to history |
---|
| 45 | -- |
---|
[1200] | 46 | -- Revision 1.5 2003/11/21 14:28:45 jalet |
---|
| 47 | -- More complete job history. |
---|
| 48 | -- |
---|
[1087] | 49 | -- Revision 1.4 2003/07/16 21:53:07 jalet |
---|
| 50 | -- Really big modifications wrt new configuration file's location and content. |
---|
| 51 | -- |
---|
[1079] | 52 | -- Revision 1.3 2003/07/09 20:17:07 jalet |
---|
| 53 | -- Email field added to PostgreSQL schema |
---|
| 54 | -- |
---|
[1021] | 55 | -- Revision 1.2 2003/06/10 16:37:54 jalet |
---|
| 56 | -- Deletion of the second user which is not needed anymore. |
---|
| 57 | -- Added a debug configuration field in /etc/pykota.conf |
---|
| 58 | -- All queries can now be sent to the logger in debug mode, this will |
---|
| 59 | -- greatly help improve performance when time for this will come. |
---|
| 60 | -- |
---|
[1015] | 61 | -- Revision 1.1 2003/06/05 07:12:31 jalet |
---|
| 62 | -- Reorganization of directories |
---|
| 63 | -- |
---|
| 64 | -- |
---|
| 65 | -- |
---|
| 66 | |
---|
| 67 | -- |
---|
| 68 | -- PyKota Database creation script for PostgreSQL |
---|
| 69 | -- |
---|
| 70 | -- Launch this as PostgreSQL administrator with \i |
---|
| 71 | -- |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | -- |
---|
| 75 | -- Create the print quota database |
---|
| 76 | -- |
---|
| 77 | CREATE DATABASE pykota; |
---|
| 78 | |
---|
| 79 | -- |
---|
| 80 | -- Create the print quota database users |
---|
| 81 | -- |
---|
| 82 | CREATE USER pykotaadmin; |
---|
[1087] | 83 | CREATE USER pykotauser; |
---|
[1015] | 84 | |
---|
| 85 | -- |
---|
| 86 | -- Now connect to the new database |
---|
| 87 | -- |
---|
| 88 | \connect pykota |
---|
| 89 | |
---|
| 90 | -- |
---|
| 91 | -- Create the users table |
---|
| 92 | -- |
---|
| 93 | CREATE TABLE users(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 94 | username TEXT UNIQUE NOT NULL, |
---|
[1079] | 95 | email TEXT, |
---|
[1015] | 96 | balance FLOAT DEFAULT 0.0, |
---|
| 97 | lifetimepaid FLOAT DEFAULT 0.0, |
---|
[1994] | 98 | limitby TEXT DEFAULT 'quota', |
---|
| 99 | coefficient FLOAT NOT NULL DEFAULT 1.0); |
---|
[1015] | 100 | |
---|
| 101 | -- |
---|
| 102 | -- Create the groups table |
---|
| 103 | -- |
---|
| 104 | CREATE TABLE groups(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 105 | groupname TEXT UNIQUE NOT NULL, |
---|
| 106 | limitby TEXT DEFAULT 'quota'); |
---|
| 107 | |
---|
| 108 | -- |
---|
| 109 | -- Create the printers table |
---|
| 110 | -- |
---|
| 111 | CREATE TABLE printers(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 112 | printername TEXT UNIQUE NOT NULL, |
---|
[1556] | 113 | description TEXT, |
---|
[1015] | 114 | priceperpage FLOAT DEFAULT 0.0, |
---|
| 115 | priceperjob FLOAT DEFAULT 0.0); |
---|
| 116 | |
---|
| 117 | -- |
---|
| 118 | -- Create the print quota table for users |
---|
| 119 | -- |
---|
| 120 | CREATE TABLE userpquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 121 | userid INT4 REFERENCES users(id), |
---|
| 122 | printerid INT4 REFERENCES printers(id), |
---|
| 123 | lifepagecounter INT4 DEFAULT 0, |
---|
| 124 | pagecounter INT4 DEFAULT 0, |
---|
| 125 | softlimit INT4, |
---|
| 126 | hardlimit INT4, |
---|
[1994] | 127 | datelimit TIMESTAMP, |
---|
| 128 | warned INT4 DEFAULT 0); -- not a boolean, will help stats |
---|
[1200] | 129 | CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); |
---|
[1015] | 130 | |
---|
| 131 | -- |
---|
| 132 | -- Create the job history table |
---|
| 133 | -- |
---|
| 134 | CREATE TABLE jobhistory(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 135 | jobid TEXT, |
---|
[1240] | 136 | userid INT4, |
---|
| 137 | printerid INT4, |
---|
[1015] | 138 | pagecounter INT4 DEFAULT 0, |
---|
[1520] | 139 | jobsizebytes INT8, |
---|
[1015] | 140 | jobsize INT4, |
---|
[1203] | 141 | jobprice FLOAT, |
---|
[1015] | 142 | action TEXT, |
---|
[1200] | 143 | filename TEXT, |
---|
| 144 | title TEXT, |
---|
| 145 | copies INT4, |
---|
| 146 | options TEXT, |
---|
[1520] | 147 | hostname TEXT, |
---|
[1994] | 148 | md5sum TEXT, |
---|
| 149 | pages TEXT, |
---|
[1240] | 150 | jobdate TIMESTAMP DEFAULT now(), |
---|
| 151 | CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota(userid, printerid)); |
---|
[1200] | 152 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
| 153 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
[1520] | 154 | CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); |
---|
[1015] | 155 | |
---|
| 156 | -- |
---|
| 157 | -- Create the print quota table for groups |
---|
| 158 | -- |
---|
| 159 | CREATE TABLE grouppquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 160 | groupid INT4 REFERENCES groups(id), |
---|
| 161 | printerid INT4 REFERENCES printers(id), |
---|
| 162 | softlimit INT4, |
---|
| 163 | hardlimit INT4, |
---|
| 164 | datelimit TIMESTAMP); |
---|
[1200] | 165 | CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); |
---|
[1015] | 166 | |
---|
| 167 | -- |
---|
| 168 | -- Create the groups/members relationship |
---|
| 169 | -- |
---|
| 170 | CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id), |
---|
| 171 | userid INT4 REFERENCES users(id), |
---|
| 172 | PRIMARY KEY (groupid, userid)); |
---|
[1240] | 173 | |
---|
| 174 | -- |
---|
| 175 | -- Create the printer groups relationship |
---|
| 176 | -- |
---|
| 177 | CREATE TABLE printergroupsmembers(groupid INT4 REFERENCES printers(id), |
---|
| 178 | printerid INT4 REFERENCES printers(id), |
---|
| 179 | PRIMARY KEY (groupid, printerid)); |
---|
[1520] | 180 | -- |
---|
| 181 | -- Create the table for payments |
---|
| 182 | -- |
---|
| 183 | CREATE TABLE payments (id SERIAL PRIMARY KEY NOT NULL, |
---|
| 184 | userid INT4 REFERENCES users(id), |
---|
| 185 | amount FLOAT, |
---|
| 186 | date TIMESTAMP DEFAULT now()); |
---|
| 187 | CREATE INDEX payments_date_ix ON payments (date); |
---|
[1015] | 188 | |
---|
[1994] | 189 | -- |
---|
| 190 | -- Create the table for coefficients wrt paper sizes and the like |
---|
| 191 | -- |
---|
| 192 | CREATE TABLE coefficients (id SERIAL PRIMARY KEY NOT NULL, |
---|
| 193 | printerid INTEGER NOT NULL REFERENCES printers(id), |
---|
| 194 | label TEXT NOT NULL, |
---|
| 195 | coefficient FLOAT NOT NULL DEFAULT 1.0, |
---|
| 196 | CONSTRAINT coeffconstraint UNIQUE (printerid, label)); |
---|
| 197 | |
---|
[1015] | 198 | -- |
---|
| 199 | -- Set some ACLs |
---|
| 200 | -- |
---|
[1520] | 201 | REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments FROM public; |
---|
| 202 | 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; |
---|
[1087] | 203 | |
---|
[1994] | 204 | GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients TO pykotaadmin; |
---|
| 205 | 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; |
---|
| 206 | GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients TO pykotauser; |
---|