root / pykota / trunk / initscripts / sqlite / pykota-sqlite.sql @ 3549

Revision 3549, 5.9 kB (checked in by jerome, 14 years ago)

Removed support for the MaxJobSize? attribute for users group print quota
entries : I couldn't see a real use for this at the moment, and it would
complexify the code. This support might reappear later however. Added full
support for the MaxJobSize? attribute for user print quota entries,
editable with edpykota's new --maxjobsize command line switch. Changed
the internal handling of the MaxJobSize? attribute for printers :
internally 0 used to mean unlimited, it now allows one to forbid
printing onto a particular printer. The database upgrade script (only
for PostgreSQL) takes care of this.
IMPORTANT : the database schema changes. A database upgrade script is
provided for PostgreSQL only. The LDAP schema doesn't change to not
break any existing LDAP directory, so the pykotaMaxJobSize attribute is
still allowed on group print quota entries, but never used.
Seems to work as expected, for a change :-)
Fixes #15.

  • Property svn:keywords set to Author Date Id Revision
Line 
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--
32CREATE 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--
44CREATE 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--
52CREATE 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--
63CREATE 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);
73CREATE INDEX userpquota_u_id_ix ON userpquota (userid);
74CREATE INDEX userpquota_p_id_ix ON userpquota (printerid);
75CREATE UNIQUE INDEX userpquota_up_id_ix ON userpquota (userid, printerid);
76
77--
78-- Create the job history table
79--
80CREATE 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));
101CREATE INDEX jobhistory_u_id_ix ON jobhistory (userid);
102CREATE INDEX jobhistory_p_id_ix ON jobhistory (printerid);
103CREATE INDEX jobhistory_pd_id_ix ON jobhistory (printerid, jobdate);
104CREATE INDEX jobhistory_hostname_ix ON jobhistory (hostname);
105
106--
107-- Create the print quota table for groups
108--
109CREATE 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);
115CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid);
116CREATE INDEX grouppquota_p_id_ix ON grouppquota (printerid);
117CREATE UNIQUE INDEX grouppquota_up_id_ix ON grouppquota (groupid, printerid);
118
119--
120-- Create the groups/members relationship
121--
122CREATE 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--
129CREATE 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--
135CREATE 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);
140CREATE INDEX payments_date_ix ON payments (date);
141
142--
143-- Create the table for coefficients wrt paper sizes and the like
144--
145CREATE 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--
154CREATE 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);
Note: See TracBrowser for help on using the browser.