[1015] | 1 | -- |
---|
| 2 | -- PyKota - Print Quotas for CUPS and LPRng |
---|
| 3 | -- |
---|
[3133] | 4 | -- (c) 2003, 2004, 2005, 2006, 2007 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 |
---|
[2303] | 17 | -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
[1015] | 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 | -- |
---|
[2954] | 33 | CREATE DATABASE pykota WITH ENCODING='UTF-8'; |
---|
[1015] | 34 | |
---|
| 35 | -- |
---|
| 36 | -- Create the print quota database users |
---|
[2817] | 37 | -- NOTE: Change the password values to the passwords you would like. |
---|
[1015] | 38 | -- |
---|
[2817] | 39 | CREATE USER pykotauser WITH UNENCRYPTED PASSWORD 'readonlypw' NOCREATEDB NOCREATEUSER; |
---|
| 40 | CREATE USER pykotaadmin WITH UNENCRYPTED PASSWORD 'readwritepw' NOCREATEDB NOCREATEUSER; |
---|
[1015] | 41 | |
---|
| 42 | -- |
---|
| 43 | -- Now connect to the new database |
---|
| 44 | -- |
---|
| 45 | \connect pykota |
---|
| 46 | |
---|
| 47 | -- |
---|
| 48 | -- Create the users table |
---|
| 49 | -- |
---|
| 50 | CREATE TABLE users(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 51 | username TEXT UNIQUE NOT NULL, |
---|
[1079] | 52 | email TEXT, |
---|
[1015] | 53 | balance FLOAT DEFAULT 0.0, |
---|
| 54 | lifetimepaid FLOAT DEFAULT 0.0, |
---|
[1994] | 55 | limitby TEXT DEFAULT 'quota', |
---|
[2317] | 56 | description TEXT, |
---|
[2054] | 57 | overcharge FLOAT NOT NULL DEFAULT 1.0); |
---|
[1015] | 58 | |
---|
| 59 | -- |
---|
| 60 | -- Create the groups table |
---|
| 61 | -- |
---|
| 62 | CREATE TABLE groups(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 63 | groupname TEXT UNIQUE NOT NULL, |
---|
[2317] | 64 | description TEXT, |
---|
[1015] | 65 | limitby TEXT DEFAULT 'quota'); |
---|
| 66 | |
---|
| 67 | -- |
---|
| 68 | -- Create the printers table |
---|
| 69 | -- |
---|
| 70 | CREATE TABLE printers(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 71 | printername TEXT UNIQUE NOT NULL, |
---|
[1556] | 72 | description TEXT, |
---|
[1015] | 73 | priceperpage FLOAT DEFAULT 0.0, |
---|
[2317] | 74 | priceperjob FLOAT DEFAULT 0.0, |
---|
[2457] | 75 | passthrough BOOLEAN DEFAULT FALSE, |
---|
[2317] | 76 | maxjobsize INT4); |
---|
[1015] | 77 | |
---|
| 78 | -- |
---|
| 79 | -- Create the print quota table for users |
---|
| 80 | -- |
---|
| 81 | CREATE TABLE userpquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 82 | userid INT4 REFERENCES users(id), |
---|
| 83 | printerid INT4 REFERENCES printers(id), |
---|
| 84 | lifepagecounter INT4 DEFAULT 0, |
---|
| 85 | pagecounter INT4 DEFAULT 0, |
---|
| 86 | softlimit INT4, |
---|
| 87 | hardlimit INT4, |
---|
[1994] | 88 | datelimit TIMESTAMP, |
---|
[2317] | 89 | maxjobsize INT4, |
---|
[2054] | 90 | warncount INT4 DEFAULT 0); |
---|
[2037] | 91 | CREATE INDEX userpquota_u_id_ix ON userpquota (userid); |
---|
| 92 | CREATE INDEX userpquota_p_id_ix ON userpquota (printerid); |
---|
[1200] | 93 | CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); |
---|
[1015] | 94 | |
---|
| 95 | -- |
---|
| 96 | -- Create the job history table |
---|
| 97 | -- |
---|
| 98 | CREATE TABLE jobhistory(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 99 | jobid TEXT, |
---|
[1240] | 100 | userid INT4, |
---|
| 101 | printerid INT4, |
---|
[1015] | 102 | pagecounter INT4 DEFAULT 0, |
---|
[1520] | 103 | jobsizebytes INT8, |
---|
[1015] | 104 | jobsize INT4, |
---|
[1203] | 105 | jobprice FLOAT, |
---|
[1015] | 106 | action TEXT, |
---|
[1200] | 107 | filename TEXT, |
---|
| 108 | title TEXT, |
---|
| 109 | copies INT4, |
---|
| 110 | options TEXT, |
---|
[1520] | 111 | hostname TEXT, |
---|
[1994] | 112 | md5sum TEXT, |
---|
| 113 | pages TEXT, |
---|
[2024] | 114 | billingcode TEXT, |
---|
[2317] | 115 | precomputedjobsize INT4, |
---|
| 116 | precomputedjobprice FLOAT, |
---|
[1240] | 117 | jobdate TIMESTAMP DEFAULT now(), |
---|
| 118 | CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota(userid, printerid)); |
---|
[2037] | 119 | CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid); |
---|
[1200] | 120 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
| 121 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
[1520] | 122 | CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); |
---|
[1015] | 123 | |
---|
| 124 | -- |
---|
| 125 | -- Create the print quota table for groups |
---|
| 126 | -- |
---|
| 127 | CREATE TABLE grouppquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 128 | groupid INT4 REFERENCES groups(id), |
---|
| 129 | printerid INT4 REFERENCES printers(id), |
---|
| 130 | softlimit INT4, |
---|
| 131 | hardlimit INT4, |
---|
[2317] | 132 | maxjobsize INT4, |
---|
[1015] | 133 | datelimit TIMESTAMP); |
---|
[2054] | 134 | CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid); |
---|
| 135 | CREATE INDEX grouppquota_p_id_ix ON grouppquota (printerid); |
---|
[1200] | 136 | CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); |
---|
[1015] | 137 | |
---|
| 138 | -- |
---|
| 139 | -- Create the groups/members relationship |
---|
| 140 | -- |
---|
| 141 | CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id), |
---|
| 142 | userid INT4 REFERENCES users(id), |
---|
| 143 | PRIMARY KEY (groupid, userid)); |
---|
[1240] | 144 | |
---|
| 145 | -- |
---|
| 146 | -- Create the printer groups relationship |
---|
| 147 | -- |
---|
| 148 | CREATE TABLE printergroupsmembers(groupid INT4 REFERENCES printers(id), |
---|
| 149 | printerid INT4 REFERENCES printers(id), |
---|
| 150 | PRIMARY KEY (groupid, printerid)); |
---|
[1520] | 151 | -- |
---|
| 152 | -- Create the table for payments |
---|
| 153 | -- |
---|
| 154 | CREATE TABLE payments (id SERIAL PRIMARY KEY NOT NULL, |
---|
| 155 | userid INT4 REFERENCES users(id), |
---|
| 156 | amount FLOAT, |
---|
[2452] | 157 | description TEXT, |
---|
[1520] | 158 | date TIMESTAMP DEFAULT now()); |
---|
| 159 | CREATE INDEX payments_date_ix ON payments (date); |
---|
[1015] | 160 | |
---|
[1994] | 161 | -- |
---|
| 162 | -- Create the table for coefficients wrt paper sizes and the like |
---|
| 163 | -- |
---|
| 164 | CREATE TABLE coefficients (id SERIAL PRIMARY KEY NOT NULL, |
---|
| 165 | printerid INTEGER NOT NULL REFERENCES printers(id), |
---|
| 166 | label TEXT NOT NULL, |
---|
[2054] | 167 | coefficient FLOAT DEFAULT 1.0, |
---|
[1994] | 168 | CONSTRAINT coeffconstraint UNIQUE (printerid, label)); |
---|
| 169 | |
---|
[2317] | 170 | -- |
---|
| 171 | -- Create the table for the billing codes |
---|
| 172 | -- |
---|
| 173 | CREATE TABLE billingcodes (id SERIAL PRIMARY KEY NOT NULL, |
---|
[2342] | 174 | billingcode TEXT UNIQUE NOT NULL, |
---|
[2318] | 175 | description TEXT, |
---|
[2317] | 176 | balance FLOAT DEFAULT 0.0, |
---|
| 177 | pagecounter INT4 DEFAULT 0); |
---|
| 178 | |
---|
[1015] | 179 | -- |
---|
| 180 | -- Set some ACLs |
---|
| 181 | -- |
---|
[2317] | 182 | REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients, billingcodes FROM public; |
---|
| 183 | 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, billingcodes_id_seq FROM public; |
---|
[1087] | 184 | |
---|
[2317] | 185 | GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients, billingcodes TO pykotaadmin; |
---|
| 186 | 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, billingcodes_id_seq TO pykotaadmin; |
---|
| 187 | GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients, billingcodes TO pykotauser; |
---|