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

Revision 1015, 4.3 kB (checked in by jalet, 21 years ago)

Reorganization of directories

  • 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.1  2003/06/05 07:12:31  jalet
23-- Reorganization of directories
24--
25--
26--
27
28--
29-- PyKota Database creation script for PostgreSQL
30--
31-- Launch this as PostgreSQL administrator with \i
32--
33
34
35--
36-- Create the print quota database
37--
38CREATE DATABASE pykota;
39
40--
41-- Create the print quota database users
42--
43CREATE USER pykotauser;
44CREATE USER pykotaadmin;
45
46--
47-- Now connect to the new database
48--
49\connect pykota
50
51--
52-- Create the users table
53--
54CREATE TABLE users(id SERIAL PRIMARY KEY NOT NULL,
55                   username TEXT UNIQUE NOT NULL,
56                   balance FLOAT DEFAULT 0.0,
57                   lifetimepaid FLOAT DEFAULT 0.0,
58                   limitby TEXT DEFAULT 'quota');
59                   
60--
61-- Create the groups table
62--
63CREATE TABLE groups(id SERIAL PRIMARY KEY NOT NULL,
64                    groupname TEXT UNIQUE NOT NULL,
65                    limitby TEXT DEFAULT 'quota');
66                   
67--
68-- Create the printers table
69--
70CREATE TABLE printers(id SERIAL PRIMARY KEY NOT NULL,
71                      printername TEXT UNIQUE NOT NULL,
72                      priceperpage FLOAT DEFAULT 0.0,
73                      priceperjob FLOAT DEFAULT 0.0);
74                   
75--
76-- Create the print quota table for users
77--
78CREATE TABLE userpquota(id SERIAL PRIMARY KEY NOT NULL,
79                        userid INT4 REFERENCES users(id),
80                        printerid INT4 REFERENCES printers(id),
81                        lifepagecounter INT4 DEFAULT 0,
82                        pagecounter INT4 DEFAULT 0,
83                        softlimit INT4,
84                        hardlimit INT4,
85                        datelimit TIMESTAMP);
86                       
87--
88-- Create the job history table
89--
90CREATE TABLE jobhistory(id SERIAL PRIMARY KEY NOT NULL,
91                        jobid TEXT,
92                        userid INT4 REFERENCES users(id),
93                        printerid INT4 REFERENCES printers(id),
94                        pagecounter INT4 DEFAULT 0,
95                        jobsize INT4,
96                        action TEXT,
97                        jobdate TIMESTAMP DEFAULT now());
98                       
99--
100-- Create the print quota table for groups
101--
102CREATE TABLE grouppquota(id SERIAL PRIMARY KEY NOT NULL,
103                         groupid INT4 REFERENCES groups(id),
104                         printerid INT4 REFERENCES printers(id),
105                         softlimit INT4,
106                         hardlimit INT4,
107                         datelimit TIMESTAMP);
108                       
109--                         
110-- Create the groups/members relationship
111--
112CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id),
113                           userid INT4 REFERENCES users(id),
114                           PRIMARY KEY (groupid, userid));
115
116--                       
117-- Set some ACLs                       
118--
119REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory FROM public;                       
120GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory TO pykotaadmin;
121GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq TO pykotaadmin;
122GRANT SELECT, UPDATE ON printers, userpquota, grouppquota TO pykotauser;
123GRANT SELECT ON users, groups, groupsmembers TO pykotauser;
124GRANT SELECT, INSERT, UPDATE ON jobhistory TO pykotauser;
125GRANT SELECT, UPDATE ON jobhistory_id_seq TO pykotauser;
Note: See TracBrowser for help on using the browser.