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

Revision 2024, 7.8 kB (checked in by jalet, 19 years ago)

Added the billing code to the history

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