grails-data-mapping
grails-data-mapping copied to clipboard
Multiple data sources: allow renaming default data source (feature request)
When using multiple data sources, there must be a default data source and it must be called 'dataSource'. In a project using several data sources, "dataSource" is not a useful semantic name. As a developer, I would like to be able to rename the default data source.
I would expect this to be a configuration parameter. There is already a GORM syntax for referring to the default data source, so I would expect that to continue to work. I would also expect an incorrectly configured system to produce an intelligible error message (see #10144 for an example of the current stack trace).
Example configuration syntax
dataSources:
default: sourceTwo
sourceOne:
driverClassName: org.h2.Driver
...
sourceTwo:
driverClassName: org.h2.Driver
...
sourceThree:
driverClassName: org.h2.Driver
...
This would be very useful. Perfect use case of why this is necessary:
-
Plugin #1 uses default dataSource, and also uses Database Migration Plugin.
-
App #1 uses plugin #1.
-
App #2 uses Plugin #1, but also has separate domain objects, and also uses Database Migration Plugin to track changes to those domain classes.
Attempts to track domain/database changes with Database Migration Plugin from App #2 are impossible (unless someone can provide sample syntax to use). It will do a diff on "dataSource", which is coming from Plugin #1. (I'm already tracking changes to domain objects in Plugin #1 by Database Migration Plugin used in Plugin #1 and do not want to do this.)
The Database Migration plugin has options to use different dataSources -- perfect for this use case -- however, Grails won't let you name the default dataSource, thereby defeating this option when using it from App #2.
There is an implicit assumption that multiple dataSources would only be used from within a single app/plugin. The design didn't foresee or account for multiple dataSources spread over multiple apps/plugins, working together as a unit.
Being an opinionated framework is great, but in this case, there is no way to override a default.
@MichaelMorett Couldn't the above be solved by simply never using the default datasource in a plugin?