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