Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cubrid support #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions flyway-database-cubrid/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (C) Red Gate Software Ltd 2010-2024

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-community-db-support</artifactId>
<version>10.17.0</version>
</parent>

<artifactId>flyway-database-cubrid</artifactId>
<name>${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-cubrid
* ========================================================================
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package org.flywaydb.community.database;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.extensibility.PluginMetadata;
import org.flywaydb.core.internal.util.FileUtils;

public class CUBRIDDatabaseExtension implements PluginMetadata {

public static String readVersion() {
try {
return FileUtils.copyToString(
Objects.requireNonNull(
CUBRIDDatabaseExtension.class.getClassLoader().getResourceAsStream(
"org/flywaydb/community/database/database/version.txt")),
StandardCharsets.UTF_8);
} catch (IOException e) {
throw new FlywayException("Unable to read extension version: " + e.getMessage(), e);
}
}

@Override
public String getDescription() {
return "Community-contributed CUBRID database support extension " + readVersion()
+ " by Redgate";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-cubrid
* ========================================================================
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package org.flywaydb.community.database.cubrid;

import org.flywaydb.core.internal.database.base.Connection;

public class CUBRIDConnection extends Connection<CUBRIDDatabase> {

public CUBRIDConnection(CUBRIDDatabase database, java.sql.Connection connection) {
super(database, connection);
}

@Override
protected String getCurrentSchemaNameOrSearchPath() {
// schema isn't supported
return null;
}

@Override
public CUBRIDSchema getSchema(String name) {
return new CUBRIDSchema(jdbcTemplate, database, name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-cubrid
* ========================================================================
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package org.flywaydb.community.database.cubrid;

import java.sql.Connection;
import lombok.CustomLog;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.database.base.Database;
import org.flywaydb.core.internal.database.base.Table;
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
import org.flywaydb.core.internal.jdbc.StatementInterceptor;

@CustomLog
public class CUBRIDDatabase extends Database<CUBRIDConnection> {

public CUBRIDDatabase(Configuration configuration,
JdbcConnectionFactory jdbcConnectionFactory,
StatementInterceptor statementInterceptor) {
super(configuration, jdbcConnectionFactory, statementInterceptor);
}

@Override
protected CUBRIDConnection doGetConnection(Connection connection) {
return new CUBRIDConnection(this, connection);
}

@Override
public void ensureSupported(Configuration configuration) {
}

@Override
public boolean supportsDdlTransactions() {
return false;
}

@Override
public String getBooleanTrue() {
return "1";
}

@Override
public String getBooleanFalse() {
return "0";
}

@Override
public boolean catalogIsSchema() {
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\" INT,\n" +
" \"installed_by\" VARCHAR(100) NOT NULL,\n" +
" \"installed_on\" TIMESTAMP NOT NULL DEFAULT NOW(),\n" +
" \"execution_time\" INT NOT NULL,\n" +
" \"success\" INT NOT NULL\n" +
");\n"
+ (baseline ? getBaselineStatement(table) + ";\n" : "")
+ "CREATE INDEX " + table.getName() + "_s_idx ON " + table + " (\"success\");";
}

@Override
public boolean useSingleConnection() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-cubrid
* ========================================================================
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package org.flywaydb.community.database.cubrid;

import java.sql.Connection;
import java.sql.Types;
import org.flywaydb.community.database.CUBRIDDatabaseExtension;
import org.flywaydb.core.api.ResourceProvider;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.database.base.BaseDatabaseType;
import org.flywaydb.core.internal.database.base.CommunityDatabaseType;
import org.flywaydb.core.internal.database.base.Database;
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
import org.flywaydb.core.internal.jdbc.StatementInterceptor;
import org.flywaydb.core.internal.parser.Parser;
import org.flywaydb.core.internal.parser.ParsingContext;

public class CUBRIDDatabaseType extends BaseDatabaseType implements CommunityDatabaseType {

@Override
public String getName() {
return "CUBRID";
}

@Override
public int getNullType() {
return Types.NULL;
}

@Override
public boolean handlesJDBCUrl(String url) {
return url.startsWith("jdbc:cubrid:");
}

@Override
public String getDriverClass(String url, ClassLoader classLoader) {
return "cubrid.jdbc.driver.CUBRIDDriver";
}

@Override
public boolean handlesDatabaseProductNameAndVersion(String databaseProductName,
String databaseProductVersion,
Connection connection) {
return databaseProductName != null && databaseProductName.trim().toLowerCase()
.contains("cubrid");
}


@Override
public Database<CUBRIDConnection> createDatabase(Configuration configuration,
JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {
return new CUBRIDDatabase(configuration, jdbcConnectionFactory, statementInterceptor);
}

@Override
public Parser createParser(Configuration configuration, ResourceProvider resourceProvider,
ParsingContext parsingContext) {
return new CUBRIDParser(configuration, parsingContext);
}

@Override
public String getPluginVersion(Configuration config) {
return CUBRIDDatabaseExtension.readVersion();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-cubrid
* ========================================================================
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package org.flywaydb.community.database.cubrid;

import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.parser.Parser;
import org.flywaydb.core.internal.parser.ParsingContext;

public class CUBRIDParser extends Parser {

protected CUBRIDParser(Configuration configuration, ParsingContext parsingContext) {
super(configuration, parsingContext, 2);
}
}
Loading