refactor: update tenant data source configuration and routing logic.
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 committed 2026-03-12 23:53:20 +03:00
1 parent abad3776db
commit 75b1ad166e
2 files changed
+11 -1

No files matched your search

@@ -103,6 +103,7 @@ public class TenantDataSourceConfig implements WebMvcConfigurer {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
vendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQLDialect");
em.setJpaVendorAdapter(vendorAdapter);
Map<String, Object> props = new HashMap<>();
@@ -33,7 +33,16 @@ public class TenantRoutingDataSource extends AbstractRoutingDataSource {
@Override
protected Object determineCurrentLookupKey() {
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";
}
/**