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

Sazonov clickhouse fork #1

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
506defa
WIP
sazonov Feb 2, 2023
0759bab
WIP
sazonov Feb 2, 2023
efd0075
WIP
sazonov Feb 3, 2023
8682546
WIP
sazonov Feb 3, 2023
10dcb92
WIP
sazonov Feb 3, 2023
4d084e4
Fixed flyway "repair" command by switching to MergeTree engine for hi…
sazonov Feb 26, 2023
c679432
Reinitializtion support for ClickHouseConfigurationExtension
sazonov Mar 1, 2023
c9848fc
Fix for creating schema tables in clustered configuration
sazonov Mar 1, 2023
979a657
Code-style
sazonov Mar 1, 2023
1c39e7b
JDBC driver update
sazonov Mar 2, 2023
9a76431
Merge branch 'main' into clickhouse-support
sazonov Mar 7, 2023
5b0b7cc
Code-style
sazonov Mar 7, 2023
91031bd
User and pass detection by connection URL
sazonov Mar 20, 2023
fe890c1
Merge branch 'main' into clickhouse-support
sazonov Mar 20, 2023
ade4e02
License and JDBC driver update, database product name check fix
sazonov Mar 21, 2023
5f3f9d1
Code-style
sazonov Mar 21, 2023
bc833fe
Merge branch 'main' into clickhouse-support
sazonov Mar 21, 2023
cbc1d7a
Field 'version' is nullable again
sazonov Mar 31, 2023
154c4e4
Merge branch 'main' into clickhouse-support
sazonov Apr 27, 2023
0ff6c22
Merge branch 'main' into clickhouse-support
sazonov May 24, 2023
9aecb28
Merge branch 'main' into clickhouse-support
sazonov Jul 11, 2023
eef0818
Merge branch 'main' into clickhouse-support
sazonov Jul 27, 2023
b8558a6
Configuration extension now supports getNamespace() method
sazonov Aug 14, 2023
ec813ca
JDBC driver update
sazonov Aug 14, 2023
c7edf61
Merge branch 'main' into clickhouse-support
sazonov Aug 14, 2023
c538eb1
Marked ClickHouse JDBC as optional dependency
sazonov Aug 14, 2023
5103800
Merge branch 'main' into clickhouse-support
sazonov Sep 11, 2023
1cbb26a
License update
sazonov Sep 11, 2023
d9cbe15
Merge branch 'main' into clickhouse-support
sazonov Sep 29, 2023
c7f4690
Merge branch 'main' into clickhouse-support
sazonov Nov 1, 2023
9e90463
Flyway 10 support
sazonov Nov 1, 2023
e408424
Merge branch 'main' into clickhouse-support
sazonov Nov 17, 2023
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
8 changes: 7 additions & 1 deletion flyway-commandline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>flyway-database-clickhouse</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>



Expand Down Expand Up @@ -1084,4 +1090,4 @@
</profile>

</profiles>
</project>
</project>
3 changes: 2 additions & 1 deletion flyway-commandline/src/main/assembly/component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<include>org.flywaydb:flyway-database-ignite</include>
<include>org.flywaydb:flyway-database-tidb</include>
<include>org.flywaydb:flyway-database-yugabytedb</include>
<include>org.flywaydb:flyway-database-clickhouse</include>
<include>org.flywaydb:flyway-sqlserver</include>
<include>org.flywaydb:flyway-singlestore</include>
<include>org.flywaydb:flyway-mysql</include>
Expand Down Expand Up @@ -250,4 +251,4 @@
</excludes>
</dependencySet>
</dependencySets>
</component>
</component>
66 changes: 66 additions & 0 deletions flyway-community-db-support/flyway-database-clickhouse/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (C) Red Gate Software Ltd 2010-2023

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.0.0</version>
</parent>

<artifactId>flyway-database-clickhouse</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>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.5.0</version>
<optional>true</optional>
</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,39 @@
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* 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.
*/
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;

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

private static String readVersion() {
try {
return FileUtils.copyToString(
ClickHouseDatabaseExtension.class.getClassLoader().getResourceAsStream("org/flywaydb/community/database/clickhouse/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,49 @@
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* 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.
*/
package org.flywaydb.community.database.clickhouse;

import lombok.Getter;
import org.flywaydb.core.extensibility.ConfigurationExtension;

import java.util.Map;

@Getter
public class ClickHouseConfigurationExtension implements ConfigurationExtension {
private static final String CLUSTER_NAME = "flyway.clickhouse.clusterName";

private String clusterName;

@Override
public String getNamespace() {
return "clickhouse";
}

@Override
public void extractParametersFromConfiguration(Map<String, String> configuration) {
String clusterName = configuration.remove(CLUSTER_NAME);
if (clusterName != null) {
this.clusterName = clusterName;
}
}

@Override
public String getConfigurationParameterFromEnvironmentVariable(String environmentVariable) {
if ("FLYWAY_CLICKHOUSE_CLUSTER_NAME".equals(environmentVariable)) {
return CLUSTER_NAME;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* 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.
*/
package org.flywaydb.community.database.clickhouse;

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

import java.sql.SQLException;
import java.util.Optional;

public class ClickHouseConnection extends Connection<ClickHouseDatabase> {
ClickHouseConnection(ClickHouseDatabase database, java.sql.Connection connection) {
super(database, connection);
}

@Override
protected String getCurrentSchemaNameOrSearchPath() throws SQLException {
return Optional.ofNullable(getJdbcTemplate().getConnection().getSchema()).map(database::unQuote).orElse(null);
}

@Override
public void doChangeCurrentSchemaOrSearchPathTo(String schema) throws SQLException {
getJdbcTemplate().getConnection().setSchema(schema);
}

@Override
public ClickHouseSchema getSchema(String name) {
return new ClickHouseSchema(jdbcTemplate, database, name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* 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.
*/
package org.flywaydb.community.database.clickhouse;

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 org.flywaydb.core.internal.util.StringUtils;

import java.sql.Connection;

public class ClickHouseDatabase extends Database<ClickHouseConnection> {
@Override
public boolean useSingleConnection() {
return true;
}

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

public String getClusterName() {
return configuration.getPluginRegister().getPlugin(ClickHouseConfigurationExtension.class).getClusterName();
}

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

@Override
public void ensureSupported(Configuration configuration) {
}

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

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

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

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

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

@Override
public String getRawCreateScript(Table table, boolean baseline) {
String clusterName = getClusterName();
boolean isClustered = StringUtils.hasText(clusterName);

String script = "CREATE TABLE IF NOT EXISTS " + table + (isClustered ? (" ON CLUSTER " + clusterName) : "") + "(" +
" installed_rank Int32," +
" version Nullable(String)," +
" description String," +
" type String," +
" script String," +
" checksum Nullable(Int32)," +
" installed_by String," +
" installed_on DateTime DEFAULT now()," +
" execution_time Int32," +
" success Bool" +
")";

String engine;

if (isClustered) {
engine = "ReplicatedMergeTree('/clickhouse/tables/{shard}/{database}/{table}', '{replica}')";
} else {
engine = "MergeTree";
}

script += " ENGINE = " + engine +
" PRIMARY KEY (script);";

return script + (baseline ? getBaselineStatement(table) + ";" : "");
}
}
Loading
Loading