Skip to content

Commit cb4087f

Browse files
BENCH-187-TEST-CONTAINERS Added init script
1 parent f21b859 commit cb4087f

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

src/main/resources/init_db.sql

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
2+
SET NAMES utf8mb4;
3+
SET FOREIGN_KEY_CHECKS = 0;
4+
5+
-- ----------------------------
6+
-- Table structure for category
7+
-- ----------------------------
8+
DROP TABLE IF EXISTS `category`;
9+
CREATE TABLE `category` (
10+
`id` bigint(20) NOT NULL AUTO_INCREMENT,
11+
`name` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL,
12+
`description` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
13+
`retired` bit(1) NOT NULL,
14+
PRIMARY KEY (`id`) USING BTREE
15+
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
16+
17+
-- ----------------------------
18+
-- Records of category
19+
-- ----------------------------
20+
21+
-- ----------------------------
22+
-- Table structure for order
23+
-- ----------------------------
24+
DROP TABLE IF EXISTS `order`;
25+
CREATE TABLE `order` (
26+
`id` bigint(20) NOT NULL AUTO_INCREMENT,
27+
`address` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
28+
`order_status` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
29+
PRIMARY KEY (`id`) USING BTREE
30+
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
31+
32+
-- ----------------------------
33+
-- Records of order
34+
-- ----------------------------
35+
INSERT INTO `order` VALUES (1, 'Leeds', 'IN_PROGRESS');
36+
INSERT INTO `order` VALUES (2, 'Manchester', 'IN_PROGRESS');
37+
38+
-- ----------------------------
39+
-- Table structure for product
40+
-- ----------------------------
41+
DROP TABLE IF EXISTS `product`;
42+
CREATE TABLE `product` (
43+
`id` bigint(20) NOT NULL AUTO_INCREMENT,
44+
`name` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
45+
`description` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
46+
`retired` bit(1) NOT NULL,
47+
`price` decimal(12, 2) NOT NULL,
48+
PRIMARY KEY (`id`) USING BTREE
49+
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
50+
51+
-- ----------------------------
52+
-- Records of product
53+
-- ----------------------------
54+
INSERT INTO `product` VALUES (1, 'Burger', '300g Beef', b'0', 6.69);
55+
INSERT INTO `product` VALUES (2, 'Cola', '500ml', b'1', 2.99);
56+
INSERT INTO `product` VALUES (3, 'Fries', 'Large Fries', b'0', 2.99);
57+
58+
-- ----------------------------
59+
-- Table structure for order_product
60+
-- ----------------------------
61+
DROP TABLE IF EXISTS `order_product`;
62+
CREATE TABLE `order_product` (
63+
`id` bigint(20) NOT NULL AUTO_INCREMENT,
64+
`order_id` bigint(20) NOT NULL,
65+
`product_id` bigint(20) NOT NULL,
66+
`quantity` int(11) NOT NULL,
67+
PRIMARY KEY (`id`) USING BTREE,
68+
INDEX `order_id`(`order_id`) USING BTREE,
69+
INDEX `product_id`(`product_id`) USING BTREE,
70+
CONSTRAINT `order_product_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
71+
CONSTRAINT `order_product_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
72+
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
73+
74+
-- ----------------------------
75+
-- Records of order_product
76+
-- ----------------------------
77+
INSERT INTO `order_product` VALUES (1, 1, 1, 5);
78+
INSERT INTO `order_product` VALUES (2, 1, 3, 47);
79+
INSERT INTO `order_product` VALUES (3, 2, 1, 1);
80+
INSERT INTO `order_product` VALUES (4, 2, 3, 1);
81+
82+
-- ----------------------------
83+
-- Table structure for product_category
84+
-- ----------------------------
85+
DROP TABLE IF EXISTS `product_category`;
86+
CREATE TABLE `product_category` (
87+
`id` bigint(20) NOT NULL AUTO_INCREMENT,
88+
`product_id` bigint(20) NOT NULL,
89+
`category_id` bigint(20) NOT NULL,
90+
PRIMARY KEY (`id`) USING BTREE,
91+
INDEX `product_id`(`product_id`) USING BTREE,
92+
INDEX `category_id`(`category_id`) USING BTREE,
93+
CONSTRAINT `product_category_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
94+
CONSTRAINT `product_category_ibfk_2` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
95+
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
96+
97+
-- ----------------------------
98+
-- Records of product_category
99+
-- ----------------------------
100+
101+
SET FOREIGN_KEY_CHECKS = 1;

src/test/java/com/answerdigital/answerking/utility/AbstractContainerBaseTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public abstract class AbstractContainerBaseTest {
1212
static {
1313
MY_SQL_CONTAINER =
1414
new MySQLContainer<>("mysql:8.0.31")
15+
.withInitScript("init_db.sql")
1516
.withReuse(true);
1617
MY_SQL_CONTAINER.start();
1718
}

0 commit comments

Comments
 (0)