This commit is contained in:
2026-08-19 17:08:42 +08:00
6 changed files with 30 additions and 12 deletions
@@ -19,15 +19,18 @@ spring:
- optional:nacos:${spring.application.name}.yml?group=BAIYUE&refreshEnabled=true
cloud:
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}
password: ${NACOS_PASSWORD:nacos}
discovery:
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848}
enabled: ${NACOS_DISCOVERY_ENABLED:true}
register-enabled: ${NACOS_REGISTER_ENABLED:true}
group: ${NACOS_GROUP:BAIYUE}
namespace: ${NACOS_NAMESPACE:public}
config:
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848}
enabled: ${NACOS_CONFIG_ENABLED:true}
namespace: ${NACOS_NAMESPACE:public}
gateway:
discovery:
+5 -5
View File
@@ -71,9 +71,9 @@ PREPARE migration_stmt FROM @ddl; EXECUTE migration_stmt; DEALLOCATE PREPARE mig
-- 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;
USE baiyue_warehouse_overseas;
USE baiyue_lastlag_warehouse;
CREATE TABLE IF NOT EXISTS wh_location (
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
-- ============================================================================
USE baiyue_warehouse_overseas;
USE baiyue_lastlag_warehouse;
CREATE TABLE IF NOT EXISTS wh_warehouse (
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库存实收快照';
-- 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()
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;
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'));
PREPARE schema_comments_025 FROM @ddl; EXECUTE schema_comments_025; DEALLOCATE PREPARE schema_comments_025;
@@ -18,7 +18,7 @@ public class WarehouseDatabaseGuardConfiguration {
static BeanFactoryPostProcessor warehouseDatabaseGuard(Environment environment) {
String url = environment.getProperty("spring.datasource.url", "").trim();
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(
"warehouse-overseas-service requires spring.datasource.url to target the baiyue_warehouse_overseas database");
}
@@ -29,9 +29,9 @@ spring:
config.namespace: ${NACOS_NAMESPACE:public}
datasource:
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}
password: ${WAREHOUSE_DB_PASSWORD:}
password: ${WAREHOUSE_DB_PASSWORD:123456}
management.endpoints.web.exposure.include: health,info,prometheus
baiyue:
@@ -1,5 +1,5 @@
-- 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
-- service account cannot create or switch schemas during startup.
@@ -1,17 +1,32 @@
package com.baiyue.warehouse.config;
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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
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
void acceptsDedicatedOverseasWarehouseDatabase() {
MockEnvironment environment = new MockEnvironment()
.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))
.doesNotThrowAnyException();
@@ -24,6 +39,6 @@ class WarehouseDatabaseGuardConfigurationTest {
assertThatThrownBy(() -> WarehouseDatabaseGuardConfiguration.warehouseDatabaseGuard(environment))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("baiyue_warehouse_overseas");
.hasMessageContaining("baiyue_lastlag_warehouse");
}
}