pivotal-cf / java-cfenv

Apache License 2.0
95 stars 59 forks source link

Add Support for MariaDB services #224

Closed daviddmd closed 1 month ago

daviddmd commented 1 year ago

With MariaDB Connector/J versions greater than 3.0, the use of the jdbc:mysql scheme is disallowed unless a permitMysqlSchemeoption is set in the JDBC URL (https://mariadb.com/kb/en/about-mariadb-connector-j/#jdbcmysql-scheme-compatibility). Besides this option, using jdbc:mariadb is also a viable option if the database is MariaDB.

Currently, the library always builds the JDBC url (if no jdbc url is detected from the credentials in the environment, in which case it retrieves it without change) with the MySQL scheme, regardless of the MariaDB database service attributes or connector in use, which causes the data source initialization to fail with >= 3.0 MariaDB connectors.

Therefore, detection for MariaDB database service attributes, such as any specific tags, schemes or labels is added, and the MySQL scheme (mysql) of the JDBC url is replaced by the MariaDB scheme (mariadb) if any of the MariaDB service conditions (label, scheme, tag) are met and the current driver class in use matches the MariaDB one, to satisfy the new requirements of the 3.0 MariaDB connector (compatible with older versions of the connector). This is accomplished by overriding the createJdbcUrl method from AbstractJdbcUrlCreator in MySqlJdbcUrlCreator and replacing the built/existing (from environment) JDBC url MySQL scheme with MariaDB if the aforementioned conditions are met.

Tests were added to simulate the conditions found in MariaDB services and verify that the service is detected as expected, while not changing the behaviour for MySQL services, regardless of the driver being used.

massiinthesea commented 1 year ago

Hello,

We have a spring boot 3 application and are currently experiencing a problem using a mariaDB service on an environment deployed in Cloudfoundry PaaS

It worked fine until buildpack version 4.62.0, but since this version, because of this change: https://github.com/pivotal-cf/java-cfenv/pull/227

In fact, before, for a specific environment, I used to disable the addition of the cloud profile with JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{ enabled: false }'

But this doesn't seem to work anymore, the cloud profile being added every time, even with this set. JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{ enabled: false }'

With the cloud profile, it fetches all the DB info from the VCAPS, and therefore reads a "jdbc:mysql" url and farts.

So I'd like to know if you know how I can force the deactivation of the cloud profile on the PaaS? If not, normally, if this mr is delivered in a future version, it should solve my initial problem, accepting jdbc:mysql urls.

PS: I've gone through the MR, and it seems ok to be merged.

Thank you very much for what you do.

dipsk2 commented 11 months ago

@anthonydahanne we are waiting for this to be merged. Is there a planned timeline?

anthonydahanne commented 11 months ago

@anthonydahanne we are waiting for this to be merged. Is there a planned timeline?

sorry about that; I just want to run those changes in 2 different Cloud Foundries instances using mysql and spring-music

this week hopefully

dipsk2 commented 4 months ago

@anthonydahanne Any updates on this?

anthonydahanne commented 1 month ago

sorry all, I broke this PR; please follow this one one: #271 - thank you!