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

Revision 915, 5.7 kB (checked in by jalet, 22 years ago)

More work done on money print charging.
Minor bugs corrected.
All tools now access to the storage as priviledged users, repykota excepted.

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