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

Revision 2974, 8.4 kB (checked in by jerome, 18 years ago)

Fixed a bug in the MySQL schema

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[1558]1--
2-- PyKota - Print Quotas for CUPS and LPRng
3--
[2622]4-- (c) 2003, 2004, 2005, 2006 Jerome Alet <alet@librelogiciel.com>
[1558]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
[2303]17-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
[1558]18--
19-- $Id$
20--
[2028]21--
[1558]22
23--
24-- PyKota Database creation script for MySQL
25--
26-- Launch this as MySQL administrator with \.
27--
28
29
30--
31-- Create the print quota database
32--
[2954]33CREATE DATABASE pykota DEFAULT CHARACTER SET 'utf8';
[1558]34
35--
36-- Create the print quota database users
[2817]37-- NOTE: Change the "IDENTIFIED BY" strings to the passwords you would like.
[1558]38--
[2695]39GRANT USAGE ON *.* TO 'pykotauser'@'localhost' IDENTIFIED BY 'readonlypw';
40GRANT USAGE ON *.* TO 'pykotaadmin'@'localhost' IDENTIFIED BY 'readwritepw';
[1558]41
42--
[2873]43-- If necessary activate the lines below (and keep the preceding ones
44-- activated at the same time)
45--
46-- GRANT USAGE ON *.* TO 'pykotauser'@'%' IDENTIFIED BY 'readonlypw';
47-- GRANT USAGE ON *.* TO 'pykotaadmin'@'%' IDENTIFIED BY 'readwritepw';
48
49--
[1558]50-- Now connect to the new database
51--
[2647]52USE pykota;
[1558]53
54--
55-- Create the users table
56--
[2638]57CREATE TABLE users (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
[1558]58                   username VARCHAR(255) UNIQUE NOT NULL,
59                   email TEXT, 
60                   balance FLOAT DEFAULT 0.0,
61                   lifetimepaid FLOAT DEFAULT 0.0,
[2638]62                   limitby VARCHAR(30) DEFAULT 'quota',
[2817]63                   description TEXT,
64                   overcharge FLOAT NOT NULL DEFAULT 1.0) TYPE=INNODB;
[1558]65                   
66--
67-- Create the groups table
68--
[2638]69CREATE TABLE groups (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
[1558]70                    groupname VARCHAR(255) UNIQUE NOT NULL,
[2817]71                    description TEXT,
[2638]72                    limitby VARCHAR(30) DEFAULT 'quota') TYPE=INNODB;
[1558]73                   
74--
75-- Create the printers table
76--
[2638]77CREATE TABLE printers (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
[1558]78                      printername VARCHAR(255) UNIQUE NOT NULL,
79                      description TEXT,
80                      priceperpage FLOAT DEFAULT 0.0,
[2638]81                      priceperjob FLOAT DEFAULT 0.0,
[2817]82                      passthrough ENUM('t','f') DEFAULT 'f',
83                      maxjobsize INT4) TYPE=INNODB;
[1558]84                   
85--
86-- Create the print quota table for users
87--
[2694]88CREATE TABLE userpquota (id INT8 PRIMARY KEY NOT NULL AUTO_INCREMENT,
[2638]89                        userid INT4, 
90                        printerid INT4, 
[1558]91                        lifepagecounter INT4 DEFAULT 0,
92                        pagecounter INT4 DEFAULT 0,
93                        softlimit INT4,
94                        hardlimit INT4,
[2903]95                        datelimit DATETIME,
[2817]96                        maxjobsize INT4,
[2638]97                        warncount INT4 DEFAULT 0, 
[2866]98                        INDEX (userid),
[2817]99                        FOREIGN KEY (userid) REFERENCES users(id),
[2866]100                        INDEX (printerid),
[2817]101                        FOREIGN KEY (printerid) REFERENCES printers(id)) 
102                        TYPE=INNODB;
[1558]103CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid);
104                       
105--
106-- Create the job history table
107--
108CREATE TABLE jobhistory(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
109                        jobid TEXT,
110                        userid INT4,
111                        printerid INT4,
112                        pagecounter INT4 DEFAULT 0,
113                        jobsizebytes INT8,
114                        jobsize INT4,
115                        jobprice FLOAT,
116                        action TEXT,
117                        filename TEXT,
118                        title TEXT,
119                        copies INT4,
120                        options TEXT,
121                        hostname VARCHAR(255),
[2817]122                        md5sum TEXT,
123                        pages TEXT,
124                        billingcode TEXT,
125                        precomputedjobsize INT4,
126                        precomputedjobprice FLOAT,
[2866]127                        jobdate TIMESTAMP,
128                        INDEX (userid, printerid),
[2873]129                        CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota (userid, printerid)
[2817]130                        ) TYPE=INNODB;
[2638]131CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid);
[1558]132CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid);
133CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate);
134CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname);
135                       
136--
137-- Create the print quota table for groups
138--
[2694]139CREATE TABLE grouppquota(id INT8 PRIMARY KEY NOT NULL AUTO_INCREMENT,
[2638]140                         groupid INT4, 
141                         printerid INT4,
[1558]142                         softlimit INT4,
143                         hardlimit INT4,
[2817]144                         maxjobsize INT4,
[2903]145                         datelimit DATETIME,
[2873]146                         INDEX (groupid),
[2817]147                         FOREIGN KEY (groupid) REFERENCES groups(id),
[2873]148                         INDEX (printerid),
[2817]149                         FOREIGN KEY (printerid) REFERENCES printers(id))
150                         TYPE=INNODB;
[1558]151CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid);
152                       
153--                         
154-- Create the groups/members relationship
155--
[2866]156CREATE TABLE groupsmembers(groupid INT4 NOT NULL,
157                           userid INT4 NOT NULL,
158                           INDEX (groupid),
[2817]159                           FOREIGN KEY (groupid) REFERENCES groups(id),
[2866]160                           INDEX (userid),
[2817]161                           FOREIGN KEY (userid) REFERENCES users(id),
[2638]162                           PRIMARY KEY (groupid, userid)) TYPE=INNODB;
[1558]163                           
164--                         
165-- Create the printer groups relationship
166--
[2866]167CREATE TABLE printergroupsmembers(groupid INT4 NOT NULL,
168                           printerid INT4 NOT NULL,
169                           INDEX (groupid),
[2974]170                           FOREIGN KEY (groupid) REFERENCES printers(id),
[2866]171                           INDEX (printerid),
[2817]172                           FOREIGN KEY (printerid) REFERENCES printers(id),
[2638]173                           PRIMARY KEY (groupid, printerid)) TYPE=INNODB;
[1558]174--
175-- Create the table for payments
176--
177CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
[2638]178                       userid INT4,
[1558]179                       amount FLOAT,
[2817]180                       description TEXT,
[2866]181                       date TIMESTAMP,
182                       INDEX (userid),
[2817]183                       FOREIGN KEY (userid) REFERENCES users(id)) TYPE=INNODB;
[1558]184CREATE INDEX payments_date_ix ON payments (date);
185
[2638]186--
187-- Create the table for coefficients wrt paper sizes and the like
188--
189CREATE TABLE coefficients (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
[2817]190                           printerid INT4 NOT NULL,
191                           label VARCHAR(255) NOT NULL,
192                           coefficient FLOAT DEFAULT 1.0,
[2866]193                           INDEX (printerid),
[2817]194                           FOREIGN KEY (printerid) REFERENCES printers(id),
195                           CONSTRAINT coeffconstraint UNIQUE (printerid, label)
196                           ) TYPE=INNODB;
[2638]197
198--
199-- Create the table for the billing codes
200--
[2691]201CREATE TABLE billingcodes (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
[2638]202                           billingcode VARCHAR(255) UNIQUE NOT NULL,
203                           description TEXT,
204                           balance FLOAT DEFAULT 0.0,
205                           pagecounter INT4 DEFAULT 0) TYPE=INNODB;
[1558]206--                       
207-- Set some ACLs                       
208--
[2638]209GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'localhost';
210GRANT SELECT ON `pykota`.* TO 'pykotauser'@'localhost';
[1558]211
[2873]212--
213-- If necessary activate the lines below (and keep the preceding ones
214-- activated at the same time)
215--
216-- GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'%';
217-- GRANT SELECT ON `pykota`.* TO 'pykotauser'@'%';
Note: See TracBrowser for help on using the browser.