Skip to content

Commit 075d136

Browse files
committed
QuestDB support
1 parent 67f57b2 commit 075d136

File tree

17 files changed

+763
-0
lines changed

17 files changed

+763
-0
lines changed

flyway-database-questdb/pom.xml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (C) Red Gate Software Ltd 2010-2024
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.flywaydb</groupId>
25+
<artifactId>flyway-community-db-support</artifactId>
26+
<version>10.18.0</version>
27+
</parent>
28+
29+
<artifactId>flyway-database-questdb</artifactId>
30+
<name>${project.artifactId}</name>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>${project.groupId}</groupId>
35+
<artifactId>flyway-core</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.projectlombok</groupId>
39+
<artifactId>lombok</artifactId>
40+
<scope>provided</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.postgresql</groupId>
44+
<artifactId>postgresql</artifactId>
45+
<version>42.7.2</version>
46+
<optional>true</optional>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>junit</groupId>
51+
<artifactId>junit</artifactId>
52+
<version>4.13.2</version>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.testcontainers</groupId>
57+
<artifactId>testcontainers</artifactId>
58+
<version>1.21.0</version>
59+
<scope>test</scope>
60+
</dependency>
61+
</dependencies>
62+
63+
<build>
64+
<resources>
65+
<resource>
66+
<directory>src/main/resources</directory>
67+
<filtering>true</filtering>
68+
</resource>
69+
</resources>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-surefire-plugin</artifactId>
74+
<version>2.17</version>
75+
<configuration>
76+
<includes>
77+
<include>**/questdb/**</include>
78+
</includes>
79+
</configuration>
80+
</plugin>
81+
<plugin>
82+
<artifactId>maven-resources-plugin</artifactId>
83+
</plugin>
84+
<plugin>
85+
<artifactId>maven-jar-plugin</artifactId>
86+
</plugin>
87+
</plugins>
88+
</build>
89+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-questdb
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
package org.flywaydb.community.database;
21+
22+
import org.flywaydb.core.api.FlywayException;
23+
import org.flywaydb.core.extensibility.PluginMetadata;
24+
import org.flywaydb.core.internal.util.FileUtils;
25+
26+
import java.io.IOException;
27+
import java.nio.charset.StandardCharsets;
28+
import java.util.Objects;
29+
30+
public class QuestDBDatabaseExtension implements PluginMetadata {
31+
public String getDescription() {
32+
return "Community-contributed QuestDB database support extension " + readVersion() + " by Redgate";
33+
}
34+
35+
public static String readVersion() {
36+
try {
37+
return FileUtils.copyToString(
38+
Objects.requireNonNull(QuestDBDatabaseExtension.class.getClassLoader().getResourceAsStream("org/flywaydb/community/database/questdb/version.txt")),
39+
StandardCharsets.UTF_8);
40+
} catch (IOException e) {
41+
throw new FlywayException("Unable to read extension version: " + e.getMessage(), e);
42+
}
43+
}
44+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-questdb
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
package org.flywaydb.community.database.questdb;
21+
22+
import org.flywaydb.core.internal.database.base.Connection;
23+
import org.flywaydb.core.internal.database.base.Schema;
24+
25+
public class QuestDBConnection extends Connection<QuestDBDatabase> {
26+
27+
private final QuestDBSchema schema = new QuestDBSchema(jdbcTemplate, database, "default");
28+
29+
QuestDBConnection(QuestDBDatabase database, java.sql.Connection connection) {
30+
super(database, connection);
31+
}
32+
33+
@Override
34+
public Schema<QuestDBDatabase, QuestDBTable> getSchema(String name) {
35+
return schema;
36+
}
37+
38+
@Override
39+
protected void doRestoreOriginalState() {
40+
}
41+
42+
@Override
43+
public Schema<QuestDBDatabase, QuestDBTable> doGetCurrentSchema() {
44+
return schema;
45+
}
46+
47+
@Override
48+
protected String getCurrentSchemaNameOrSearchPath() {
49+
return "default";
50+
}
51+
52+
@Override
53+
public void changeCurrentSchemaTo(final Schema schema) {
54+
}
55+
56+
@Override
57+
public void doChangeCurrentSchemaOrSearchPathTo(final String schema) {
58+
}
59+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-questdb
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
package org.flywaydb.community.database.questdb;
21+
22+
import org.flywaydb.core.api.configuration.Configuration;
23+
import org.flywaydb.core.internal.database.base.Database;
24+
import org.flywaydb.core.internal.database.base.Table;
25+
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
26+
import org.flywaydb.core.internal.jdbc.StatementInterceptor;
27+
28+
import java.sql.Connection;
29+
30+
public class QuestDBDatabase extends Database<QuestDBConnection> {
31+
32+
@Override
33+
public boolean useSingleConnection() {
34+
return true;
35+
}
36+
37+
public QuestDBDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {
38+
super(configuration, jdbcConnectionFactory, statementInterceptor);
39+
}
40+
41+
@Override
42+
protected QuestDBConnection doGetConnection(Connection connection) {
43+
return new QuestDBConnection(this, connection);
44+
}
45+
46+
@Override
47+
public void ensureSupported(Configuration configuration) {
48+
}
49+
50+
@Override
51+
public boolean supportsDdlTransactions() {
52+
return false;
53+
}
54+
55+
@Override
56+
public String getBooleanTrue() {
57+
return "true";
58+
}
59+
60+
@Override
61+
public String getBooleanFalse() {
62+
return "false";
63+
}
64+
65+
@Override
66+
public boolean catalogIsSchema() {
67+
return false;
68+
}
69+
70+
@Override
71+
public boolean supportsMultiStatementTransactions() {
72+
return false;
73+
}
74+
75+
@Override
76+
public String getRawCreateScript(Table table, boolean baseline) {
77+
return "CREATE TABLE IF NOT EXISTS " + table.getName() + " (\n" +
78+
" \"installed_rank\" INT,\n" +
79+
" \"version\" STRING,\n" +
80+
" \"description\" STRING,\n" +
81+
" \"type\" STRING,\n" +
82+
" \"script\" STRING,\n" +
83+
" \"checksum\" INT,\n" +
84+
" \"installed_by\" STRING,\n" +
85+
" \"installed_on\" TIMESTAMP,\n" +
86+
" \"execution_time\" INT,\n" +
87+
" \"success\" BOOLEAN\n" +
88+
") timestamp (installed_on) partition by day wal\n";
89+
}
90+
91+
@Override
92+
public String getInsertStatement(Table table) {
93+
return "INSERT INTO " + table.getName()
94+
+ " (" + quote("installed_rank")
95+
+ ", " + quote("version")
96+
+ ", " + quote("description")
97+
+ ", " + quote("type")
98+
+ ", " + quote("script")
99+
+ ", " + quote("checksum")
100+
+ ", " + quote("installed_by")
101+
+ ", " + quote("installed_on")
102+
+ ", " + quote("execution_time")
103+
+ ", " + quote("success")
104+
+ ")"
105+
+ " VALUES (?, ?, ?, ?, ?, ?, ?, now(), ?, ?)";
106+
}
107+
108+
public String getSelectStatement(Table table) {
109+
return "SELECT " + quote("installed_rank")
110+
+ "," + quote("version")
111+
+ "," + quote("description")
112+
+ "," + quote("type")
113+
+ "," + quote("script")
114+
+ "," + quote("checksum")
115+
+ "," + quote("installed_on")
116+
+ "," + quote("installed_by")
117+
+ "," + quote("execution_time")
118+
+ "," + quote("success")
119+
+ " FROM " + table.getName()
120+
+ " WHERE " + quote("installed_rank") + " > ?"
121+
+ " ORDER BY " + quote("installed_rank");
122+
}
123+
}

0 commit comments

Comments
 (0)