Debian Codegraph @

testdata/mysql.sql

raw
1 /**
2 * This is the database schema for testing MySQL support of ozzo-dbx.
3 * The following database setup is required in order to run the test:
4 * - host: 127.0.0.1
5 * - user: travis
6 * - pass: <none>
7 * - database: pocketbase_dbx_test
8 */
9
10 DROP TABLE IF EXISTS `order_item` CASCADE;
11 DROP TABLE IF EXISTS `item` CASCADE;
12 DROP TABLE IF EXISTS `order` CASCADE;
13 DROP TABLE IF EXISTS `customer` CASCADE;
14 DROP TABLE IF EXISTS `user` CASCADE;
15
16 CREATE TABLE `customer` (
17 `id` int(11) NOT NULL AUTO_INCREMENT,
18 `email` varchar(128) NOT NULL,
19 `name` varchar(128),
20 `address` text,
21 `status` int (11) DEFAULT 0,
22 PRIMARY KEY (`id`)
23 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
24
25 CREATE TABLE `user` (
26 `id` int(11) NOT NULL AUTO_INCREMENT,
27 `email` varchar(128) NOT NULL,
28 `created` date,
29 `updated` date,
30 PRIMARY KEY (`id`)
31 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
32
33 CREATE TABLE `item` (
34 `id` int(11) NOT NULL AUTO_INCREMENT,
35 `name` varchar(128) NOT NULL,
36 PRIMARY KEY (`id`)
37 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
38
39 CREATE TABLE `order` (
40 `id` int(11) NOT NULL AUTO_INCREMENT,
41 `customer_id` int(11) NOT NULL,
42 `created_at` int(11) NOT NULL,
43 `total` decimal(10,0) NOT NULL,
44 PRIMARY KEY (`id`),
45 CONSTRAINT `FK_order_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE
46 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
47
48 CREATE TABLE `order_item` (
49 `order_id` int(11) NOT NULL,
50 `item_id` int(11) NOT NULL,
51 `quantity` int(11) NOT NULL,
52 `subtotal` decimal(10,0) NOT NULL,
53 PRIMARY KEY (`order_id`,`item_id`),
54 KEY `FK_order_item_item_id` (`item_id`),
55 CONSTRAINT `FK_order_item_order_id` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE,
56 CONSTRAINT `FK_order_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`) ON DELETE CASCADE
57 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
58
59 INSERT INTO `customer` (email, name, address, status) VALUES ('[email protected]', 'user1', 'address1', 1);
60 INSERT INTO `customer` (email, name, address, status) VALUES ('[email protected]', 'user2', NULL, 1);
61 INSERT INTO `customer` (email, name, address, status) VALUES ('[email protected]', 'user3', 'address3', 2);
62
63 INSERT INTO `user` (email, created) VALUES ('[email protected]', '2015-01-02');
64 INSERT INTO `user` (email, created) VALUES ('[email protected]', now());
65
66 INSERT INTO `item` (name) VALUES ('The Go Programming Language');
67 INSERT INTO `item` (name) VALUES ('Go in Action');
68 INSERT INTO `item` (name) VALUES ('Go Programming Blueprints');
69 INSERT INTO `item` (name) VALUES ('Building Microservices');
70 INSERT INTO `item` (name) VALUES ('Go Web Programming');
71
72 INSERT INTO `order` (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
73 INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
74 INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
75
76 INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
77 INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
78 INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
79 INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
80 INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
81 INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);