在正确基点上继续开发
Change-Id: Id4ef3e3bd2627176ea8254561140a7bf570f9cdb
diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml
index 45122fa..45b607b 100644
--- a/src/test/resources/application-test.yml
+++ b/src/test/resources/application-test.yml
@@ -2,7 +2,14 @@
spring:
application:
name: PTPlatform-test # 区分测试环境
-
+
+ spring:
+ sql:
+ init:
+ mode: always # 一定要始终执行,不论你用的是哪个 profile
+ schema-locations: classpath:schema.sql
+
+
# 数据源配置 (H2 内存数据库)
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=MYSQL # 模拟MySQL语法
@@ -10,7 +17,6 @@
username: sa
password:
-
# JPA/Hibernate 配置
jpa:
hibernate:
diff --git a/src/test/resources/schema.sql b/src/test/resources/schema.sql
new file mode 100644
index 0000000..677d41c
--- /dev/null
+++ b/src/test/resources/schema.sql
@@ -0,0 +1,40 @@
+CREATE TABLE IF NOT EXISTS help_posts (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ author_id INT NOT NULL,
+ title VARCHAR(255) NOT NULL,
+ content TEXT NOT NULL,
+ like_count INT NOT NULL DEFAULT 0,
+ reply_count INT NOT NULL DEFAULT 0,
+ create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()
+);
+
+
+CREATE TABLE IF NOT EXISTS help_comments (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ post_id INT NOT NULL,
+ author_id INT NOT NULL,
+ content TEXT NOT NULL,
+ like_count INT NOT NULL DEFAULT 0,
+ create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
+ CONSTRAINT fk_help_comments_post FOREIGN KEY (post_id) REFERENCES help_posts(id) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS seed_posts (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ author_id INT NOT NULL,
+ title VARCHAR(255) NOT NULL,
+ content TEXT NOT NULL,
+ like_count INT NOT NULL DEFAULT 0,
+ reply_count INT NOT NULL DEFAULT 0,
+ create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()
+);
+
+CREATE TABLE IF NOT EXISTS seed_comments (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ post_id INT NOT NULL,
+ author_id INT NOT NULL,
+ content TEXT NOT NULL,
+ like_count INT NOT NULL DEFAULT 0,
+ create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
+ CONSTRAINT fk_seed_comments_post FOREIGN KEY (post_id) REFERENCES seed_posts(id) ON DELETE CASCADE
+);