micronaut-data icon indicating copy to clipboard operation
micronaut-data copied to clipboard

Create a way to disable Micronaut Data programmatically

Open sdelamo opened this issue 1 year ago • 6 comments

see: https://github.com/micronaut-projects/micronaut-data/discussions/2856#discussioncomment-9135627

sdelamo avatar Apr 18 '24 09:04 sdelamo

What exactly do you want to disable?

dstepanov avatar Apr 18 '24 09:04 dstepanov

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

sdelamo avatar Apr 18 '24 10:04 sdelamo

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

dstepanov avatar Apr 18 '24 10:04 dstepanov

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

I think disabling a datasource completely.

sdelamo avatar Apr 18 '24 21:04 sdelamo

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.

dstepanov avatar Apr 19 '24 12:04 dstepanov

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!

Nahuel92 avatar Apr 19 '24 12:04 Nahuel92

Done in micronaut-sql by https://github.com/micronaut-projects/micronaut-sql/pull/1323

timyates avatar May 03 '24 11:05 timyates