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

Revision 1473, 6.1 kB (checked in by jalet, 20 years ago)

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