1 | -- |
---|
2 | -- PyKota - Print Quotas for CUPS and LPRng |
---|
3 | -- |
---|
4 | -- (c) 2003, 2004, 2005 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 | -- |
---|
33 | |
---|
34 | -- |
---|
35 | -- Create the print quota database users |
---|
36 | -- |
---|
37 | -- TODO : CREATE USER pykotaadmin; |
---|
38 | -- TODO : CREATE USER pykotauser; |
---|
39 | |
---|
40 | -- |
---|
41 | -- Now connect to the new database |
---|
42 | -- |
---|
43 | \u pykota |
---|
44 | |
---|
45 | -- |
---|
46 | -- Create the users table |
---|
47 | -- |
---|
48 | CREATE TABLE users(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
49 | username VARCHAR(255) UNIQUE NOT NULL, |
---|
50 | email TEXT, |
---|
51 | balance FLOAT DEFAULT 0.0, |
---|
52 | lifetimepaid FLOAT DEFAULT 0.0, |
---|
53 | limitby VARCHAR(30) DEFAULT 'quota'); |
---|
54 | |
---|
55 | -- |
---|
56 | -- Create the groups table |
---|
57 | -- |
---|
58 | CREATE TABLE groups(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
59 | groupname VARCHAR(255) UNIQUE NOT NULL, |
---|
60 | limitby VARCHAR(30) DEFAULT 'quota'); |
---|
61 | |
---|
62 | -- |
---|
63 | -- Create the printers table |
---|
64 | -- |
---|
65 | CREATE TABLE printers(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
66 | printername VARCHAR(255) UNIQUE NOT NULL, |
---|
67 | description TEXT, |
---|
68 | priceperpage FLOAT DEFAULT 0.0, |
---|
69 | priceperjob FLOAT DEFAULT 0.0); |
---|
70 | |
---|
71 | -- |
---|
72 | -- Create the print quota table for users |
---|
73 | -- |
---|
74 | CREATE TABLE userpquota(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
75 | userid INT4 REFERENCES users(id), |
---|
76 | printerid INT4 REFERENCES printers(id), |
---|
77 | lifepagecounter INT4 DEFAULT 0, |
---|
78 | pagecounter INT4 DEFAULT 0, |
---|
79 | softlimit INT4, |
---|
80 | hardlimit INT4, |
---|
81 | datelimit TIMESTAMP); |
---|
82 | CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); |
---|
83 | |
---|
84 | -- |
---|
85 | -- Create the job history table |
---|
86 | -- |
---|
87 | CREATE TABLE jobhistory(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
88 | jobid TEXT, |
---|
89 | userid INT4, |
---|
90 | printerid INT4, |
---|
91 | pagecounter INT4 DEFAULT 0, |
---|
92 | jobsizebytes INT8, |
---|
93 | jobsize INT4, |
---|
94 | jobprice FLOAT, |
---|
95 | action TEXT, |
---|
96 | filename TEXT, |
---|
97 | title TEXT, |
---|
98 | copies INT4, |
---|
99 | options TEXT, |
---|
100 | hostname VARCHAR(255), |
---|
101 | jobdate TIMESTAMP, |
---|
102 | CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) |
---|
103 | REFERENCES userpquota(userid, printerid)); |
---|
104 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
105 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
106 | CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); |
---|
107 | |
---|
108 | -- |
---|
109 | -- Create the print quota table for groups |
---|
110 | -- |
---|
111 | CREATE TABLE grouppquota(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
112 | groupid INT4 REFERENCES groups(id), |
---|
113 | printerid INT4 REFERENCES printers(id), |
---|
114 | softlimit INT4, |
---|
115 | hardlimit INT4, |
---|
116 | datelimit TIMESTAMP); |
---|
117 | CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); |
---|
118 | |
---|
119 | -- |
---|
120 | -- Create the groups/members relationship |
---|
121 | -- |
---|
122 | CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id), |
---|
123 | userid INT4 REFERENCES users(id), |
---|
124 | PRIMARY KEY (groupid, userid)); |
---|
125 | |
---|
126 | -- |
---|
127 | -- Create the printer groups relationship |
---|
128 | -- |
---|
129 | CREATE TABLE printergroupsmembers(groupid INT4 REFERENCES printers(id), |
---|
130 | printerid INT4 REFERENCES printers(id), |
---|
131 | PRIMARY KEY (groupid, printerid)); |
---|
132 | -- |
---|
133 | -- Create the table for payments |
---|
134 | -- |
---|
135 | CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
136 | userid INT4 REFERENCES users(id), |
---|
137 | amount FLOAT, |
---|
138 | date TIMESTAMP DEFAULT now()); |
---|
139 | CREATE INDEX payments_date_ix ON payments (date); |
---|
140 | |
---|
141 | -- |
---|
142 | -- Set some ACLs |
---|
143 | -- |
---|
144 | -- TODO : REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments FROM public; |
---|
145 | -- TODO : REVOKE ALL ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq, payments_id_seq FROM public; |
---|
146 | |
---|
147 | -- TODO : GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotaadmin; |
---|
148 | -- TODO : GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq, payments_id_seq TO pykotaadmin; |
---|
149 | -- TODO : GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotauser; |
---|