root / pykota / trunk / initscripts / postgresql / pykota-postgresql.sql @ 1994

Revision 1994, 7.7 kB (checked in by jalet, 19 years ago)

Added the coefficient table, and many columns to existing tables

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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.12  2004/12/23 18:40:18  jalet
23-- Added the coefficient table, and many columns to existing tables
24--
25-- Revision 1.11  2004/06/20 16:15:21  jalet
26-- Added "description" attribute for printers
27--
28-- Revision 1.10  2004/06/03 23:14:09  jalet
29-- Now stores the job's size in bytes in the database.
30-- Preliminary work on payments storage : database schemas are OK now,
31-- but no code to store payments yet.
32-- Removed schema picture, not relevant anymore.
33--
34-- Revision 1.9  2004/05/13 11:15:29  jalet
35-- Added hostname field in job history
36--
37-- Revision 1.8  2004/01/08 14:10:32  jalet
38-- Copyright year changed.
39--
40-- Revision 1.7  2003/12/27 16:49:25  uid67467
41-- Should be ok now.
42--
43-- Revision 1.6  2003/11/23 19:01:36  jalet
44-- Job price added to history
45--
46-- Revision 1.5  2003/11/21 14:28:45  jalet
47-- More complete job history.
48--
49-- Revision 1.4  2003/07/16 21:53:07  jalet
50-- Really big modifications wrt new configuration file's location and content.
51--
52-- Revision 1.3  2003/07/09 20:17:07  jalet
53-- Email field added to PostgreSQL schema
54--
55-- Revision 1.2  2003/06/10 16:37:54  jalet
56-- Deletion of the second user which is not needed anymore.
57-- Added a debug configuration field in /etc/pykota.conf
58-- All queries can now be sent to the logger in debug mode, this will
59-- greatly help improve performance when time for this will come.
60--
61-- Revision 1.1  2003/06/05 07:12:31  jalet
62-- Reorganization of directories
63--
64--
65--
66
67--
68-- PyKota Database creation script for PostgreSQL
69--
70-- Launch this as PostgreSQL administrator with \i
71--
72
73
74--
75-- Create the print quota database
76--
77CREATE DATABASE pykota;
78
79--
80-- Create the print quota database users
81--
82CREATE USER pykotaadmin;
83CREATE USER pykotauser;
84
85--
86-- Now connect to the new database
87--
88\connect pykota
89
90--
91-- Create the users table
92--
93CREATE TABLE users(id SERIAL PRIMARY KEY NOT NULL,
94                   username TEXT UNIQUE NOT NULL,
95                   email TEXT, 
96                   balance FLOAT DEFAULT 0.0,
97                   lifetimepaid FLOAT DEFAULT 0.0,
98                   limitby TEXT DEFAULT 'quota',
99                   coefficient FLOAT NOT NULL DEFAULT 1.0);
100                   
101--
102-- Create the groups table
103--
104CREATE TABLE groups(id SERIAL PRIMARY KEY NOT NULL,
105                    groupname TEXT UNIQUE NOT NULL,
106                    limitby TEXT DEFAULT 'quota');
107                   
108--
109-- Create the printers table
110--
111CREATE TABLE printers(id SERIAL PRIMARY KEY NOT NULL,
112                      printername TEXT UNIQUE NOT NULL,
113                      description TEXT,
114                      priceperpage FLOAT DEFAULT 0.0,
115                      priceperjob FLOAT DEFAULT 0.0);
116                   
117--
118-- Create the print quota table for users
119--
120CREATE TABLE userpquota(id SERIAL PRIMARY KEY NOT NULL,
121                        userid INT4 REFERENCES users(id),
122                        printerid INT4 REFERENCES printers(id),
123                        lifepagecounter INT4 DEFAULT 0,
124                        pagecounter INT4 DEFAULT 0,
125                        softlimit INT4,
126                        hardlimit INT4,
127                        datelimit TIMESTAMP,
128                        warned INT4 DEFAULT 0); -- not a boolean, will help stats
129CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid);
130                       
131--
132-- Create the job history table
133--
134CREATE TABLE jobhistory(id SERIAL PRIMARY KEY NOT NULL,
135                        jobid TEXT,
136                        userid INT4,
137                        printerid INT4,
138                        pagecounter INT4 DEFAULT 0,
139                        jobsizebytes INT8,
140                        jobsize INT4,
141                        jobprice FLOAT,
142                        action TEXT,
143                        filename TEXT,
144                        title TEXT,
145                        copies INT4,
146                        options TEXT,
147                        hostname TEXT,
148                        md5sum TEXT,
149                        pages TEXT,
150                        jobdate TIMESTAMP DEFAULT now(),
151                        CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota(userid, printerid));
152CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid);
153CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate);
154CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname);
155                       
156--
157-- Create the print quota table for groups
158--
159CREATE TABLE grouppquota(id SERIAL PRIMARY KEY NOT NULL,
160                         groupid INT4 REFERENCES groups(id),
161                         printerid INT4 REFERENCES printers(id),
162                         softlimit INT4,
163                         hardlimit INT4,
164                         datelimit TIMESTAMP);
165CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid);
166                       
167--                         
168-- Create the groups/members relationship
169--
170CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id),
171                           userid INT4 REFERENCES users(id),
172                           PRIMARY KEY (groupid, userid));
173                           
174--                         
175-- Create the printer groups relationship
176--
177CREATE TABLE printergroupsmembers(groupid INT4 REFERENCES printers(id),
178                           printerid INT4 REFERENCES printers(id),
179                           PRIMARY KEY (groupid, printerid));
180--
181-- Create the table for payments
182--
183CREATE TABLE payments (id SERIAL PRIMARY KEY NOT NULL,
184                       userid INT4 REFERENCES users(id),
185                       amount FLOAT,
186                       date TIMESTAMP DEFAULT now());
187CREATE INDEX payments_date_ix ON payments (date);
188
189--
190-- Create the table for coefficients wrt paper sizes and the like
191--
192CREATE TABLE coefficients (id SERIAL PRIMARY KEY NOT NULL, 
193                           printerid INTEGER NOT NULL REFERENCES printers(id), 
194                           label TEXT NOT NULL, 
195                           coefficient FLOAT NOT NULL DEFAULT 1.0, 
196                           CONSTRAINT coeffconstraint UNIQUE (printerid, label));
197
198--                       
199-- Set some ACLs                       
200--
201REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments FROM public;                       
202REVOKE ALL ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq, payments_id_seq FROM public;
203
204GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients TO pykotaadmin;
205GRANT 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;
206GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments, coefficients TO pykotauser;
Note: See TracBrowser for help on using the browser.