-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
138 lines (124 loc) · 4.34 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
CREATE TABLE `cart_storage` (
`id` varchar(191) NOT NULL,
`cart_data` longtext NOT NULL,
`created_at` TIMESTAMP,
`updated_at` TIMESTAMP
);
CREATE TABLE `transactions` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`number` varchar(191) NOT NULL UNIQUE,
`cart_id` varchar(191) NOT NULL,
`cart_data` longtext NOT NULL,
`amount` DECIMAL(13,2) NOT NULL DEFAULT '0.00',
`mode` enum NOT NULL DEFAULT 'COD',
`status` enum NOT NULL DEFAULT 'Pending',
`meta` longtext,
`log` longtext,
`created_at` TIMESTAMP NOT NULL,
`created_by` bigint(20) NOT NULL,
`updated_at` TIMESTAMP,
`updated_by` bigint(20)
);
CREATE TABLE `orders` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`number` varchar(191) NOT NULL UNIQUE,
`transaction_id` bigint(20) NOT NULL,
`amount` DECIMAL(13,2),
`customer_id` bigint(20) NOT NULL,
`status` enum NOT NULL DEFAULT 'Pending',
`created_at` TIMESTAMP NOT NULL,
`created_by` bigint(20) NOT NULL,
`updated_at` TIMESTAMP,
`updated_by` bigint(20),
`deleted_at` TIMESTAMP,
`deleted_by` bigint(20)
);
CREATE TABLE `payment_request` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`transaction_id` bigint(20) NOT NULL,
`request_type` enum NOT NULL DEFAULT 'Payment',
`gateway_id` bigint(20) NOT NULL,
`gateway_request_id` varchar(191) UNIQUE,
`gateway_request_data` longtext NOT NULL,
`gateway_response_id` varchar(191) UNIQUE,
`gateway_response_data` longtext NOT NULL,
`webhook_response_data` longtext,
`status` enum NOT NULL DEFAULT 'Pending',
`last_requested_at` TIMESTAMP,
`created_at` TIMESTAMP NOT NULL,
`updated_at` TIMESTAMP
);
CREATE TABLE `payment_gateway` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(191) NOT NULL,
`description` TEXT,
`api_key` varchar(255) NOT NULL,
`auth_token` varchar(255) NOT NULL,
`webhook` TEXT,
`salt_key` varchar(191),
`created_at` TIMESTAMP NOT NULL,
`created_by` bigint(20) NOT NULL,
`updated_at` TIMESTAMP,
`updated_by` bigint(20),
`deleted_at` TIMESTAMP,
`deleted_by` bigint(20)
);
CREATE TABLE `transaction_payments` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`transaction_id` bigint(20) NOT NULL,
`mode` enum NOT NULL DEFAULT 'COD',
`note` longtext,
`amount` DECIMAL(13,2) DEFAULT '0.00',
`customer_id` bigint(20) NOT NULL,
`created_at` TIMESTAMP NOT NULL,
`created_by` bigint(20) NOT NULL,
`updated_at` TIMESTAMP,
`updated_by` bigint(20),
`deleted_at` TIMESTAMP,
`deleted_by` bigint(20)
);
CREATE TABLE `order_items` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`order_id` bigint NOT NULL,
`model_type` varchar(191) NOT NULL,
`model_id` bigint(20) NOT NULL,
`name` varchar(191) NOT NULL,
`price` DECIMAL(13,2) NOT NULL DEFAULT '0.00',
`quantity` int(11) NOT NULL DEFAULT '0',
`amount` DECIMAL(13,2),
`status` enum NOT NULL DEFAULT 'Pending',
`scheduled_slot` varchar(191),
`scheduled_at` TIMESTAMP,
`scheduled_by` bigint(20),
`delivered_at` TIMESTAMP,
`delivered_by` bigint(20),
`created_at` TIMESTAMP NOT NULL,
`created_by` bigint(20) NOT NULL,
`updated_at` TIMESTAMP,
`updated_by` bigint(20),
`deleted_at` TIMESTAMP,
`deleted_by` bigint(20)
);
CREATE TABLE `refund_request` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`payment_request_id` bigint(20) NOT NULL,
`request_type` enum NOT NULL DEFAULT 'Refund',
`gateway_request_id` varchar(191) NOT NULL,
`gateway_request_data` longtext NOT NULL,
`gateway_response_id` varchar(191) UNIQUE,
`gateway_response_data` longtext NOT NULL,
`status` enum NOT NULL DEFAULT 'Pending',
`last_requested_at` TIMESTAMP,
`created_at` TIMESTAMP NOT NULL,
`created_by` bigint(20) NOT NULL,
`updated_at` TIMESTAMP,
`updated_by` bigint(20),
`deleted_at` TIMESTAMP,
`deleted_by` bigint(20)
);
ALTER TABLE `orders` ADD CONSTRAINT `orders_fk0` FOREIGN KEY (`transaction_id`) REFERENCES `transactions`(`id`);
ALTER TABLE `payment_request` ADD CONSTRAINT `payment_request_fk0` FOREIGN KEY (`transaction_id`) REFERENCES `transactions`(`id`);
ALTER TABLE `payment_request` ADD CONSTRAINT `payment_request_fk1` FOREIGN KEY (`gateway_id`) REFERENCES `payment_gateway`(`id`);
ALTER TABLE `transaction_payments` ADD CONSTRAINT `transaction_payments_fk0` FOREIGN KEY (`transaction_id`) REFERENCES `transactions`(`id`);
ALTER TABLE `order_items` ADD CONSTRAINT `order_items_fk0` FOREIGN KEY (`order_id`) REFERENCES `orders`(`id`);
ALTER TABLE `refund_request` ADD CONSTRAINT `refund_request_fk0` FOREIGN KEY (`payment_request_id`) REFERENCES `payment_request`(`id`);