-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmigrations.php
executable file
·67 lines (48 loc) · 1.27 KB
/
migrations.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/*
This is Migration file for creating required database tables for this
project
*/
include_once ('db/db_connection.php');
include_once ('config.php');
$db = new DBConnection();
try {
$db->exec("DROP DATABASE $DB_NAME");
} catch(Exception $e) {
// pass
} finally {
$db->exec("CREATE DATABASE $DB_NAME");
}
$db = new DBConnection($DB_NAME);
$db->exec(
"CREATE TABLE category(".
"id INT NOT NULL AUTO_INCREMENT, ".
"name VARCHAR(100) NOT NULL, ".
"description VARCHAR(500) NOT NULL, ".
"PRIMARY KEY ( Id ) ".
");"
);
$db->exec(
"CREATE TABLE sub_category(".
"id INT NOT NULL AUTO_INCREMENT, ".
"name VARCHAR(100) NOT NULL, ".
"description VARCHAR(500) NOT NULL,".
"category_id INT NOT NULL, ".
"PRIMARY KEY ( Id ),".
"FOREIGN KEY (category_id) REFERENCES category(id)".
");"
);
$db->exec(
"CREATE TABLE product(".
"id INT NOT NULL AUTO_INCREMENT, ".
"name VARCHAR(100) NOT NULL, ".
"description VARCHAR(500) NOT NULL, ".
"quantity INT NOT NULL, ".
"price INT NOT NULL,".
"sub_category_id INT NOT NULL, ".
"image_link VARCHAR(200) NOT NULL, ".
"PRIMARY KEY ( Id ), ".
"FOREIGN KEY (sub_category_id) REFERENCES sub_category( id )".
");"
);
?>