暂存提交

This commit is contained in:
2026-08-19 16:24:02 +08:00
parent f5c4bf130a
commit 6acb6178da
354 changed files with 25000 additions and 198 deletions
@@ -0,0 +1,27 @@
package com.baiyue.warehouse.config;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** Prevents the warehouse schema migration from ever running against another database. */
@Configuration(proxyBeanMethods = false)
public class WarehouseDatabaseGuardConfiguration {
private static final Pattern MYSQL_SCHEMA = Pattern.compile(
"^jdbc:mysql://[^/]+/([^?;]+)(?:[?;].*)?$", Pattern.CASE_INSENSITIVE);
@Bean
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))) {
throw new IllegalStateException(
"warehouse-overseas-service requires spring.datasource.url to target the baiyue_warehouse_overseas database");
}
return beanFactory -> { };
}
}