[1015] | 1 | -- |
---|
| 2 | -- PyKota - Print Quotas for CUPS and LPRng |
---|
| 3 | -- |
---|
| 4 | -- (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
| 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$ |
---|
[1200] | 22 | -- Revision 1.5 2003/11/21 14:28:45 jalet |
---|
| 23 | -- More complete job history. |
---|
| 24 | -- |
---|
[1087] | 25 | -- Revision 1.4 2003/07/16 21:53:07 jalet |
---|
| 26 | -- Really big modifications wrt new configuration file's location and content. |
---|
| 27 | -- |
---|
[1079] | 28 | -- Revision 1.3 2003/07/09 20:17:07 jalet |
---|
| 29 | -- Email field added to PostgreSQL schema |
---|
| 30 | -- |
---|
[1021] | 31 | -- Revision 1.2 2003/06/10 16:37:54 jalet |
---|
| 32 | -- Deletion of the second user which is not needed anymore. |
---|
| 33 | -- Added a debug configuration field in /etc/pykota.conf |
---|
| 34 | -- All queries can now be sent to the logger in debug mode, this will |
---|
| 35 | -- greatly help improve performance when time for this will come. |
---|
| 36 | -- |
---|
[1015] | 37 | -- Revision 1.1 2003/06/05 07:12:31 jalet |
---|
| 38 | -- Reorganization of directories |
---|
| 39 | -- |
---|
| 40 | -- |
---|
| 41 | -- |
---|
| 42 | |
---|
| 43 | -- |
---|
| 44 | -- PyKota Database creation script for PostgreSQL |
---|
| 45 | -- |
---|
| 46 | -- Launch this as PostgreSQL administrator with \i |
---|
| 47 | -- |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | -- |
---|
| 51 | -- Create the print quota database |
---|
| 52 | -- |
---|
| 53 | CREATE DATABASE pykota; |
---|
| 54 | |
---|
| 55 | -- |
---|
| 56 | -- Create the print quota database users |
---|
| 57 | -- |
---|
| 58 | CREATE USER pykotaadmin; |
---|
[1087] | 59 | CREATE USER pykotauser; |
---|
[1015] | 60 | |
---|
| 61 | -- |
---|
| 62 | -- Now connect to the new database |
---|
| 63 | -- |
---|
| 64 | \connect pykota |
---|
| 65 | |
---|
| 66 | -- |
---|
| 67 | -- Create the users table |
---|
| 68 | -- |
---|
| 69 | CREATE TABLE users(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 70 | username TEXT UNIQUE NOT NULL, |
---|
[1079] | 71 | email TEXT, |
---|
[1015] | 72 | balance FLOAT DEFAULT 0.0, |
---|
| 73 | lifetimepaid FLOAT DEFAULT 0.0, |
---|
| 74 | limitby TEXT DEFAULT 'quota'); |
---|
| 75 | |
---|
| 76 | -- |
---|
| 77 | -- Create the groups table |
---|
| 78 | -- |
---|
| 79 | CREATE TABLE groups(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 80 | groupname TEXT UNIQUE NOT NULL, |
---|
| 81 | limitby TEXT DEFAULT 'quota'); |
---|
| 82 | |
---|
| 83 | -- |
---|
| 84 | -- Create the printers table |
---|
| 85 | -- |
---|
| 86 | CREATE TABLE printers(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 87 | printername TEXT UNIQUE NOT NULL, |
---|
| 88 | priceperpage FLOAT DEFAULT 0.0, |
---|
| 89 | priceperjob FLOAT DEFAULT 0.0); |
---|
| 90 | |
---|
| 91 | -- |
---|
| 92 | -- Create the print quota table for users |
---|
| 93 | -- |
---|
| 94 | CREATE TABLE userpquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 95 | userid INT4 REFERENCES users(id), |
---|
| 96 | printerid INT4 REFERENCES printers(id), |
---|
| 97 | lifepagecounter INT4 DEFAULT 0, |
---|
| 98 | pagecounter INT4 DEFAULT 0, |
---|
| 99 | softlimit INT4, |
---|
| 100 | hardlimit INT4, |
---|
| 101 | datelimit TIMESTAMP); |
---|
[1200] | 102 | CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); |
---|
[1015] | 103 | |
---|
| 104 | -- |
---|
| 105 | -- Create the job history table |
---|
| 106 | -- |
---|
| 107 | CREATE TABLE jobhistory(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 108 | jobid TEXT, |
---|
| 109 | userid INT4 REFERENCES users(id), |
---|
| 110 | printerid INT4 REFERENCES printers(id), |
---|
| 111 | pagecounter INT4 DEFAULT 0, |
---|
| 112 | jobsize INT4, |
---|
| 113 | action TEXT, |
---|
[1200] | 114 | filename TEXT, |
---|
| 115 | title TEXT, |
---|
| 116 | copies INT4, |
---|
| 117 | options TEXT, |
---|
[1015] | 118 | jobdate TIMESTAMP DEFAULT now()); |
---|
[1200] | 119 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
| 120 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
[1015] | 121 | |
---|
| 122 | -- |
---|
| 123 | -- Create the print quota table for groups |
---|
| 124 | -- |
---|
| 125 | CREATE TABLE grouppquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 126 | groupid INT4 REFERENCES groups(id), |
---|
| 127 | printerid INT4 REFERENCES printers(id), |
---|
| 128 | softlimit INT4, |
---|
| 129 | hardlimit INT4, |
---|
| 130 | datelimit TIMESTAMP); |
---|
[1200] | 131 | CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); |
---|
[1015] | 132 | |
---|
| 133 | -- |
---|
| 134 | -- Create the groups/members relationship |
---|
| 135 | -- |
---|
| 136 | CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id), |
---|
| 137 | userid INT4 REFERENCES users(id), |
---|
| 138 | PRIMARY KEY (groupid, userid)); |
---|
| 139 | |
---|
| 140 | -- |
---|
| 141 | -- Set some ACLs |
---|
| 142 | -- |
---|
| 143 | REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory FROM public; |
---|
[1087] | 144 | REVOKE ALL ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq FROM public; |
---|
| 145 | |
---|
[1015] | 146 | GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory TO pykotaadmin; |
---|
| 147 | GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq TO pykotaadmin; |
---|
[1087] | 148 | GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory TO pykotauser; |
---|