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

Revision 1079, 4.4 kB (checked in by jalet, 21 years ago)

Email field added to PostgreSQL schema

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