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

Revision 2638, 7.0 kB (checked in by matt, 18 years ago)

Initial MySQL support

  • 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, 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18--
19-- $Id$
20--
21--
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--
33CREATE DATABASE pykota;
34
35--
36-- Create the print quota database users
37--
38GRANT USAGE ON *.* TO 'pykotauser'@'localhost' IDENTIFIED BY 'readonly';
39GRANT USAGE ON *.* TO 'pykotaadmin'@'localhost' IDENTIFIED BY 'readwrite';
40
41--
42-- Now connect to the new database
43--
44use pykota;
45
46--
47-- Create the users table
48--
49CREATE TABLE users (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
50                   username VARCHAR(255) UNIQUE NOT NULL,
51                   email TEXT, 
52                   balance FLOAT DEFAULT 0.0,
53                   lifetimepaid FLOAT DEFAULT 0.0,
54                   limitby VARCHAR(30) DEFAULT 'quota',
55                   description TEXT,
56                   overcharge FLOAT NOT NULL DEFAULT 1.0) TYPE=INNODB;
57                   
58--
59-- Create the groups table
60--
61CREATE TABLE groups (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
62                    groupname VARCHAR(255) UNIQUE NOT NULL,
63                    description TEXT,
64                    limitby VARCHAR(30) DEFAULT 'quota') TYPE=INNODB;
65                   
66--
67-- Create the printers table
68--
69CREATE TABLE printers (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
70                      printername VARCHAR(255) UNIQUE NOT NULL,
71                      description TEXT,
72                      priceperpage FLOAT DEFAULT 0.0,
73                      priceperjob FLOAT DEFAULT 0.0,
74                      passthrough ENUM('t','f') DEFAULT 'f',
75                      maxjobsize INT4) TYPE=INNODB;
76                   
77--
78-- Create the print quota table for users
79--
80CREATE TABLE userpquota (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
81                        userid INT4, 
82                        printerid INT4, 
83                        lifepagecounter INT4 DEFAULT 0,
84                        pagecounter INT4 DEFAULT 0,
85                        softlimit INT4,
86                        hardlimit INT4,
87                        datelimit TIMESTAMP,
88                        maxjobsize INT4,
89                        warncount INT4 DEFAULT 0, 
90                        FOREIGN KEY (userid) REFERENCES users(id),
91                        FOREIGN KEY (printerid) REFERENCES printers(id)) 
92                        TYPE=INNODB;
93CREATE INDEX userpquota_u_id_ix ON userpquota (userid);
94CREATE INDEX userpquota_p_id_ix ON userpquota (printerid);
95CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid);
96                       
97--
98-- Create the job history table
99--
100CREATE TABLE jobhistory(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
101                        jobid TEXT,
102                        userid INT4,
103                        printerid INT4,
104                        pagecounter INT4 DEFAULT 0,
105                        jobsizebytes INT8,
106                        jobsize INT4,
107                        jobprice FLOAT,
108                        action TEXT,
109                        filename TEXT,
110                        title TEXT,
111                        copies INT4,
112                        options TEXT,
113                        hostname VARCHAR(255),
114                        md5sum TEXT,
115                        pages TEXT,
116                        billingcode TEXT,
117                        precomputedjobsize INT4,
118                        precomputedjobprice FLOAT,
119                        jobdate TIMESTAMP DEFAULT,
120                        CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota(userid, printerid)) TYPE=INNODB;
121CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid);
122CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid);
123CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate);
124CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname);
125                       
126--
127-- Create the print quota table for groups
128--
129CREATE TABLE grouppquota(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
130                         groupid INT4, 
131                         printerid INT4,
132                         softlimit INT4,
133                         hardlimit INT4,
134                         maxjobsize INT4,
135                         datelimit TIMESTAMP,
136                         FOREIGN KEY (groupid) REFERENCES groups(id),
137                         FOREIGN KEY (printerid) REFERENCES printers(id))
138                         TYPE=INNODB;
139CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid);
140CREATE INDEX grouppquota_p_id_ix ON grouppquota (printerid);
141CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid);
142                       
143--                         
144-- Create the groups/members relationship
145--
146CREATE TABLE groupsmembers(groupid INT4,
147                           userid INT4,
148                           FOREIGN KEY (groupid) REFERENCES groups(id),
149                           FOREIGN KEY (userid) REFERENCES users(id),
150                           PRIMARY KEY (groupid, userid)) TYPE=INNODB;
151                           
152--                         
153-- Create the printer groups relationship
154--
155CREATE TABLE printergroupsmembers(groupid INT4,
156                           printerid INT4,
157                           FOREIGN KEY (groupid) REFERENCES groups(id),
158                           FOREIGN KEY (printerid) REFERENCES printers(id),
159                           PRIMARY KEY (groupid, printerid)) TYPE=INNODB;
160--
161-- Create the table for payments
162--
163CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
164                       userid INT4,
165                       amount FLOAT,
166                       description TEXT,
167                       date TIMESTAMP DEFAULT now(),
168                       FOREIGN KEY (userid) REFERENCES users(id)) TYPE=INNODB;
169CREATE INDEX payments_date_ix ON payments (date);
170
171--
172-- Create the table for coefficients wrt paper sizes and the like
173--
174CREATE TABLE coefficients (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
175                           printerid INT4 NOT NULL,
176                           label VARCHAR(255) NOT NULL,
177                           coefficient FLOAT DEFAULT 1.0,
178                           FOREIGN KEY (printerid) REFERENCES printers(id),
179                           CONSTRAINT coeffconstraint UNIQUE (printerid, label));
180
181--
182-- Create the table for the billing codes
183--
184CREATE TABLE billingcodes (id INT4 PRIMARY KEY NOT NULL,
185                           billingcode VARCHAR(255) UNIQUE NOT NULL,
186                           description TEXT,
187                           balance FLOAT DEFAULT 0.0,
188                           pagecounter INT4 DEFAULT 0) TYPE=INNODB;
189--                       
190-- Set some ACLs                       
191--
192GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'localhost';
193GRANT SELECT ON `pykota`.* TO 'pykotauser'@'localhost';
Note: See TracBrowser for help on using the browser.