asyncer-io / r2dbc-mysql

Reactive Relational Database Connectivity for MySQL. The official successor to mirromutth/r2dbc-mysql(dev.miku:r2dbc-mysql).
https://r2dbc.io
Apache License 2.0
195 stars 21 forks source link

[feature] create database if not exists #158

Closed trajano closed 8 months ago

trajano commented 9 months ago

Is your feature request related to a problem? Please describe. Because R2DBC kicks in before Liquibase and the mysql driver doesn't support auto creation, it fails creating the connection as the database does not exist

Describe the solution you'd like Same as JDBC MySQL createDatabaseIfNotExists=true property

Additional context Add any other context or screenshots about the feature request here.

mirromutth commented 8 months ago

This feature involves modifications to MySqlConnection.init and QueryFlow.clientCapability.

If the createDatabaseIfNotExists is enabled, then disableConnectWithDatabase whatever database is set or not. Then HandshakeResponse.encode will not send database to server on handshake. After handshake succeed, send CREATE DATABASE IF NOT EXISTS query and COM_INIT_DB command if the createDatabaseIfNotExists is enabled.

One thing that can be optimized here is that we can try to send only COM_INIT_DB first, and then if it fails, try to send CREATE statement and COM_INIT_DB again.

This feature can also be enhanced for those server versions that do not support initializing the database over the handshake protocol.

jchrys commented 8 months ago

162