-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.sql
142 lines (111 loc) · 3.06 KB
/
schema.sql
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
-- phpMyAdmin SQL Dump
-- version 5.1.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Apr 24, 2022 at 06:29 AM
-- Server version: 10.4.20-MariaDB
-- PHP Version: 8.0.9
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
--
-- Database: `online-store`
--
-- --------------------------------------------------------
--
-- Table structure for table `item`
--
CREATE TABLE `item` (
`item_id` varchar(36) NOT NULL,
`name` varchar(50) NOT NULL,
`description` text DEFAULT NULL,
`price` decimal(10,2) NOT NULL,
`cover_photo` varchar(36),
`availability` boolean NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `item_image`
--
CREATE TABLE `item_image` (
`item_id` varchar(36) NOT NULL,
`image_id` varchar(36) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `order`
--
CREATE TABLE `order` (
`order_id` varchar(36) NOT NULL,
`customer_name` varchar(50) NOT NULL,
`customer_address` varchar(100) NOT NULL,
`customer_contact_num` varchar(15) NOT NULL,
`customer_email` varchar(50) NOT NULL,
`date_time` datetime NOT NULL,
`status` enum('PAID','PROCESSING','DISPATCHED','DELIVERED') NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `order_item`
--
CREATE TABLE `order_item` (
`order_id` varchar(36) NOT NULL,
`item_id` varchar(36) NOT NULL,
`quantity` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `vendor`
--
CREATE TABLE `vendor` (
`username` varchar(20) NOT NULL,
`password` varchar(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `item`
--
ALTER TABLE `item`
ADD PRIMARY KEY (`item_id`);
--
-- Indexes for table `item_image`
--
ALTER TABLE `item_image`
ADD PRIMARY KEY (`item_id`,`image_id`);
--
-- Indexes for table `order`
--
ALTER TABLE `order`
ADD PRIMARY KEY (`order_id`);
--
-- Indexes for table `order_item`
--
ALTER TABLE `order_item`
ADD PRIMARY KEY (`order_id`,`item_id`),
ADD KEY `item_id` (`item_id`);
--
-- Indexes for table `vendor`
--
ALTER TABLE `vendor`
ADD PRIMARY KEY (`username`);
--
-- Constraints for dumped tables
--
--
-- Constraints for table `item_image`
--
ALTER TABLE `item_image`
ADD CONSTRAINT `item_image_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `item` (`item_id`) ON DELETE CASCADE;
--
-- Constraints for table `order_item`
--
ALTER TABLE `order_item`
ADD CONSTRAINT `order_item_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `order` (`order_id`),
ADD CONSTRAINT `order_item_ibfk_2` FOREIGN KEY (`item_id`) REFERENCES `item` (`item_id`);
COMMIT;
-- Add test vendor
-- username: test, password: 'password123'
INSERT INTO `vendor` VALUES ('test', '$2b$10$yOhIC0ip5gMqNvGGV1GaGus7PUXZSvtV2g/xOmqkaP0hQBMaKJ4bq');