or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

connection-management.mddatabase-operations.mddatabase-types.mdindex.mdschema-management.mdsql-parsing.mdutility-components.md

database-types.mddocs/

0

# Database Types

1

2

Database type plugins are the primary entry points for MySQL and MariaDB support in Flyway. They are automatically discovered through Java's Service Provider Interface (SPI) and handle URL recognition, driver selection, and factory methods for creating database-specific instances.

3

4

## Capabilities

5

6

### MySQL Database Type

7

8

The primary MySQL database type plugin that handles MySQL database connections and creates MySQL-specific instances.

9

10

```java { .api }

11

/**

12

* MySQL database type plugin for Flyway

13

* Automatically registered via META-INF/services/org.flywaydb.core.extensibility.Plugin

14

*/

15

public class MySQLDatabaseType extends BaseDatabaseType {

16

17

/**

18

* Returns the database type name

19

* @return "MySQL"

20

*/

21

public String getName();

22

23

/**

24

* Returns supported database engines

25

* @return List containing "MySQL", "PerconaXtraDbCluster", "TiDb", "AuroraMySql"

26

*/

27

public List<String> getSupportedEngines();

28

29

/**

30

* Returns the null type for this database

31

* @return Types.VARCHAR

32

*/

33

public int getNullType();

34

35

/**

36

* Determines if this database type can handle the given JDBC URL

37

* @param url JDBC URL to test

38

* @return true if URL is MySQL-compatible

39

*/

40

public boolean handlesJDBCUrl(String url);

41

42

/**

43

* Returns the appropriate JDBC driver class for the URL

44

* @param url JDBC URL

45

* @param classLoader Class loader for driver loading

46

* @return Driver class name (e.g., "com.mysql.cj.jdbc.Driver")

47

*/

48

public String getDriverClass(String url, ClassLoader classLoader);

49

50

/**

51

* Returns backup driver classes if primary driver is not available

52

* @param url JDBC URL

53

* @param classLoader Class loader for driver loading

54

* @return Backup driver class name or null

55

*/

56

public String getBackupDriverClass(String url, ClassLoader classLoader);

57

58

/**

59

* Determines if database product name/version matches MySQL

60

* @param databaseProductName Database product name from JDBC metadata

61

* @param databaseProductVersion Database version from JDBC metadata

62

* @param connection JDBC connection for additional checks

63

* @return true if database is MySQL

64

*/

65

public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection);

66

67

/**

68

* Factory method to create MySQL database instance

69

* @param configuration Flyway configuration

70

* @param jdbcConnectionFactory JDBC connection factory

71

* @param statementInterceptor Statement interceptor for monitoring

72

* @return MySQLDatabase instance

73

*/

74

public Database createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor);

75

76

/**

77

* Factory method to create MySQL parser instance

78

* @param configuration Flyway configuration

79

* @param resourceProvider Resource provider for SQL scripts

80

* @param parsingContext Parsing context and settings

81

* @return MySQLParser instance

82

*/

83

public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext);

84

85

/**

86

* Sets default connection properties for MySQL connections

87

* @param url JDBC URL

88

* @param props Properties to modify

89

* @param classLoader Class loader context

90

*/

91

public void setDefaultConnectionProps(String url, Properties props, ClassLoader classLoader);

92

93

/**

94

* Handles external authentication properties (e.g., option files)

95

* @param url JDBC URL

96

* @param username Database username

97

* @return Properties with external authentication settings

98

*/

99

public Properties getExternalAuthProperties(String url, String username);

100

101

/**

102

* Returns extended error message for driver instantiation failures

103

* @return Error message with MySQL connector/J download instructions

104

*/

105

public String instantiateClassExtendedErrorMessage();

106

}

107

```

108

109

**Constants:**

110

111

```java { .api }

112

// Driver class constants

113

private static final String MYSQL_LEGACY_JDBC_DRIVER = "com.mysql.jdbc.Driver";

114

private static final String MARIADB_JDBC_DRIVER = "org.mariadb.jdbc.Driver";

115

}

116

```

117

118

**Usage Example:**

119

120

```java

121

// Automatic usage via Flyway

122

Flyway flyway = Flyway.configure()

123

.dataSource("jdbc:mysql://localhost:3306/mydb", "user", "password")

124

.load(); // MySQLDatabaseType automatically discovered and used

125

126

// Direct usage (advanced)

127

MySQLDatabaseType dbType = new MySQLDatabaseType();

128

boolean canHandle = dbType.handlesJDBCUrl("jdbc:mysql://localhost:3306/test");

129

String driverClass = dbType.getDriverClass("jdbc:mysql://localhost:3306/test", Thread.currentThread().getContextClassLoader());

130

```

131

132

### MariaDB Database Type

133

134

MariaDB-specific database type plugin with higher priority than MySQL to ensure MariaDB URLs are handled correctly.

135

136

