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

Revision 911, 5.4 kB (checked in by jalet, 21 years ago)

Typo

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