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

Revision 2028, 7.9 kB (checked in by jalet, 19 years ago)

Modified copyright years

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