[695] | 1 | -- |
---|
| 2 | -- PyKota - Print Quotas for CUPS |
---|
| 3 | -- |
---|
| 4 | -- (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
[873] | 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. |
---|
[695] | 9 | -- |
---|
[873] | 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. |
---|
[695] | 18 | -- |
---|
| 19 | -- $Id$ |
---|
| 20 | -- |
---|
| 21 | -- $Log$ |
---|
[896] | 22 | -- Revision 1.8 2003/04/09 20:09:34 jalet |
---|
| 23 | -- New table to keep job history |
---|
| 24 | -- |
---|
[887] | 25 | -- Revision 1.7 2003/04/08 20:38:08 jalet |
---|
| 26 | -- The last job Id is saved now for each printer, this will probably |
---|
| 27 | -- allow other accounting methods in the future. |
---|
| 28 | -- |
---|
[873] | 29 | -- Revision 1.6 2003/03/29 13:45:27 jalet |
---|
| 30 | -- GPL paragraphs were incorrectly (from memory) copied into the sources. |
---|
| 31 | -- Two README files were added. |
---|
| 32 | -- Upgrade script for PostgreSQL pre 1.01 schema was added. |
---|
| 33 | -- |
---|
[849] | 34 | -- Revision 1.5 2003/03/12 19:06:08 jalet |
---|
| 35 | -- Initial support for groups added. |
---|
| 36 | -- |
---|
[812] | 37 | -- Revision 1.4 2003/02/27 08:40:14 jalet |
---|
| 38 | -- DATETIME is not supported anymore in PostgreSQL 7.3 it seems, but |
---|
| 39 | -- TIMESTAMP is. |
---|
| 40 | -- |
---|
[811] | 41 | -- Revision 1.3 2003/02/26 20:34:22 jalet |
---|
| 42 | -- Default value for printer page counter set to 0 |
---|
| 43 | -- |
---|
[765] | 44 | -- Revision 1.2 2003/02/08 22:12:09 jalet |
---|
| 45 | -- Life time counter for users and groups added. |
---|
| 46 | -- |
---|
[695] | 47 | -- Revision 1.1 2003/02/05 21:28:17 jalet |
---|
| 48 | -- Initial import into CVS |
---|
| 49 | -- |
---|
| 50 | -- |
---|
| 51 | -- |
---|
| 52 | |
---|
| 53 | -- |
---|
| 54 | -- PyKota Database creation script for PostgreSQL |
---|
| 55 | -- |
---|
| 56 | -- Launch this as PostgreSQL administrator with \i |
---|
| 57 | -- |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | -- |
---|
| 61 | -- Create the print quota database |
---|
| 62 | -- |
---|
| 63 | CREATE DATABASE pykota; |
---|
| 64 | |
---|
| 65 | -- |
---|
| 66 | -- Create the print quota database users |
---|
| 67 | -- |
---|
| 68 | CREATE USER pykotauser; |
---|
| 69 | CREATE USER pykotaadmin; |
---|
| 70 | |
---|
| 71 | -- |
---|
| 72 | -- Now connect to the new database |
---|
| 73 | -- |
---|
| 74 | \connect pykota |
---|
| 75 | |
---|
| 76 | -- |
---|
| 77 | -- Create the users table |
---|
| 78 | -- |
---|
| 79 | CREATE TABLE users(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 80 | username TEXT UNIQUE NOT NULL); |
---|
| 81 | |
---|
| 82 | -- |
---|
| 83 | -- Create the groups table |
---|
| 84 | -- |
---|
| 85 | CREATE TABLE groups(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 86 | groupname TEXT UNIQUE NOT NULL); |
---|
| 87 | |
---|
| 88 | -- |
---|
| 89 | -- Create the printers table |
---|
| 90 | -- |
---|
| 91 | CREATE TABLE printers(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 92 | printername TEXT UNIQUE NOT NULL, |
---|
[887] | 93 | lastjobid TEXT, |
---|
[695] | 94 | lastusername TEXT, |
---|
[811] | 95 | pagecounter INT4 DEFAULT 0); |
---|
[695] | 96 | |
---|
| 97 | -- |
---|
| 98 | -- Create the print quota table for users |
---|
| 99 | -- |
---|
| 100 | CREATE TABLE userpquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 101 | userid INT4 REFERENCES users(id), |
---|
| 102 | printerid INT4 REFERENCES printers(id), |
---|
[765] | 103 | lifepagecounter INT4 DEFAULT 0, |
---|
[695] | 104 | pagecounter INT4 DEFAULT 0, |
---|
| 105 | softlimit INT4, |
---|
| 106 | hardlimit INT4, |
---|
[812] | 107 | datelimit TIMESTAMP); |
---|
[695] | 108 | |
---|
| 109 | -- |
---|
[896] | 110 | -- Create the job history table for u |
---|
| 111 | -- |
---|
| 112 | CREATE TABLE jobhistory(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 113 | jobid TEXT, |
---|
| 114 | userid INT4 REFERENCES users(id), |
---|
| 115 | printerid INT4 REFERENCES printers(id), |
---|
| 116 | jobsize INT4, |
---|
| 117 | jobdate TIMESTAMP DEFAULT now()); |
---|
| 118 | |
---|
| 119 | -- |
---|
[695] | 120 | -- Create the print quota table for groups |
---|
| 121 | -- |
---|
| 122 | CREATE TABLE grouppquota(id SERIAL PRIMARY KEY NOT NULL, |
---|
| 123 | groupid INT4 REFERENCES groups(id), |
---|
| 124 | printerid INT4 REFERENCES printers(id), |
---|
| 125 | softlimit INT4, |
---|
| 126 | hardlimit INT4, |
---|
[812] | 127 | datelimit TIMESTAMP); |
---|
[695] | 128 | |
---|
[849] | 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)); |
---|
| 135 | |
---|
[695] | 136 | -- |
---|
| 137 | -- Set some ACLs |
---|
| 138 | -- |
---|
[896] | 139 | REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory FROM public; |
---|
| 140 | GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory TO pykotaadmin; |
---|
| 141 | GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq TO pykotaadmin; |
---|
[695] | 142 | GRANT SELECT, UPDATE ON printers, userpquota, grouppquota TO pykotauser; |
---|
[896] | 143 | GRANT SELECT ON users, groups, groupsmembers, jobhistory TO pykotauser; |
---|