1 | -- |
---|
2 | -- PyKota - Print Quotas for CUPS and LPRng |
---|
3 | -- |
---|
4 | -- (c) 2003-2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
18 | -- |
---|
19 | -- $Id$ |
---|
20 | -- |
---|
21 | -- $Log$ |
---|
22 | -- Revision 1.1 2004/06/20 19:14:20 jalet |
---|
23 | -- Added first draft of MySQL initialization script |
---|
24 | -- |
---|
25 | -- |
---|
26 | -- |
---|
27 | |
---|
28 | -- |
---|
29 | -- PyKota Database creation script for MySQL |
---|
30 | -- |
---|
31 | -- Launch this as MySQL administrator with \. |
---|
32 | -- |
---|
33 | |
---|
34 | |
---|
35 | -- |
---|
36 | -- Create the print quota database |
---|
37 | -- |
---|
38 | |
---|
39 | -- |
---|
40 | -- Create the print quota database users |
---|
41 | -- |
---|
42 | -- TODO : CREATE USER pykotaadmin; |
---|
43 | -- TODO : CREATE USER pykotauser; |
---|
44 | |
---|
45 | -- |
---|
46 | -- Now connect to the new database |
---|
47 | -- |
---|
48 | \u pykota |
---|
49 | |
---|
50 | -- |
---|
51 | -- Create the users table |
---|
52 | -- |
---|
53 | CREATE TABLE users(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
54 | username VARCHAR(255) UNIQUE NOT NULL, |
---|
55 | email TEXT, |
---|
56 | balance FLOAT DEFAULT 0.0, |
---|
57 | lifetimepaid FLOAT DEFAULT 0.0, |
---|
58 | limitby VARCHAR(30) DEFAULT 'quota'); |
---|
59 | |
---|
60 | -- |
---|
61 | -- Create the groups table |
---|
62 | -- |
---|
63 | CREATE TABLE groups(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
64 | groupname VARCHAR(255) UNIQUE NOT NULL, |
---|
65 | limitby VARCHAR(30) DEFAULT 'quota'); |
---|
66 | |
---|
67 | -- |
---|
68 | -- Create the printers table |
---|
69 | -- |
---|
70 | CREATE 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 | |
---|
76 | -- |
---|
77 | -- Create the print quota table for users |
---|
78 | -- |
---|
79 | CREATE TABLE userpquota(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
80 | userid INT4 REFERENCES users(id), |
---|
81 | printerid INT4 REFERENCES printers(id), |
---|
82 | lifepagecounter INT4 DEFAULT 0, |
---|
83 | pagecounter INT4 DEFAULT 0, |
---|
84 | softlimit INT4, |
---|
85 | hardlimit INT4, |
---|
86 | datelimit TIMESTAMP); |
---|
87 | CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); |
---|
88 | |
---|
89 | -- |
---|
90 | -- Create the job history table |
---|
91 | -- |
---|
92 | CREATE TABLE jobhistory(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
93 | jobid TEXT, |
---|
94 | userid INT4, |
---|
95 | printerid INT4, |
---|
96 | pagecounter INT4 DEFAULT 0, |
---|
97 | jobsizebytes INT8, |
---|
98 | jobsize INT4, |
---|
99 | jobprice FLOAT, |
---|
100 | action TEXT, |
---|
101 | filename TEXT, |
---|
102 | title TEXT, |
---|
103 | copies INT4, |
---|
104 | options TEXT, |
---|
105 | hostname VARCHAR(255), |
---|
106 | jobdate TIMESTAMP, |
---|
107 | CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) |
---|
108 | REFERENCES userpquota(userid, printerid)); |
---|
109 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
110 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
111 | CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); |
---|
112 | |
---|
113 | -- |
---|
114 | -- Create the print quota table for groups |
---|
115 | -- |
---|
116 | CREATE TABLE grouppquota(id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
117 | groupid INT4 REFERENCES groups(id), |
---|
118 | printerid INT4 REFERENCES printers(id), |
---|
119 | softlimit INT4, |
---|
120 | hardlimit INT4, |
---|
121 | datelimit TIMESTAMP); |
---|
122 | CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid); |
---|
123 | |
---|
124 | -- |
---|
125 | -- Create the groups/members relationship |
---|
126 | -- |
---|
127 | CREATE TABLE groupsmembers(groupid INT4 REFERENCES groups(id), |
---|
128 | userid INT4 REFERENCES users(id), |
---|
129 | PRIMARY KEY (groupid, userid)); |
---|
130 | |
---|
131 | -- |
---|
132 | -- Create the printer groups relationship |
---|
133 | -- |
---|
134 | CREATE TABLE printergroupsmembers(groupid INT4 REFERENCES printers(id), |
---|
135 | printerid INT4 REFERENCES printers(id), |
---|
136 | PRIMARY KEY (groupid, printerid)); |
---|
137 | -- |
---|
138 | -- Create the table for payments |
---|
139 | -- |
---|
140 | CREATE TABLE payments (id INT4 PRIMARY KEY NOT NULL AUTO_INCREMENT, |
---|
141 | userid INT4 REFERENCES users(id), |
---|
142 | amount FLOAT, |
---|
143 | date TIMESTAMP DEFAULT now()); |
---|
144 | CREATE INDEX payments_date_ix ON payments (date); |
---|
145 | |
---|
146 | -- |
---|
147 | -- Set some ACLs |
---|
148 | -- |
---|
149 | -- TODO : REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments FROM public; |
---|
150 | -- 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; |
---|
151 | |
---|
152 | -- TODO : GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotaadmin; |
---|
153 | -- 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; |
---|
154 | -- TODO : GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, printergroupsmembers, jobhistory, payments TO pykotauser; |
---|