[1015] | 1 | -- |
---|
| 2 | -- PyKota - Print Quotas for CUPS and LPRng |
---|
| 3 | -- |
---|
[2028] | 4 | -- (c) 2003, 2004, 2005 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 | -- |
---|
[2054] | 21 | -- |
---|
[1015] | 22 | |
---|
| 23 | -- |
---|
| 24 | -- PyKota Database creation script for PostgreSQL |
---|
| 25 | -- |
---|
| 26 | -- Launch this as PostgreSQL administrator with \i |
---|
| 27 | -- |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | -- |
---|
| 31 | -- Create the print quota database |
---|
| 32 | -- |
---|
| 33 | CREATE DATABASE pykota; |
---|
| 34 | |
---|
| 35 | -- |
---|
| 36 | -- Create the print quota database users |
---|
| 37 | -- |
---|
| 38 | CREATE USER pykotaadmin; |
---|
[1087] | 39 | CREATE USER pykotauser; |
---|
[1015] | 40 | |
---|
| 41 | -- |
---|
| 42 | -- Now connect to the new database |
---|
| 43 | -- |
---|
| 44 | \connect pykota |
---|
| 45 | |
---|
| 46 | -- |
---|
| 47 | -- Create the users table |
---|
| 48 | -- |
---|
| 49 | CREATE TABLE users(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 50 | username TEXT UNIQUE NOT NULL, |
---|
[1079] | 51 | email TEXT, |
---|
[1015] | 52 | balance FLOAT DEFAULT 0.0, |
---|
| 53 | lifetimepaid FLOAT DEFAULT 0.0, |
---|
[1994] | 54 | limitby TEXT DEFAULT 'quota', |
---|
[2054] | 55 | overcharge FLOAT NOT NULL DEFAULT 1.0); |
---|
[1015] | 56 | |
---|
| 57 | -- |
---|
| 58 | -- Create the groups table |
---|
| 59 | -- |
---|
| 60 | CREATE TABLE groups(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 61 | groupname TEXT UNIQUE NOT NULL, |
---|
| 62 | limitby TEXT DEFAULT 'quota'); |
---|
| 63 | |
---|
| 64 | -- |
---|
| 65 | -- Create the printers table |
---|
| 66 | -- |
---|
| 67 | CREATE TABLE printers(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 68 | printername TEXT UNIQUE NOT NULL, |
---|
[1556] | 69 | description TEXT, |
---|
[1015] | 70 | priceperpage FLOAT DEFAULT 0.0, |
---|
| 71 | priceperjob FLOAT DEFAULT 0.0); |
---|
| 72 | |
---|
| 73 | -- |
---|
| 74 | -- Create the print quota table for users |
---|
| 75 | -- |
---|
| 76 | CREATE TABLE userpquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 77 | userid INT4 REFERENCES users(id), |
---|
| 78 | printerid INT4 REFERENCES printers(id), |
---|
| 79 | lifepagecounter INT4 DEFAULT 0, |
---|
| 80 | pagecounter INT4 DEFAULT 0, |
---|
| 81 | softlimit INT4, |
---|
| 82 | hardlimit INT4, |
---|
[1994] | 83 | datelimit TIMESTAMP, |
---|
[2054] | 84 | warncount INT4 DEFAULT 0); |
---|
[2037] | 85 | CREATE INDEX userpquota_u_id_ix ON userpquota (userid); |
---|
| 86 | CREATE INDEX userpquota_p_id_ix ON userpquota (printerid); |
---|
[1200] | 87 | CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); |
---|
[1015] | 88 | |
---|
| 89 | -- |
---|
| 90 | -- Create the job history table |
---|
| 91 | -- |
---|
| 92 | CREATE TABLE jobhistory(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 93 | jobid TEXT, |
---|
[1240] | 94 | userid INT4, |
---|
| 95 | printerid INT4, |
---|
[1015] | 96 | pagecounter INT4 DEFAULT 0, |
---|
[1520] | 97 | jobsizebytes INT8, |
---|
[1015] | 98 | jobsize INT4, |
---|
[1203] | 99 | jobprice FLOAT, |
---|
[1015] | 100 | action TEXT, |
---|
[1200] | 101 | filename TEXT, |
---|
| 102 | title TEXT, |
---|
| 103 | copies INT4, |
---|
| 104 | options TEXT, |
---|
[1520] | 105 | hostname TEXT, |
---|
[1994] | 106 | md5sum TEXT, |
---|
| 107 | pages TEXT, |
---|
[2024] | 108 | billingcode TEXT, |
---|
[1240] | 109 | jobdate TIMESTAMP DEFAULT now(), |
---|
| 110 | CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota(userid, printerid)); |
---|
[2037] | 111 | CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid); |
---|
[1200] | 112 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
| 113 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
[1520] | 114 | CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); |
---|
[1015] | 115 | |
---|
| 116 | -- |
---|
| 117 | -- Create the print quota table for groups |
---|
| 118 | -- |
---|
| 119 | CREATE TABLE grouppquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 120 | groupid INT4 REFERENCES groups(id), |
---|
| 121 | printerid INT4 REFERENCES printers(id), |
---|
| 122 | softlimit INT4, |
---|
| 123 | hardlimit INT4, |
---|
| 124 | datelimit TIMESTAMP); |
---|
[2054] | 125 | CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid); |
---|
| 126 | CREATE INDEX grouppquota_p_id_ix ON grouppquota (printerid); |
---|
[1200] | 127 | CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); |
---|
[1015] | 128 | |
---|
| 129 | -- |
---|
| 130 | -- Create the groups/members relationship |
---|
| 131 | -- |
---|
| 132 | CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id), |
---|
| 133 | userid INT4 REFERENCES users(id), |
---|
| 134 | PRIMARY KEY (groupid, userid)); |
---|
[1240] | 135 | |
---|
| 136 | -- |
---|
| 137 | -- Create the printer groups relationship |
---|
| 138 | -- |
---|
| 139 | CREATE TABLE printergroupsmembers(groupid INT4 REFERENCES printers(id), |
---|
| 140 | printerid INT4 REFERENCES printers(id), |
---|
| 141 | PRIMARY KEY (groupid, printerid)); |
---|
[1520] | 142 | -- |
---|
| 143 | -- Create the table for payments |
---|
| 144 | -- |
---|
| 145 | CREATE TABLE payments (id SERIAL PRIMARY KEY NOT NULL, |
---|
| 146 | userid INT4 REFERENCES users(id), |
---|
| 147 | amount FLOAT, |
---|
| 148 | date TIMESTAMP DEFAULT now()); |
---|
| 149 | CREATE INDEX payments_date_ix ON payments (date); |
---|
[1015] | 150 | |
---|
[1994] | 151 | -- |
---|
| 152 | -- Create the table for coefficients wrt paper sizes and the like |
---|
| 153 | -- |
---|
| 154 | CREATE TABLE coefficients (id SERIAL PRIMARY KEY NOT NULL, |
---|
| 155 | printerid INTEGER NOT NULL REFERENCES printers(id), |
---|
| 156 | label TEXT NOT NULL, |
---|
[2054] | 157 | coefficient FLOAT DEFAULT 1.0, |
---|
[1994] | 158 | CONSTRAINT coeffconstraint UNIQUE (printerid, label)); |
---|
| 159 | |
---|
[1015] | 160 | -- |
---|
| 161 | -- Set some ACLs |
---|
| 162 | -- |
---|
[2054] | 163 | REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients FROM public; |
---|
| 164 | REVOKE ALL 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 FROM public; |
---|
[1087] | 165 | |
---|
[1994] | 166 | GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients TO pykotaadmin; |
---|
| 167 | 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; |
---|
| 168 | GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients TO pykotauser; |
---|