Skip to content

QuestDB support #87

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

Open
wants to merge 3 commits 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
89 changes: 89 additions & 0 deletions flyway-database-questdb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?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.18.0</version>
</parent>

<artifactId>flyway-database-questdb</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>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.2</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.21.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>**/questdb/**</include>
</includes>
</configuration>
</plugin>
<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,44 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-questdb
* ========================================================================
* 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 org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.extensibility.PluginMetadata;
import org.flywaydb.core.internal.util.FileUtils;

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

public class QuestDBDatabaseExtension implements PluginMetadata {
public String getDescription() {
return "Community-contributed QuestDB database support extension " + readVersion() + " by Redgate";
}

public static String readVersion() {
try {
return FileUtils.copyToString(
Objects.requireNonNull(QuestDBDatabaseExtension.class.getClassLoader().getResourceAsStream("org/flywaydb/community/database/questdb/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,59 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-questdb
* ========================================================================
* 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.questdb;

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

public class QuestDBConnection extends Connection<QuestDBDatabase> {

private final QuestDBSchema schema = new QuestDBSchema(jdbcTemplate, database, "default");

QuestDBConnection(QuestDBDatabase database, java.sql.Connection connection) {
super(database, connection);
}

@Override
public Schema<QuestDBDatabase, QuestDBTable> getSchema(String name) {
return schema;
}

@Override
protected void doRestoreOriginalState() {
}

@Override
public Schema<QuestDBDatabase, QuestDBTable> doGetCurrentSchema() {
return schema;
}

@Override
protected String getCurrentSchemaNameOrSearchPath() {
return "default";
}

@Override
public void changeCurrentSchemaTo(final Schema schema) {
}

@Override
public void doChangeCurrentSchemaOrSearchPathTo(final String schema) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-questdb
* ========================================================================
* 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.questdb;

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;

import java.sql.Connection;

public class QuestDBDatabase extends Database<QuestDBConnection> {

@Override
public boolean useSingleConnection() {
return true;
}

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

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

@Override
public void ensureSupported(Configuration configuration) {
}

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

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

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

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

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

@Override
public String getRawCreateScript(Table table, boolean baseline) {
return "CREATE TABLE IF NOT EXISTS " + table.getName() + " (\n" +
" \"installed_rank\" INT,\n" +
" \"version\" STRING,\n" +
" \"description\" STRING,\n" +
" \"type\" STRING,\n" +
" \"script\" STRING,\n" +
" \"checksum\" INT,\n" +
" \"installed_by\" STRING,\n" +
" \"installed_on\" TIMESTAMP,\n" +
" \"execution_time\" INT,\n" +
" \"success\" BOOLEAN\n" +
") timestamp (installed_on) partition by day wal\n";
}

@Override
public String getInsertStatement(Table table) {
return "INSERT INTO " + table.getName()
+ " (" + quote("installed_rank")
+ ", " + quote("version")
+ ", " + quote("description")
+ ", " + quote("type")
+ ", " + quote("script")
+ ", " + quote("checksum")
+ ", " + quote("installed_by")
+ ", " + quote("installed_on")
+ ", " + quote("execution_time")
+ ", " + quote("success")
+ ")"
+ " VALUES (?, ?, ?, ?, ?, ?, ?, now(), ?, ?)";
}

public String getSelectStatement(Table table) {
return "SELECT " + quote("installed_rank")
+ "," + quote("version")
+ "," + quote("description")
+ "," + quote("type")
+ "," + quote("script")
+ "," + quote("checksum")
+ "," + quote("installed_on")
+ "," + quote("installed_by")
+ "," + quote("execution_time")
+ "," + quote("success")
+ " FROM " + table.getName()
+ " WHERE " + quote("installed_rank") + " > ?"
+ " ORDER BY " + quote("installed_rank");
}
}
Loading