-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbmigrate.php
51 lines (41 loc) · 1.15 KB
/
dbmigrate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Database migration file.
* Run: $ php dbmigrate.php
*/
require 'bootstrap.php';
try {
$config = new Config();
$dbi = DB::getInstance($config::DB_HOST, $config::DB_NAME, $config::DB_USER, $config::DB_PASSWORD);
$db = $dbi->connect();
$db->beginTransaction();
// Create import_log table
$db->exec('DROP TABLE IF EXISTS `import_log`');
$db->exec('
CREATE TABLE `import_log` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`file` varchar(300) NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `file` (`file`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
');
// Create user table
$db->exec('DROP TABLE IF EXISTS `user`');
$db->exec('
CREATE TABLE `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`number` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
`phone` varchar(30) NOT NULL,
`email` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `number` (`file`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
');
$db->commit();
} catch (Exception $e) {
$db->rollback();
throw $e;
}
?>