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

kingdb support #71

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
38 changes: 38 additions & 0 deletions flyway-database-kingdb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.16.3</version>
</parent>

<artifactId>flyway-database-kingdb</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>flyway-core</artifactId>
<version>${version.flyway}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>flyway-database-postgresql</artifactId>
<version>${version.flyway}</version>
<exclusions>
<exclusion>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-kingdb
* ========================================================================
* 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.kingdb;

import org.flywaydb.core.internal.database.base.Schema;
import org.flywaydb.database.postgresql.PostgreSQLConnection;


public class KingDBConnection extends PostgreSQLConnection {
protected KingDBConnection(KingDBDatabase database, java.sql.Connection connection) {
super(database, connection);
}

@Override
public Schema getSchema(String name) {
return new KingDBSchema(jdbcTemplate, database, name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-kingdb
* ========================================================================
* 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.kingdb;

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

import java.sql.Connection;

public class KingDBDatabase extends PostgreSQLDatabase {

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

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

@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
@@ -0,0 +1,67 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-kingdb
* ========================================================================
* 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.kingdb;

import org.flywaydb.core.api.ResourceProvider;
import org.flywaydb.core.api.configuration.Configuration;

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;
import org.flywaydb.database.postgresql.PostgreSQLDatabaseType;

import java.sql.Connection;


public class KingDBDatabaseType extends PostgreSQLDatabaseType implements CommunityDatabaseType {

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

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

@Override
public String getDriverClass(String url, ClassLoader classLoader) {
return url.startsWith("jdbc:kingbase8:") ? "com.kingbase8.Driver" : super.getDriverClass(url, classLoader);
}

@Override
public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection) {
return databaseProductName.toLowerCase().startsWith("kingbase");
}

@Override
public Database createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {
return new KingDBDatabase(configuration, jdbcConnectionFactory, statementInterceptor);
}

@Override
public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext) {
return new KingDBParser(configuration, parsingContext);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-kingdb
* ========================================================================
* 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.kingdb;

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

public class KingDBParser extends PostgreSQLParser {

public KingDBParser(Configuration configuration, ParsingContext parsingContext) {
super(configuration, parsingContext);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-kingdb
* ========================================================================
* 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.kingdb;

import org.flywaydb.core.internal.database.base.Table;
import org.flywaydb.core.internal.jdbc.JdbcTemplate;
import org.flywaydb.database.postgresql.PostgreSQLDatabase;
import org.flywaydb.database.postgresql.PostgreSQLSchema;


public class KingDBSchema extends PostgreSQLSchema {

/**
* Creates a new KingDBSchema schema.
*
* @param jdbcTemplate The Jdbc Template for communicating with the DB.
* @param database The database-specific support.
* @param name The name of the schema.
*/
protected KingDBSchema(JdbcTemplate jdbcTemplate, PostgreSQLDatabase database, String name) {
super(jdbcTemplate, database, name);
}

@Override
public Table getTable(String tableName) {
return new KingDBTable(jdbcTemplate, (KingDBDatabase) database, this, tableName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-kingdb
* ========================================================================
* 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.kingdb;

import org.flywaydb.core.internal.jdbc.JdbcTemplate;
import org.flywaydb.database.postgresql.PostgreSQLDatabase;
import org.flywaydb.database.postgresql.PostgreSQLSchema;
import org.flywaydb.database.postgresql.PostgreSQLTable;


public class KingDBTable extends PostgreSQLTable {

/**
* Creates a new KingDBTable table.
*
* @param jdbcTemplate The Jdbc Template for communicating with the DB.
* @param database The database-specific support.
* @param schema The schema this table lives in.
* @param name The name of the table.
*/
protected KingDBTable(JdbcTemplate jdbcTemplate, PostgreSQLDatabase database, PostgreSQLSchema schema, String name) {
super(jdbcTemplate, database, schema, name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-kingdb
* ========================================================================
* 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.kingdb.org.flywaydb.community.database;

import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.internal.util.FileUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class KingDBDatabaseExtension {
public String getDescription() {
return "Community-contributed KingDB database support extension " + readVersion() + " by Redgate";
}

public static String readVersion() {
try {
return FileUtils.copyToString(
KingDBDatabaseExtension.class.getClassLoader().getResourceAsStream("org/flywaydb/community/database/kingdb/version.txt"),
StandardCharsets.UTF_8);
} catch (IOException e) {
throw new FlywayException("Unable to read extension version: " + e.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-kingdb
* ========================================================================
* 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==================================
*/
/**
* Community-supported package. No compatibility guarantees provided.
*/
package org.flywaydb.community.database.kingdb;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.flywaydb.community.database.kingdb.KingDBDatabaseType
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${pom.version}
Loading