暂存提交
This commit is contained in:
@@ -19,15 +19,18 @@ spring:
|
|||||||
- optional:nacos:${spring.application.name}.yml?group=BAIYUE&refreshEnabled=true
|
- optional:nacos:${spring.application.name}.yml?group=BAIYUE&refreshEnabled=true
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8858}
|
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848}
|
||||||
username: ${NACOS_USERNAME:nacos}
|
username: ${NACOS_USERNAME:nacos}
|
||||||
password: ${NACOS_PASSWORD:nacos}
|
password: ${NACOS_PASSWORD:nacos}
|
||||||
discovery:
|
discovery:
|
||||||
|
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848}
|
||||||
enabled: ${NACOS_DISCOVERY_ENABLED:true}
|
enabled: ${NACOS_DISCOVERY_ENABLED:true}
|
||||||
register-enabled: ${NACOS_REGISTER_ENABLED:true}
|
register-enabled: ${NACOS_REGISTER_ENABLED:true}
|
||||||
group: ${NACOS_GROUP:BAIYUE}
|
group: ${NACOS_GROUP:BAIYUE}
|
||||||
namespace: ${NACOS_NAMESPACE:public}
|
namespace: ${NACOS_NAMESPACE:public}
|
||||||
config:
|
config:
|
||||||
|
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848}
|
||||||
|
enabled: ${NACOS_CONFIG_ENABLED:true}
|
||||||
namespace: ${NACOS_NAMESPACE:public}
|
namespace: ${NACOS_NAMESPACE:public}
|
||||||
gateway:
|
gateway:
|
||||||
discovery:
|
discovery:
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ PREPARE migration_stmt FROM @ddl; EXECUTE migration_stmt; DEALLOCATE PREPARE mig
|
|||||||
-- Warehouse locations, pallets, resource locks and UTF-8 descriptions
|
-- Warehouse locations, pallets, resource locks and UTF-8 descriptions
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
|
|
||||||
CREATE DATABASE IF NOT EXISTS baiyue_warehouse_overseas
|
CREATE DATABASE IF NOT EXISTS baiyue_lastlag_warehouse
|
||||||
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
USE baiyue_warehouse_overseas;
|
USE baiyue_lastlag_warehouse;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS wh_location (
|
CREATE TABLE IF NOT EXISTS wh_location (
|
||||||
id BIGINT UNSIGNED NOT NULL COMMENT '库位ID(雪花ID)',
|
id BIGINT UNSIGNED NOT NULL COMMENT '库位ID(雪花ID)',
|
||||||
@@ -520,7 +520,7 @@ PREPARE migration_stmt FROM @ddl; EXECUTE migration_stmt; DEALLOCATE PREPARE mig
|
|||||||
-- Warehouse master-data descriptions and query indexes
|
-- Warehouse master-data descriptions and query indexes
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
|
|
||||||
USE baiyue_warehouse_overseas;
|
USE baiyue_lastlag_warehouse;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS wh_warehouse (
|
CREATE TABLE IF NOT EXISTS wh_warehouse (
|
||||||
id BIGINT UNSIGNED NOT NULL COMMENT '仓库ID(雪花ID)', tenant_id BIGINT UNSIGNED NOT NULL COMMENT '仓库所属租户ID',
|
id BIGINT UNSIGNED NOT NULL COMMENT '仓库ID(雪花ID)', tenant_id BIGINT UNSIGNED NOT NULL COMMENT '仓库所属租户ID',
|
||||||
@@ -752,7 +752,7 @@ CREATE TABLE IF NOT EXISTS ll_inbound_stock_receipt (
|
|||||||
) ENGINE=InnoDB COMMENT='入仓PDA库存实收快照';
|
) ENGINE=InnoDB COMMENT='入仓PDA库存实收快照';
|
||||||
|
|
||||||
-- 2026-08-17 warehouse virtual location and generated pallet code support.
|
-- 2026-08-17 warehouse virtual location and generated pallet code support.
|
||||||
USE baiyue_warehouse_overseas;
|
USE baiyue_lastlag_warehouse;
|
||||||
|
|
||||||
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema=DATABASE()
|
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema=DATABASE()
|
||||||
AND table_name='wh_pallet' AND column_name='pallet_code'),
|
AND table_name='wh_pallet' AND column_name='pallet_code'),
|
||||||
@@ -3319,7 +3319,7 @@ SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.columns WHERE tab
|
|||||||
PREPARE schema_comments_025 FROM @ddl; EXECUTE schema_comments_025; DEALLOCATE PREPARE schema_comments_025;
|
PREPARE schema_comments_025 FROM @ddl; EXECUTE schema_comments_025; DEALLOCATE PREPARE schema_comments_025;
|
||||||
|
|
||||||
|
|
||||||
USE baiyue_warehouse_overseas;
|
USE baiyue_lastlag_warehouse;
|
||||||
|
|
||||||
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name='wh_location' AND COALESCE(table_comment,'') <> '仓库库位表:按租户和仓库维护库位及承重信息'), 'ALTER TABLE wh_location COMMENT = ''仓库库位表:按租户和仓库维护库位及承重信息''', 'SELECT 1'));
|
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name='wh_location' AND COALESCE(table_comment,'') <> '仓库库位表:按租户和仓库维护库位及承重信息'), 'ALTER TABLE wh_location COMMENT = ''仓库库位表:按租户和仓库维护库位及承重信息''', 'SELECT 1'));
|
||||||
PREPARE schema_comments_025 FROM @ddl; EXECUTE schema_comments_025; DEALLOCATE PREPARE schema_comments_025;
|
PREPARE schema_comments_025 FROM @ddl; EXECUTE schema_comments_025; DEALLOCATE PREPARE schema_comments_025;
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ public class WarehouseDatabaseGuardConfiguration {
|
|||||||
static BeanFactoryPostProcessor warehouseDatabaseGuard(Environment environment) {
|
static BeanFactoryPostProcessor warehouseDatabaseGuard(Environment environment) {
|
||||||
String url = environment.getProperty("spring.datasource.url", "").trim();
|
String url = environment.getProperty("spring.datasource.url", "").trim();
|
||||||
Matcher matcher = MYSQL_SCHEMA.matcher(url);
|
Matcher matcher = MYSQL_SCHEMA.matcher(url);
|
||||||
if (!matcher.matches() || !"baiyue_warehouse_overseas".equalsIgnoreCase(matcher.group(1))) {
|
if (!matcher.matches() || !"baiyue_lastlag_warehouse".equalsIgnoreCase(matcher.group(1))) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"warehouse-overseas-service requires spring.datasource.url to target the baiyue_warehouse_overseas database");
|
"warehouse-overseas-service requires spring.datasource.url to target the baiyue_warehouse_overseas database");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ spring:
|
|||||||
config.namespace: ${NACOS_NAMESPACE:public}
|
config.namespace: ${NACOS_NAMESPACE:public}
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: ${WAREHOUSE_DB_URL:jdbc:mysql://127.0.0.1:3306/baiyue_warehouse_overseas?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true}
|
url: ${WAREHOUSE_DB_URL:jdbc:mysql://127.0.0.1:3306/baiyue_lastlag_warehouse?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true}
|
||||||
username: ${WAREHOUSE_DB_USERNAME:root}
|
username: ${WAREHOUSE_DB_USERNAME:root}
|
||||||
password: ${WAREHOUSE_DB_PASSWORD:}
|
password: ${WAREHOUSE_DB_PASSWORD:123456}
|
||||||
management.endpoints.web.exposure.include: health,info,prometheus
|
management.endpoints.web.exposure.include: health,info,prometheus
|
||||||
|
|
||||||
baiyue:
|
baiyue:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
-- This script is run through warehouse-overseas-service's datasource only.
|
-- This script is run through warehouse-overseas-service's datasource only.
|
||||||
-- The datasource guard requires the selected schema to be baiyue_warehouse_overseas;
|
-- The datasource guard requires the selected schema to be baiyue_lastlag_warehouse;
|
||||||
-- database creation and USE are intentionally forbidden here so a miswired
|
-- database creation and USE are intentionally forbidden here so a miswired
|
||||||
-- service account cannot create or switch schemas during startup.
|
-- service account cannot create or switch schemas during startup.
|
||||||
|
|
||||||
|
|||||||
+17
-2
@@ -1,17 +1,32 @@
|
|||||||
package com.baiyue.warehouse.config;
|
package com.baiyue.warehouse.config;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.env.YamlPropertySourceLoader;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
class WarehouseDatabaseGuardConfigurationTest {
|
class WarehouseDatabaseGuardConfigurationTest {
|
||||||
|
@Test
|
||||||
|
void applicationDefaultsTargetDedicatedOverseasWarehouseDatabase() throws Exception {
|
||||||
|
var properties = new YamlPropertySourceLoader()
|
||||||
|
.load("application", new ClassPathResource("application.yml"))
|
||||||
|
.get(0);
|
||||||
|
|
||||||
|
assertThat(properties.getProperty("spring.datasource.url"))
|
||||||
|
.asString()
|
||||||
|
.contains("baiyue_lastlag_warehouse")
|
||||||
|
.doesNotContain("baiyue_lastlag_warehouse");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void acceptsDedicatedOverseasWarehouseDatabase() {
|
void acceptsDedicatedOverseasWarehouseDatabase() {
|
||||||
MockEnvironment environment = new MockEnvironment()
|
MockEnvironment environment = new MockEnvironment()
|
||||||
.withProperty("spring.datasource.url",
|
.withProperty("spring.datasource.url",
|
||||||
"jdbc:mysql://127.0.0.1:3306/baiyue_warehouse_overseas?serverTimezone=Asia/Shanghai");
|
"jdbc:mysql://127.0.0.1:3306/baiyue_lastlag_warehouse?serverTimezone=Asia/Shanghai");
|
||||||
|
|
||||||
assertThatCode(() -> WarehouseDatabaseGuardConfiguration.warehouseDatabaseGuard(environment))
|
assertThatCode(() -> WarehouseDatabaseGuardConfiguration.warehouseDatabaseGuard(environment))
|
||||||
.doesNotThrowAnyException();
|
.doesNotThrowAnyException();
|
||||||
@@ -24,6 +39,6 @@ class WarehouseDatabaseGuardConfigurationTest {
|
|||||||
|
|
||||||
assertThatThrownBy(() -> WarehouseDatabaseGuardConfiguration.warehouseDatabaseGuard(environment))
|
assertThatThrownBy(() -> WarehouseDatabaseGuardConfiguration.warehouseDatabaseGuard(environment))
|
||||||
.isInstanceOf(IllegalStateException.class)
|
.isInstanceOf(IllegalStateException.class)
|
||||||
.hasMessageContaining("baiyue_warehouse_overseas");
|
.hasMessageContaining("baiyue_lastlag_warehouse");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user