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