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

Revision 3561, 8.0 kB (checked in by jerome, 11 years ago)

Changed copyright years.

  • 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-2013 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                         datelimit DATETIME,
144                         INDEX (groupid),
145                         FOREIGN KEY (groupid) REFERENCES groups(id),
146                         INDEX (printerid),
147                         FOREIGN KEY (printerid) REFERENCES printers(id))
148                         TYPE=INNODB;
149CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid);
150
151--
152-- Create the groups/members relationship
153--
154CREATE TABLE groupsmembers(groupid INT4 NOT NULL,
155                           userid INT4 NOT NULL,
156                           INDEX (groupid),
157                           FOREIGN KEY (groupid) REFERENCES groups(id),
158                           INDEX (userid),
159                           FOREIGN KEY (userid) REFERENCES users(id),
160                           PRIMARY KEY (groupid, userid)) TYPE=INNODB;
161
162--
163-- Create the printer groups relationship
164--
165CREATE TABLE printergroupsmembers(groupid INT4 NOT NULL,
166                           printerid INT4 NOT NULL,
167                           INDEX (groupid),
168                           FOREIGN KEY (groupid) REFERENCES printers(id),
169                           INDEX (printerid),
170                           FOREIGN KEY (printerid) REFERENCES printers(id),
171                           PRIMARY KEY (groupid, printerid)) TYPE=INNODB;
172--
173-- Create the table for payments
174--
175CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
176                       userid INT4,
177                       amount FLOAT,
178                       description TEXT,
179                       date TIMESTAMP,
180                       INDEX (userid),
181                       FOREIGN KEY (userid) REFERENCES users(id)) TYPE=INNODB;
182CREATE INDEX payments_date_ix ON payments (date);
183
184--
185-- Create the table for coefficients wrt paper sizes and the like
186--
187CREATE TABLE coefficients (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
188                           printerid INT4 NOT NULL,
189                           label VARCHAR(255) NOT NULL,
190                           coefficient FLOAT DEFAULT 1.0,
191                           INDEX (printerid),
192                           FOREIGN KEY (printerid) REFERENCES printers(id),
193                           CONSTRAINT coeffconstraint UNIQUE (printerid, label)
194                           ) TYPE=INNODB;
195
196--
197-- Create the table for the billing codes
198--
199CREATE TABLE billingcodes (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT,
200                           billingcode VARCHAR(255) UNIQUE NOT NULL,
201                           description TEXT,
202                           balance FLOAT DEFAULT 0.0,
203                           pagecounter INT4 DEFAULT 0) TYPE=INNODB;
204--
205-- Set some ACLs
206--
207GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'localhost';
208GRANT SELECT ON `pykota`.* TO 'pykotauser'@'localhost';
209
210--
211-- If necessary activate the lines below (and keep the preceding ones
212-- activated at the same time)
213--
214-- GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON `pykota`.* TO 'pykotaadmin'@'%';
215-- GRANT SELECT ON `pykota`.* TO 'pykotauser'@'%';
Note: See TracBrowser for help on using the browser.