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

Revision 3413, 8.1 kB (checked in by jerome, 16 years ago)

Removed unnecessary spaces at EOL.

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