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

Revision 900, 5.0 kB (checked in by jalet, 21 years ago)

Job history added. Upgrade script neutralized for now !

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1--
2-- PyKota - Print Quotas for CUPS
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.10  2003/04/10 21:47:20  jalet
23-- Job history added. Upgrade script neutralized for now !
24--
25-- Revision 1.9  2003/04/09 20:11:29  jalet
26-- Added a field to save the action taken for this job (Allow, Deny)
27--
28-- Revision 1.8  2003/04/09 20:09:34  jalet
29-- New table to keep job history
30--
31-- Revision 1.7  2003/04/08 20:38:08  jalet
32-- The last job Id is saved now for each printer, this will probably
33-- allow other accounting methods in the future.
34--
35-- Revision 1.6  2003/03/29 13:45:27  jalet
36-- GPL paragraphs were incorrectly (from memory) copied into the sources.
37-- Two README files were added.
38-- Upgrade script for PostgreSQL pre 1.01 schema was added.
39--
40-- Revision 1.5  2003/03/12 19:06:08  jalet
41-- Initial support for groups added.
42--
43-- Revision 1.4  2003/02/27 08:40:14  jalet
44-- DATETIME is not supported anymore in PostgreSQL 7.3 it seems, but
45-- TIMESTAMP is.
46--
47-- Revision 1.3  2003/02/26 20:34:22  jalet
48-- Default value for printer page counter set to 0
49--
50-- Revision 1.2  2003/02/08 22:12:09  jalet
51-- Life time counter for users and groups added.
52--
53-- Revision 1.1  2003/02/05 21:28:17  jalet
54-- Initial import into CVS
55--
56--
57--
58
59--
60-- PyKota Database creation script for PostgreSQL
61--
62-- Launch this as PostgreSQL administrator with \i
63--
64
65
66--
67-- Create the print quota database
68--
69CREATE DATABASE pykota;
70
71--
72-- Create the print quota database users
73--
74CREATE USER pykotauser;
75CREATE USER pykotaadmin;
76
77--
78-- Now connect to the new database
79--
80\connect pykota
81
82--
83-- Create the users table
84--
85CREATE TABLE users(id SERIAL PRIMARY KEY NOT NULL,
86                   username TEXT UNIQUE NOT NULL);
87                   
88--
89-- Create the groups table
90--
91CREATE TABLE groups(id SERIAL PRIMARY KEY NOT NULL,
92                    groupname TEXT UNIQUE NOT NULL);
93                   
94--
95-- Create the printers table
96--
97CREATE TABLE printers(id SERIAL PRIMARY KEY NOT NULL,
98                      printername TEXT UNIQUE NOT NULL);
99                   
100--
101-- Create the print quota table for users
102--
103CREATE TABLE userpquota(id SERIAL PRIMARY KEY NOT NULL,
104                        userid INT4 REFERENCES users(id),
105                        printerid INT4 REFERENCES printers(id),
106                        lifepagecounter INT4 DEFAULT 0,
107                        pagecounter INT4 DEFAULT 0,
108                        softlimit INT4,
109                        hardlimit INT4,
110                        datelimit TIMESTAMP);
111                       
112--
113-- Create the job history table
114--
115CREATE TABLE jobhistory(id SERIAL PRIMARY KEY NOT NULL,
116                        jobid TEXT,
117                        userid INT4 REFERENCES users(id),
118                        printerid INT4 REFERENCES printers(id),
119                        pagecounter INT4 DEFAULT 0,
120                        jobsize INT4,
121                        action TEXT,
122                        jobdate TIMESTAMP DEFAULT now());
123                       
124--
125-- Create the print quota table for groups
126--
127CREATE TABLE grouppquota(id SERIAL PRIMARY KEY NOT NULL,
128                         groupid INT4 REFERENCES groups(id),
129                         printerid INT4 REFERENCES printers(id),
130                         softlimit INT4,
131                         hardlimit INT4,
132                         datelimit TIMESTAMP);
133                       
134--                         
135-- Create the groups/members relationship
136--
137CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id),
138                           userid INT4 REFERENCES users(id),
139                           PRIMARY KEY (groupid, userid));
140
141--                       
142-- Set some ACLs                       
143--
144REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory FROM public;                       
145GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory TO pykotaadmin;
146GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq TO pykotaadmin;
147GRANT SELECT, UPDATE ON printers, userpquota, grouppquota TO pykotauser;
148GRANT SELECT ON users, groups, groupsmembers TO pykotauser;
149GRANT SELECT, INSERT, UPDATE ON jobhistory TO pykotauser;
150GRANT SELECT, UPDATE ON jobhistory_id_seq TO pykotauser;
Note: See TracBrowser for help on using the browser.