Skip to content

Commit

Permalink
Merge pull request #27 from Sfurti-yb/DB-7847-fix
Browse files Browse the repository at this point in the history
Update the Flyway plugin for YugabyteDB
  • Loading branch information
Barry-RG authored Mar 5, 2024
2 parents b3ef33f + 7b8131d commit 48db9d8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions flyway-database-yugabytedb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@
*/
package org.flywaydb.community.database.postgresql.yugabytedb;

import lombok.CustomLog;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.database.base.Table;
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
import org.flywaydb.core.internal.jdbc.StatementInterceptor;
import org.flywaydb.database.postgresql.PostgreSQLDatabase;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;


@CustomLog
public class YugabyteDBDatabase extends PostgreSQLDatabase {

public YugabyteDBDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {
Expand All @@ -30,6 +36,13 @@ public YugabyteDBDatabase(Configuration configuration, JdbcConnectionFactory jdb

@Override
protected YugabyteDBConnection doGetConnection(Connection connection) {
Statement stmt = null;
try {
stmt = connection.createStatement();
stmt.execute("set yb_silence_advisory_locks_not_supported_error=on;");
} catch (SQLException throwable) {
LOG.error("Unable to set yb_silence_advisory_locks_not_supported_error ", throwable);
}
return new YugabyteDBConnection(this, connection);
}

Expand All @@ -44,4 +57,22 @@ public boolean supportsDdlTransactions() {
return false;
}

@Override
public String getRawCreateScript(Table table, boolean baseline) {
return "CREATE TABLE IF NOT EXISTS " + table + " (\n" +
" \"installed_rank\" INT NOT NULL PRIMARY KEY,\n" +
" \"version\" VARCHAR(50),\n" +
" \"description\" VARCHAR(200) NOT NULL,\n" +
" \"type\" VARCHAR(20) NOT NULL,\n" +
" \"script\" VARCHAR(1000) NOT NULL,\n" +
" \"checksum\" INTEGER,\n" +
" \"installed_by\" VARCHAR(100) NOT NULL,\n" +
" \"installed_on\" TIMESTAMP NOT NULL DEFAULT now(),\n" +
" \"execution_time\" INTEGER NOT NULL,\n" +
" \"success\" BOOLEAN NOT NULL\n" +
");\n" +
(baseline ? getBaselineStatement(table) + ";\n" : "") +
"CREATE INDEX IF NOT EXISTS \"" + table.getName() + "_s_idx\" ON " + table + " (\"success\");";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String getName() {

@Override
public boolean handlesJDBCUrl(String url) {
return url.startsWith("jdbc:postgresql:") || url.startsWith("jdbc:p6spy:postgresql:");
return url.startsWith("jdbc:yugabytedb:") || url.startsWith("jdbc:postgresql:") || url.startsWith("jdbc:p6spy:postgresql:");
}

@Override
Expand Down

0 comments on commit 48db9d8

Please sign in to comment.