1 | -- |
---|
2 | -- PyKota - Print Quotas for CUPS |
---|
3 | -- |
---|
4 | -- (c) 2003-2009 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 SQLite |
---|
24 | -- |
---|
25 | -- Launch this with sqlite with the .read command |
---|
26 | -- |
---|
27 | |
---|
28 | |
---|
29 | -- |
---|
30 | -- Create the users table |
---|
31 | -- |
---|
32 | CREATE TABLE users(id INTEGER PRIMARY KEY NOT NULL, |
---|
33 | username TEXT UNIQUE NOT NULL, |
---|
34 | email TEXT, |
---|
35 | balance FLOAT DEFAULT 0.0, |
---|
36 | lifetimepaid FLOAT DEFAULT 0.0, |
---|
37 | limitby TEXT DEFAULT 'quota', |
---|
38 | description TEXT, |
---|
39 | overcharge FLOAT NOT NULL DEFAULT 1.0); |
---|
40 | |
---|
41 | -- |
---|
42 | -- Create the groups table |
---|
43 | -- |
---|
44 | CREATE TABLE groups(id INTEGER PRIMARY KEY NOT NULL, |
---|
45 | groupname TEXT UNIQUE NOT NULL, |
---|
46 | description TEXT, |
---|
47 | limitby TEXT DEFAULT 'quota'); |
---|
48 | |
---|
49 | -- |
---|
50 | -- Create the printers table |
---|
51 | -- |
---|
52 | CREATE TABLE printers(id INTEGER PRIMARY KEY NOT NULL, |
---|
53 | printername TEXT UNIQUE NOT NULL, |
---|
54 | description TEXT, |
---|
55 | priceperpage FLOAT DEFAULT 0.0, |
---|
56 | priceperjob FLOAT DEFAULT 0.0, |
---|
57 | passthrough BOOLEAN DEFAULT FALSE, |
---|
58 | maxjobsize INT4); |
---|
59 | |
---|
60 | -- |
---|
61 | -- Create the print quota table for users |
---|
62 | -- |
---|
63 | CREATE TABLE userpquota(id INTEGER PRIMARY KEY NOT NULL, |
---|
64 | userid INT4 REFERENCES users(id), |
---|
65 | printerid INT4 REFERENCES printers(id), |
---|
66 | lifepagecounter INT4 DEFAULT 0, |
---|
67 | pagecounter INT4 DEFAULT 0, |
---|
68 | softlimit INT4, |
---|
69 | hardlimit INT4, |
---|
70 | datelimit TEXT, |
---|
71 | maxjobsize INT4, |
---|
72 | warncount INT4 DEFAULT 0); |
---|
73 | CREATE INDEX userpquota_u_id_ix ON userpquota (userid); |
---|
74 | CREATE INDEX userpquota_p_id_ix ON userpquota (printerid); |
---|
75 | CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid); |
---|
76 | |
---|
77 | -- |
---|
78 | -- Create the job history table |
---|
79 | -- |
---|
80 | CREATE TABLE jobhistory(id INTEGER PRIMARY KEY NOT NULL, |
---|
81 | jobid TEXT, |
---|
82 | userid INT4, |
---|
83 | printerid INT4, |
---|
84 | pagecounter INT4 DEFAULT 0, |
---|
85 | jobsizebytes INT8, |
---|
86 | jobsize INT4, |
---|
87 | jobprice FLOAT, |
---|
88 | action TEXT, |
---|
89 | filename TEXT, |
---|
90 | title TEXT, |
---|
91 | copies INT4, |
---|
92 | options TEXT, |
---|
93 | hostname TEXT, |
---|
94 | md5sum TEXT, |
---|
95 | pages TEXT, |
---|
96 | billingcode TEXT, |
---|
97 | precomputedjobsize INT4, |
---|
98 | precomputedjobprice FLOAT, |
---|
99 | jobdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
---|
100 | CONSTRAINT checkUserPQuota FOREIGN KEY (userid, printerid) REFERENCES userpquota(userid, printerid)); |
---|
101 | CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid); |
---|
102 | CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid); |
---|
103 | CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate); |
---|
104 | CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname); |
---|
105 | |
---|
106 | -- |
---|
107 | -- Create the print quota table for groups |
---|
108 | -- |
---|
109 | CREATE TABLE grouppquota(id INTEGER PRIMARY KEY NOT NULL, |
---|
110 | groupid INT4 REFERENCES groups(id), |
---|
111 | printerid INT4 REFERENCES printers(id), |
---|
112 | softlimit INT4, |
---|
113 | hardlimit INT4, |
---|
114 | datelimit TEXT); |
---|
115 | CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid); |
---|
116 | CREATE INDEX grouppquota_p_id_ix ON grouppquota (printerid); |
---|
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 INTEGER PRIMARY KEY NOT NULL, |
---|
136 | userid INT4 REFERENCES users(id), |
---|
137 | amount FLOAT, |
---|
138 | description TEXT, |
---|
139 | date TIMESTAMP DEFAULT CURRENT_TIMESTAMP); |
---|
140 | CREATE INDEX payments_date_ix ON payments (date); |
---|
141 | |
---|
142 | -- |
---|
143 | -- Create the table for coefficients wrt paper sizes and the like |
---|
144 | -- |
---|
145 | CREATE TABLE coefficients (id INTEGER PRIMARY KEY NOT NULL, |
---|
146 | printerid INTEGER NOT NULL REFERENCES printers(id), |
---|
147 | label TEXT NOT NULL, |
---|
148 | coefficient FLOAT DEFAULT 1.0, |
---|
149 | CONSTRAINT coeffconstraint UNIQUE (printerid, label)); |
---|
150 | |
---|
151 | -- |
---|
152 | -- Create the table for the billing codes |
---|
153 | -- |
---|
154 | CREATE TABLE billingcodes (id INTEGER PRIMARY KEY NOT NULL, |
---|
155 | billingcode TEXT UNIQUE NOT NULL, |
---|
156 | description TEXT, |
---|
157 | balance FLOAT DEFAULT 0.0, |
---|
158 | pagecounter INT4 DEFAULT 0); |
---|