```java { .api }

137

/**

138

* MariaDB database type plugin for Flyway

139

* Has higher priority than MySQL to handle MariaDB-specific features

140

* Automatically registered via META-INF/services/org.flywaydb.core.extensibility.Plugin

141

*/

142

public class MariaDBDatabaseType extends BaseDatabaseType {

143

144

/**

145

* Returns the database type name

146

* @return "MariaDB"

147

*/

148

public String getName();

149

150

/**

151

* Returns priority for database type selection

152

* @return 1 (higher than MySQL's default priority)

153

*/

154

public int getPriority();

155

156

/**

157

* Returns the null type for this database

158

* @return Types.VARCHAR

159

*/

160

public int getNullType();

161

162

/**

163

* Determines if this database type can handle the given JDBC URL

164

* @param url JDBC URL to test

165

* @return true if URL is MariaDB-compatible

166

*/

167

public boolean handlesJDBCUrl(String url);

168

169

/**

170

* Returns the appropriate JDBC driver class for MariaDB

171

* @param url JDBC URL

172

* @param classLoader Class loader for driver loading

173

* @return "org.mariadb.jdbc.Driver" or P6Spy wrapper

174

*/

175

public String getDriverClass(String url, ClassLoader classLoader);

176

177

/**

178

* Determines if database product matches MariaDB

179

* Handles various MariaDB detection scenarios including Azure Database for MariaDB

180

* @param databaseProductName Database product name from JDBC metadata

181

* @param databaseProductVersion Database version from JDBC metadata

182

* @param connection JDBC connection for SELECT VERSION() check

183

* @return true if database is MariaDB

184

*/

185

public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection);

186

187

/**

188

* Factory method to create MariaDB database instance

189

* @param configuration Flyway configuration

190

* @param jdbcConnectionFactory JDBC connection factory

191

* @param statementInterceptor Statement interceptor for monitoring

192

* @return MariaDBDatabase instance

193

*/

194

public Database createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor);

195

196

/**

197

* Factory method to create MariaDB parser instance

198

* @param configuration Flyway configuration

199

* @param resourceProvider Resource provider for SQL scripts

200

* @param parsingContext Parsing context and settings

201

* @return MariaDBParser instance

202

*/

203

public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext);

204

205

/**

206

* Sets default connection properties for MariaDB connections

207

* @param url JDBC URL

208

* @param props Properties to modify

209

* @param classLoader Class loader context

210

*/

211

public void setDefaultConnectionProps(String url, Properties props, ClassLoader classLoader);

212

}

213

```

214

215

**Usage Example:**

216

217

```java

218

// Automatic usage via Flyway

219

Flyway flyway = Flyway.configure()

220

.dataSource("jdbc:mariadb://localhost:3306/mydb", "user", "password")

221

.load(); // MariaDBDatabaseType automatically discovered and used

222

223

// Direct usage (advanced)

224

MariaDBDatabaseType dbType = new MariaDBDatabaseType();

225

boolean canHandle = dbType.handlesJDBCUrl("jdbc:mariadb://localhost:3306/test");

226

int priority = dbType.getPriority(); // Returns 1 (higher than MySQL)

227

```

228

229

## Supported URL Patterns

230

231

### MySQL URLs

232

- `jdbc:mysql://host:port/database` - Standard MySQL

233

- `jdbc:google://project:region:instance/database` - Google Cloud SQL

234

- `jdbc:p6spy:mysql://host:port/database` - P6Spy proxy

235

- `jdbc:aws-wrapper:mysql://host:port/database` - AWS wrapper URLs

236

- Secret manager URLs with MySQL protocol

237

238

### MariaDB URLs

239

- `jdbc:mariadb://host:port/database` - Standard MariaDB

240

- `jdbc:p6spy:mariadb://host:port/database` - P6Spy proxy

241

- Secret manager URLs with MariaDB protocol

242

243

## Driver Class Resolution

244

245

### MySQL Drivers (in order of preference)

246

1. `com.mysql.cj.jdbc.Driver` - Modern MySQL Connector/J

247

2. `com.mysql.jdbc.GoogleDriver` - Google Cloud SQL

248

3. `software.amazon.jdbc.Driver` - AWS wrapper

249

4. `com.p6spy.engine.spy.P6SpyDriver` - P6Spy proxy

250

251

### Backup Drivers

252

1. `com.mysql.jdbc.Driver` - Legacy MySQL driver

253

2. `org.mariadb.jdbc.Driver` - MariaDB driver (if not disabled)

254

255

### MariaDB Drivers

256

1. `org.mariadb.jdbc.Driver` - Standard MariaDB driver

257

2. `com.p6spy.engine.spy.P6SpyDriver` - P6Spy proxy

258

259

## Database Product Detection

260

261

### MySQL Detection

262

- Product name contains "MySQL"

263

- Handles Google Cloud SQL variations (e.g., "Google SQL Service/MySQL")

264

265

### MariaDB Detection

266

- Product name starts with "MariaDB"

267

- Product name contains "MySQL" AND version contains "MariaDB" (older drivers)

268

- Product name contains "MySQL" AND `SELECT VERSION()` contains "MariaDB" (Azure Database for MariaDB)

269

270

## Connection Properties

271

272

Both database types set the following default connection properties:

273

274

```java

275

props.put("connectionAttributes", "program_name:" + APPLICATION_NAME);

276

```

277

278

This helps identify Flyway connections in database logs and monitoring systems.