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