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

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

Make the quota table IDs INT8 (bigint) so that we never run out if there get to be lots of printers and/or users

  • 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 INT8 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 now(),
120                        CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota (userid, printerid)
121                        ) TYPE=INNODB;
122CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid);
123CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid);
124CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate);
125CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname);
126                       
127--
128-- Create the print quota table for groups
129--
130CREATE TABLE grouppquota(id INT8 PRIMARY KEY NOT NULL AUTO_INCREMENT,
131                         groupid INT4, 
132                         printerid INT4,
133                         softlimit INT4,
134                         hardlimit INT4,
135                         maxjobsize INT4,
136                         datelimit TIMESTAMP,
137                         FOREIGN KEY (groupid) REFERENCES groups(id),
138                         FOREIGN KEY (printerid) REFERENCES printers(id))
139                         TYPE=INNODB;
140CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid);
141CREATE INDEX grouppquota_p_id_ix ON grouppquota (printerid);
142CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid);
143                       
144--                         
145-- Create the groups/members relationship
146--
147CREATE TABLE groupsmembers(groupid INT4,
148                           userid INT4,
149                           FOREIGN KEY (groupid) REFERENCES groups(id),
150                           FOREIGN KEY (userid) REFERENCES users(id),
151                           PRIMARY KEY (groupid, userid)) TYPE=INNODB;
152                           
153--                         
154-- Create the printer groups relationship
155--
156CREATE TABLE printergroupsmembers(groupid INT4,
157                           printerid INT4,
158                           FOREIGN KEY (groupid) REFERENCES groups(id),
159                           FOREIGN KEY (printerid) REFERENCES printers(id),
160                           PRIMARY KEY (groupid, printerid)) TYPE=INNODB;
161--
162-- Create the table for payments
163--
164CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
165                       userid INT4,
166                       amount FLOAT,
167                       description TEXT,
168                       date TIMESTAMP DEFAULT now(),
169                       FOREIGN KEY (userid) REFERENCES users(id)) TYPE=INNODB;
170CREATE INDEX payments_date_ix ON payments (date);
171
172--
173-- Create the table for coefficients wrt paper sizes and the like
174--
175CREATE TABLE coefficients (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
176                           printerid INT4 NOT NULL,
177                           label VARCHAR(255) NOT NULL,
178                           coefficient FLOAT DEFAULT 1.0,
179                           FOREIGN KEY (printerid) REFERENCES printers(id),
180                           CONSTRAINT coeffconstraint UNIQUE (printerid, label)
181                           ) TYPE=INNODB;
182
183--
184-- Create the table for the billing codes
185--
186CREATE TABLE billingcodes (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
187                           billingcode VARCHAR(255) UNIQUE NOT NULL,
188                           description TEXT,
189                           balance FLOAT DEFAULT 0.0,
190                           pagecounter INT4 DEFAULT 0) TYPE=INNODB;
191--                       
192-- Set some ACLs                       
193--
194GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'localhost';
195GRANT SELECT ON `pykota`.* TO 'pykotauser'@'localhost';
Note: See TracBrowser for help on using the browser.