refactor: update tenant data source configuration and routing logic.
All checks were successful
Build and Push Docker Images / build-and-push-backend (push) Successful in 31s
Build and Push Docker Images / build-and-push-frontend (push) Successful in 11s
Build and Push Docker Images / deploy-to-k8s (push) Successful in 46s

This commit is contained in:
Zuev
2026-03-12 23:53:20 +03:00
parent abad3776db
commit 75b1ad166e
2 changed files with 11 additions and 1 deletions

View File

@@ -103,6 +103,7 @@ public class TenantDataSourceConfig implements WebMvcConfigurer {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true); vendorAdapter.setGenerateDdl(true);
vendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQLDialect");
em.setJpaVendorAdapter(vendorAdapter); em.setJpaVendorAdapter(vendorAdapter);
Map<String, Object> props = new HashMap<>(); Map<String, Object> props = new HashMap<>();

View File

@@ -33,7 +33,16 @@ public class TenantRoutingDataSource extends AbstractRoutingDataSource {
@Override @Override
protected Object determineCurrentLookupKey() { protected Object determineCurrentLookupKey() {
String tenant = TenantContext.getCurrentTenant(); String tenant = TenantContext.getCurrentTenant();
return tenant != null ? tenant : "default"; if (tenant != null && dataSources.containsKey(tenant)) {
return tenant;
}
// Fallback: если нет контекста (например при инициализации JPA)
// или тенант не найден — берём первый доступный
if (!dataSources.isEmpty()) {
String fallback = dataSources.keySet().iterator().next().toString();
return fallback;
}
return "default";
} }
/** /**