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

Revision 1200, 5.3 kB (checked in by jalet, 20 years ago)

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