Skip to content
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

Create a way to disable Micronaut Data programmatically #2893

Closed
sdelamo opened this issue Apr 18, 2024 · 7 comments
Closed

Create a way to disable Micronaut Data programmatically #2893

sdelamo opened this issue Apr 18, 2024 · 7 comments
Assignees
Labels
type: enhancement New feature or request

Comments

@sdelamo
Copy link
Contributor

sdelamo commented Apr 18, 2024

see: #2856 (reply in thread)

@sdelamo sdelamo added the type: enhancement New feature or request label Apr 18, 2024
@dstepanov
Copy link
Contributor

What exactly do you want to disable?

@sdelamo
Copy link
Contributor Author

sdelamo commented Apr 18, 2024

What exactly do you want to disable?

see the linked discussion.

A user with configuration such as application.properties

datasources.default.db-type=mysql
datasources.default.dialect=MYSQL
micronaut.application.name=demo
datasources.default.schema-generate=CREATE_DROP
datasources.default.driver-class-name=com.mysql.cj.jdbc.Driver

Should be able to write a functional test unrelated to persistence and don't waste time trying to setup the persistence logic.

Users need to be able to annotate a test with something like:

@Property(name = "data.enabled=false")
@MicronautTest
MyFunctionalTestUnrelatedToPersistenceTest

We added for example the ability to disable JPA:

https://micronaut-projects.github.io/micronaut-sql/5.6.0/guide/#hibernate-disable

@dstepanov
Copy link
Contributor

Depends if you want to disable some implementation based on it JDBC / Hibernate
Or disable a datasource completely

@sdelamo
Copy link
Contributor Author

sdelamo commented Apr 18, 2024

Depends if you want to disable some implementation based on it JDBC / Hibernate Or disable a datasource completely

I think disabling a datasource completely.

@dstepanov
Copy link
Contributor

Then it should be implemented in sql module. BasicJdbcConfiguration should implement Toggleable, but I'm not sure if we do support excluding the bean definitions by default if the interface is implemented.

@Nahuel92
Copy link

Adding to what Sergio has mentioned:
Yes please, we need to disable a DataSource completely.

Use case: I wanted to test a mapper interaction with a service to verify that everything works well together, but the app uses a DB and I don't really want to set up one just for that test (or the couple of tests not related to a DB).

Thanks!

timyates added a commit to micronaut-projects/micronaut-sql that referenced this issue Apr 24, 2024
This allows the testing of non-db beans without requiring the connection pools to be fully configured.

Does not cover r2dbc as that is defined elsewhere.

micronaut-projects/micronaut-data#2893

It is done this way (with package requirements) as there is no way currently to allow EachBean to skip factory creation based on a property of the bean (ie Toggleable#isEnabled).
sdelamo pushed a commit to micronaut-projects/micronaut-sql that referenced this issue Apr 26, 2024
This allows the testing of non-db beans without requiring the connection pools to be fully configured.

Does not cover r2dbc as that is defined elsewhere.

micronaut-projects/micronaut-data#2893

It is done this way (with package requirements) as there is no way currently to allow EachBean to skip factory creation based on a property of the bean (ie Toggleable#isEnabled).
@timyates
Copy link
Contributor

timyates commented May 3, 2024

Done in micronaut-sql by micronaut-projects/micronaut-sql#1323

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants