root / pykota / trunk / initscripts / mysql / pykota-mysql.sql @ 2139

Revision 2139, 6.0 kB (checked in by jerome, 19 years ago)

Added the Log keyword property

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision Log
Line 
1--
2-- PyKota - Print Quotas for CUPS and LPRng
3--
4-- (c) 2003, 2004, 2005 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.2  2005/01/17 08:44:24  jalet
23-- Modified copyright years
24--
25-- Revision 1.1  2004/06/20 19:14:20  jalet
26-- Added first draft of MySQL initialization script
27--
28--
29--
30
31--
32-- PyKota Database creation script for MySQL
33--
34-- Launch this as MySQL administrator with \.
35--
36
37
38--
39-- Create the print quota database
40--
41
42--
43-- Create the print quota database users
44--
45-- TODO : CREATE USER pykotaadmin;
46-- TODO : CREATE USER pykotauser;
47
48--
49-- Now connect to the new database
50--
51\u pykota
52
53--
54-- Create the users table
55--
56CREATE TABLE users(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
57                   username VARCHAR(255) UNIQUE NOT NULL,
58                   email TEXT, 
59                   balance FLOAT DEFAULT 0.0,
60                   lifetimepaid FLOAT DEFAULT 0.0,
61                   limitby VARCHAR(30) DEFAULT 'quota');
62                   
63--
64-- Create the groups table
65--
66CREATE TABLE groups(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
67                    groupname VARCHAR(255) UNIQUE NOT NULL,
68                    limitby VARCHAR(30) DEFAULT 'quota');
69                   
70--
71-- Create the printers table
72--
73CREATE TABLE printers(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
74                      printername VARCHAR(255) UNIQUE NOT NULL,
75                      description TEXT,
76                      priceperpage FLOAT DEFAULT 0.0,
77                      priceperjob FLOAT DEFAULT 0.0);
78                   
79--
80-- Create the print quota table for users
81--
82CREATE TABLE userpquota(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
83                        userid INT4 REFERENCES users(id),
84                        printerid INT4 REFERENCES printers(id),
85                        lifepagecounter INT4 DEFAULT 0,
86                        pagecounter INT4 DEFAULT 0,
87                        softlimit INT4,
88                        hardlimit INT4,
89                        datelimit TIMESTAMP);
90CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid);
91                       
92--
93-- Create the job history table
94--
95CREATE TABLE jobhistory(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
96                        jobid TEXT,
97                        userid INT4,
98                        printerid INT4,
99                        pagecounter INT4 DEFAULT 0,
100                        jobsizebytes INT8,
101                        jobsize INT4,
102                        jobprice FLOAT,
103                        action TEXT,
104                        filename TEXT,
105                        title TEXT,
106                        copies INT4,
107                        options TEXT,
108                        hostname VARCHAR(255),
109                        jobdate TIMESTAMP,
110                        CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) 
111                                                           REFERENCES userpquota(userid, printerid));
112CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid);
113CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate);
114CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname);
115                       
116--
117-- Create the print quota table for groups
118--
119CREATE TABLE grouppquota(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
120                         groupid INT4 REFERENCES groups(id),
121                         printerid INT4 REFERENCES printers(id),
122                         softlimit INT4,
123                         hardlimit INT4,
124                         datelimit TIMESTAMP);
125CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid);
126                       
127--                         
128-- Create the groups/members relationship
129--
130CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id),
131                           userid INT4 REFERENCES users(id),
132                           PRIMARY KEY (groupid, userid));
133                           
134--                         
135-- Create the printer groups relationship
136--
137CREATE TABLE printergroupsmembers(groupid INT4 REFERENCES printers(id),
138                           printerid INT4 REFERENCES printers(id),
139                           PRIMARY KEY (groupid, printerid));
140--
141-- Create the table for payments
142--
143CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
144                       userid INT4 REFERENCES users(id),
145                       amount FLOAT,
146                       date TIMESTAMP DEFAULT now());
147CREATE INDEX payments_date_ix ON payments (date);
148
149--                       
150-- Set some ACLs                       
151--
152-- TODO : REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments FROM public;                       
153-- TODO : REVOKE ALL ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq, payments_id_seq FROM public;
154
155-- TODO : GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotaadmin;
156-- TODO : GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq, payments_id_seq TO pykotaadmin;
157-- TODO : GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotauser;
Note: See TracBrowser for help on using the browser.