0

I'm working on data migration from SQL Server to PostgreSQL. I'm planning to switch the data source using a feature toggle to reduce the migration risk. I've got good idea how to return appropriate DataSource based on the feature toggle from AbstractRoutingDataSource. How can I wire in the returned DataSource into my Jpa/Crud Repositories. The examples I've found online were only focused on Jpa or assumed multitenancy requirement. In other cases assumed that each data source is defined in separate package because of @EnableJpaRepositories - which from what I understand wouldn't work with AbstractRoutingDataSource.

This is a follow-up question to Spring Boot - dynamically choose datasource with different SQL flavours based on a feature toggle

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
sumek
  • 26,495
  • 13
  • 56
  • 75
  • Consider deploying two separate versions of your service - one for each of the data sources - and using an LB to direct traffic to one or the other. That way, each service does one thing (recommended), rather than having one service that does two things. – Bohemian May 25 '23 at 11:33
  • That would be quite difficult given the infra constraints I have – sumek May 25 '23 at 13:33
  • If you are using Spring Boot just providing the `DataSource` as a bean should be sufficient for it to get picked up. – Jens Schauder May 31 '23 at 12:34

0 Answers0