Develop and Download Open Source Software

Browse Subversion Repository

Contents of /setup_database.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 43 - (show annotations) (download) (as text)
Mon Mar 22 18:14:07 2010 UTC (14 years, 2 months ago) by berupon
File MIME type: application/x-httpd-php
File size: 7195 byte(s)
indent変更
1 <?php
2
3 // Copyright (c) 2009 Katsuhisa Yuasa <berupon [at] gmail.com>
4 // License http://www.opensource.org/licenses/mit-license.html
5
6 require_once 'config.php';
7 require_once 'common.php';
8
9 $con = openDatabase(DB_PATH);
10
11 // check if tables exist
12
13 // check database signature and version
14
15 // create tables
16
17 if (!pdo_sqlite_isTableExists($con, 'test')) {
18
19 $sql =
20 <<<SQL
21 CREATE TABLE test(
22 id INTEGER,
23 number INTEGER,
24 name TEXT
25 );
26 SQL;
27
28 $con->query($sql);
29 }
30
31 function createTableIfNotExists($con, $tableName, $sql) {
32 if (!pdo_sqlite_isTableExists($con, $tableName)) {
33 $con->query($sql);
34 }
35 }
36
37 $sql =
38 <<<SQL
39 CREATE TABLE user(
40 serial INTEGER PRIMARY KEY,
41 id TEXT UNIQUE NOT NULL,
42 password TEXT NOT NULL,
43 role_serial INTEGER,
44 name TEXT,
45 sales_code TEXT UNIQUE,
46 tel TEXT,
47 email TEXT,
48 url TEXT,
49 status INTEGER,
50 slip_count INTEGER NOT NULL DEFAULT 0
51 );
52 SQL;
53 createTableIfNotExists($con, 'user', $sql);
54
55 $sql =
56 <<<SQL
57 CREATE TABLE role(
58 serial INTEGER PRIMARY KEY,
59 name TEXT UNIQUE NOT NULL,
60 desc TEXT NOT NULL,
61 seq INTEGER NOT NULL
62 );
63 SQL;
64 createTableIfNotExists($con, 'role', $sql);
65
66 $sql =
67 <<<SQL
68 CREATE TABLE privilege(
69 serial INTEGER PRIMARY KEY,
70 id TEXT UNIQUE NOT NULL,
71 name TEXT UNIQUE NOT NULL,
72 desc TEXT NOT NULL
73 );
74 SQL;
75 createTableIfNotExists($con, 'privilege', $sql);
76 $con->exec("
77 INSERT INTO privilege(id, name, desc) VALUES('Master/Item', '���������������������������', '���������������������������������������������������������������������������������������');
78 INSERT INTO privilege(id, name, desc) VALUES('Master/Office', '������������������������������', '���������������������������������������������������������������������������������������������');
79 INSERT INTO privilege(id, name, desc) VALUES('Master/User', '���������������������������������', '���������������������������������������������������������������������������������������');
80 INSERT INTO privilege(id, name, desc) VALUES('Slip', '������������', '������������������������������������������������������������������������������');
81 INSERT INTO privilege(id, name, desc) VALUES('Inventory', '���������', '���������������������������������������������������������������������������������');
82 INSERT INTO privilege(id, name, desc) VALUES('Database', '������������������', '���������������������������������������������������������������������');
83 ");
84
85 $sql =
86 <<<SQL
87 CREATE TABLE role_privilege(
88 role_serial INTEGER,
89 privilege_serial INTEGER,
90 PRIMARY KEY(role_serial, privilege_serial)
91 );
92 SQL;
93 createTableIfNotExists($con, 'role_privilege', $sql);
94
95 $sql =
96 <<<SQL
97 CREATE TABLE key_value(
98 type INTEGER,
99 key INTEGER,
100 value TEXT,
101 PRIMARY KEY(type, key)
102 );
103 SQL;
104 createTableIfNotExists($con, 'key_value', $sql);
105
106 // http://www.clio.ne.jp/home/kimtaq/YOUGO/JIS.HTML
107 // key ��� JIS���������(JIS X 0401)
108 $JAPAN_PREFECTURES = array(
109 1 => '���������',
110 2 => '���������',
111 3 => '���������',
112 4 => '���������',
113 5 => '���������',
114 6 => '���������',
115 7 => '���������',
116 8 => '���������',
117 9 => '���������',
118 10 => '���������',
119 11 => '���������',
120 12 => '���������',
121 13 => '���������',
122 14 => '������������',
123 15 => '���������',
124 16 => '���������',
125 17 => '���������',
126 18 => '���������',
127 19 => '���������',
128 20 => '���������',
129 21 => '���������',
130 22 => '���������',
131 23 => '���������',
132 24 => '���������',
133 25 => '���������',
134 26 => '���������',
135 27 => '���������',
136 28 => '���������',
137 29 => '���������',
138 30 => '������������',
139 31 => '���������',
140 32 => '���������',
141 33 => '���������',
142 34 => '���������',
143 35 => '���������',
144 36 => '���������',
145 37 => '���������',
146 38 => '���������',
147 39 => '���������',
148 40 => '���������',
149 41 => '���������',
150 42 => '���������',
151 43 => '���������',
152 44 => '���������',
153 45 => '���������',
154 46 => '������������',
155 47 => '���������',
156 );
157
158 $sql = 'INSERT INTO key_value(type, key, value) VALUES(0, :key, :value);';
159 $stmt = conPrepare($con, $sql);
160 foreach ($JAPAN_PREFECTURES as $key => $value) {
161 statementBindValue($stmt, ':key', $key);
162 statementBindValue($stmt, ':value', $value);
163 $stmt->execute();
164 $stmt->closeCursor();
165 }
166
167 $sql =
168 <<<SQL
169 INSERT INTO key_value(type, key, value) VALUES(1, 1<<0, '���������');
170 INSERT INTO key_value(type, key, value) VALUES(1, 1<<1, '������');
171
172 INSERT INTO key_value(type, key, value) VALUES(2, 1<<0, '������');
173 INSERT INTO key_value(type, key, value) VALUES(2, 1<<1, '������');
174 SQL;
175 $con->exec($sql);
176
177 $sql =
178 <<<SQL
179 CREATE TABLE office(
180 serial INTEGER PRIMARY KEY,
181 code TEXT,
182 category_serial INTEGER,
183 type int,
184 name TEXT NOT NULL,
185 short_name TEXT,
186 tel TEXT,
187 fax TEXT,
188 address TEXT,
189 zipcode TEXT,
190 prefecture INTEGER,
191 email TEXT,
192 url TEXT
193 );
194 SQL;
195 createTableIfNotExists($con, 'office', $sql);
196
197 $sql =
198 <<<SQL
199 CREATE TABLE office_category(
200 serial INTEGER PRIMARY KEY,
201 name TEXT UNIQUE NOT NULL,
202 seq INTEGER NOT NULL
203 );
204 SQL;
205 createTableIfNotExists($con, 'office_category', $sql);
206
207 $sql =
208 <<<SQL
209 CREATE TABLE item_category(
210 serial INTEGER PRIMARY KEY,
211 name TEXT,
212 path TEXT UNIQUE,
213 counting_type TEXT
214 );
215 SQL;
216 createTableIfNotExists($con, 'item_category', $sql);
217
218 $sql =
219 <<<SQL
220 CREATE TABLE item_category_attributes(
221 item_category_serial INTEGER,
222 num INTEGER,
223 name TEXT,
224 counting_type TEXT,
225 PRIMARY KEY(item_category_serial, num)
226 );
227 SQL;
228 createTableIfNotExists($con, 'item_category_attributes', $sql);
229
230 $sql =
231 <<<SQL
232 CREATE TABLE item_info(
233 serial INTEGER PRIMARY KEY,
234 code TEXT,
235 category_serial INTEGER,
236 supply_name TEXT,
237 supply_model_number TEXT,
238 product_name TEXT,
239 product_model_number TEXT,
240 attribute1 TEXT,
241 attribute2 TEXT,
242 attribute3 TEXT,
243 attribute4 TEXT,
244 counting_type TEXT
245 );
246 SQL;
247 createTableIfNotExists($con, 'item_info', $sql);
248
249 $sql =
250 <<<SQL
251 CREATE TABLE relation(
252 type INTEGER,
253 first INTEGER,
254 second TEXT
255 );
256 CREATE UNIQUE INDEX index_relation_type_first_second ON relation (type, first, second);
257 SQL;
258 createTableIfNotExists($con, 'relation', $sql);
259
260 $sql =
261 <<<SQL
262 CREATE TABLE slip(
263 serial INTEGER PRIMARY KEY,
264 type INTEGER,
265 code TEXT,
266 slip_date INTEGER,
267 order_name TEXT,
268 warehouse_serial INTEGER,
269 supplier_serial INTEGER,
270 delivery_period INTEGER,
271 total_price INTEGER
272 );
273 SQL;
274 createTableIfNotExists($con, 'slip', $sql);
275
276 $sql =
277 <<<SQL
278 CREATE TABLE slip_item(
279 slip_serial INTEGER,
280 item_info_serial INTEGER,
281 supply_name TEXT,
282 product_name TEXT,
283 count INTEGER,
284 unit_price INTEGER,
285 remarks TEXT,
286 PRIMARY KEY(slip_serial, item_info_serial)
287 );
288 SQL;
289 createTableIfNotExists($con, 'slip_item', $sql);
290
291 $sql =
292 <<<SQL
293 CREATE TABLE slip_item_breakdown(
294 item_info_serial INTEGER,
295 dispatching_slip_serial INTEGER,
296 entering_slip_serial INTEGER,
297 reconcile_count INTEGER NOT NULL DEFAULT 0,
298 PRIMARY KEY(item_info_serial, dispatching_slip_serial, entering_slip_serial)
299 );
300 SQL;
301 createTableIfNotExists($con, 'slip_item_breakdown', $sql);
302

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26