李进 пре 2 година
родитељ
комит
31570bb18c

+ 34 - 0
device-api-service/src/main/java/com/xy/config/MysqlSyncConfig.java

@@ -0,0 +1,34 @@
+package com.xy.config;
+
+import com.xy.utils.DataTime;
+import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.EncodedResource;
+import org.springframework.jdbc.datasource.init.ScriptUtils;
+import org.springframework.stereotype.Service;
+
+import javax.sql.DataSource;
+
+/**
+ * 执行sql脚本
+ */
+@Service
+@AllArgsConstructor
+public class MysqlSyncConfig {
+
+    private DataSource dataSource;
+
+    @Bean
+    @SneakyThrows
+    public Boolean syncSql() {
+        String time = DataTime.getSring("yyyyMMdd");
+        Resource classPathResource = new ClassPathResource(String.format("prod/%s/%s.sql", time, time));
+        EncodedResource encodedResource = new EncodedResource(classPathResource, "utf-8");
+        ScriptUtils.executeSqlScript(dataSource.getConnection(), encodedResource);
+        return true;
+    }
+
+}

+ 2 - 0
device-start/src/main/resources/prod/20230322/20230322.md

@@ -0,0 +1,2 @@
+## 测试发布
+1. 测试新增表

+ 13 - 0
device-start/src/main/resources/prod/20230322/20230322.sql

@@ -0,0 +1,13 @@
+DROP TABLE IF EXISTS test;
+CREATE TABLE test(
+    `create_user` BIGINT    COMMENT '创建人' ,
+    `create_time` DATETIME    COMMENT '创建时间' ,
+    `update_user` BIGINT    COMMENT '更新人' ,
+    `update_time` DATETIME    COMMENT '更新时间' ,
+    `deleted` bit(1)   DEFAULT 0 COMMENT '逻辑删除'
+)  COMMENT = '测试';
+
+INSERT INTO `xy`.`test`(`create_user`, `create_time`, `update_user`, `update_time`, `deleted`) VALUES (1, '2023-03-22 11:10:41', 1, '2023-03-22 11:10:44', b'1');
+INSERT INTO `xy`.`test`(`create_user`, `create_time`, `update_user`, `update_time`, `deleted`) VALUES (2, '2023-03-22 11:10:48', 2, '2023-03-22 11:10:51', b'1');
+
+delete from test where create_user = 1;