Skip to content

Multiple data sources: allow renaming default data source (feature request) #14634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
karaken12 opened this issue Sep 29, 2016 · 2 comments
Open

Comments

@karaken12
Copy link

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
        ...
@MichaelMorett
Copy link
Contributor

MichaelMorett commented Feb 14, 2017

This would be very useful. Perfect use case of why this is necessary:

  1. Plugin GRAILS-10580 Rollback of transaction with checked exception grails-data-mapping#1 uses default dataSource, and also uses Database Migration Plugin.

  2. App GRAILS-10580 Rollback of transaction with checked exception grails-data-mapping#1 uses plugin GRAILS-10580 Rollback of transaction with checked exception grails-data-mapping#1.

  3. App Manually merge changes for GRAILS-9644 grails-data-mapping#2 uses Plugin GRAILS-10580 Rollback of transaction with checked exception grails-data-mapping#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 apache/grails-data-mapping#2 are impossible (unless someone can provide sample syntax to use). It will do a diff on "dataSource", which is coming from Plugin apache/grails-data-mapping#1. (I'm already tracking changes to domain objects in Plugin apache/grails-data-mapping#1 by Database Migration Plugin used in Plugin apache/grails-data-mapping#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 apache/grails-data-mapping#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.

@jameskleeh
Copy link
Contributor

@MichaelMorett Couldn't the above be solved by simply never using the default datasource in a plugin?

@jameskleeh jameskleeh transferred this issue from apache/grails-core Nov 1, 2018
@jdaugherty jdaugherty transferred this issue from apache/grails-data-mapping Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
@jameskleeh @MichaelMorett @karaken12 @jdaugherty and others