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

Revision 2866, 7.9 kB (checked in by matt, 18 years ago)

Syntax corrections to work on older versions of MySQL. Should work on >= 3.22.44, 4.0.x and 4.1.x now.

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