root / pykota / trunk / initscripts / sqlite / pykota.sqlite @ 2622

Revision 2622, 6.2 kB (checked in by jerome, 18 years ago)

Added 2006 to the copyright's years.

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