From 542a56a4bf8e7e953ac7a916f3aca98e0b8f9958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=98=89=E4=BF=8A?= <> Date: Thu, 5 Sep 2024 19:23:16 +0800 Subject: [PATCH 1/2] Added kingbase database support --- flyway-database-kingbase/pom.xml | 71 ++++ .../database/KingbaseDatabaseExtension.java | 59 +++ .../KingbaseAdvisoryLockTemplate.java | 123 ++++++ .../KingbaseConfigurationExtension.java | 52 +++ .../database/kingbase/KingbaseConnection.java | 115 ++++++ .../kingbase/KingbaseCopyParsedStatement.java | 98 +++++ .../database/kingbase/KingbaseDatabase.java | 148 +++++++ .../kingbase/KingbaseDatabaseType.java | 152 +++++++ .../database/kingbase/KingbaseParser.java | 155 +++++++ .../database/kingbase/KingbaseSchema.java | 380 ++++++++++++++++++ .../database/kingbase/KingbaseTable.java | 64 +++ .../database/kingbase/KingbaseType.java | 47 +++ .../database/kingbase/TransactionalModel.java | 27 ++ .../database/kingbase/package-info.java | 23 ++ .../org.flywaydb.core.extensibility.Plugin | 1 + .../community/database/kingbase/version.txt | 1 + pom.xml | 1 + 17 files changed, 1517 insertions(+) create mode 100644 flyway-database-kingbase/pom.xml create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/KingbaseDatabaseExtension.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseAdvisoryLockTemplate.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConfigurationExtension.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConnection.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseCopyParsedStatement.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabase.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabaseType.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseParser.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseSchema.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseTable.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseType.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/TransactionalModel.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/package-info.java create mode 100644 flyway-database-kingbase/src/main/resources/META-INF/services/org.flywaydb.core.extensibility.Plugin create mode 100644 flyway-database-kingbase/src/main/resources/org/flywaydb/community/database/kingbase/version.txt diff --git a/flyway-database-kingbase/pom.xml b/flyway-database-kingbase/pom.xml new file mode 100644 index 0000000..0abfe8b --- /dev/null +++ b/flyway-database-kingbase/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + + org.flywaydb + flyway-community-db-support + 10.16.1 + + + flyway-database-kingbase + ${project.artifactId} + + + + ${project.groupId} + flyway-core + + + ${project.groupId} + flyway-database-postgresql + ${version.flyway} + + + org.flywaydb + flyway-core + + + + + org.projectlombok + lombok + provided + + + + + + + src/main/resources + true + + + + + maven-resources-plugin + + + maven-jar-plugin + + + + \ No newline at end of file diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/KingbaseDatabaseExtension.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/KingbaseDatabaseExtension.java new file mode 100644 index 0000000..5fb3923 --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/KingbaseDatabaseExtension.java @@ -0,0 +1,59 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ +/* + * 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. + */ +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 KingbaseDatabaseExtension implements PluginMetadata { + public String getDescription() { + return "Community-contributed kingbase database support extension " + readVersion() + " by Redgate"; + } + + public static String readVersion() { + try { + return FileUtils.copyToString( + KingbaseDatabaseExtension.class.getClassLoader().getResourceAsStream("org/flywaydb/community" + + "/database/kingbase/version.txt"), + StandardCharsets.UTF_8); + } catch (IOException e) { + throw new FlywayException("Unable to read extension version: " + e.getMessage(), e); + } + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseAdvisoryLockTemplate.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseAdvisoryLockTemplate.java new file mode 100644 index 0000000..d4c5fcb --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseAdvisoryLockTemplate.java @@ -0,0 +1,123 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import lombok.CustomLog; +import org.flywaydb.core.api.FlywayException; +import org.flywaydb.core.api.configuration.Configuration; +import org.flywaydb.core.internal.exception.FlywaySqlException; +import org.flywaydb.core.internal.jdbc.JdbcTemplate; +import org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate; +import org.flywaydb.core.internal.strategy.RetryStrategy; +import org.flywaydb.core.internal.util.FlywayDbWebsiteLinks; +import org.flywaydb.core.internal.util.SqlCallable; + +import java.sql.SQLException; +import java.util.List; +import java.util.concurrent.Callable; + +@CustomLog +public class KingbaseAdvisoryLockTemplate { + private static final long LOCK_MAGIC_NUM = + (0x46L << 40) // F + + (0x6CL << 32) // l + + (0x79L << 24) // y + + (0x77 << 16) // w + + (0x61 << 8) // a + + 0x79; // y + + private final Configuration configuration; + private final JdbcTemplate jdbcTemplate; + private final long lockNum; + + KingbaseAdvisoryLockTemplate(Configuration configuration, JdbcTemplate jdbcTemplate, int discriminator) { + this.configuration = configuration; + this.jdbcTemplate = jdbcTemplate; + this.lockNum = LOCK_MAGIC_NUM + discriminator; + } + + public T execute(Callable callable) { + KingbaseConfigurationExtension configurationExtension = configuration.getPluginRegister().getPlugin(KingbaseConfigurationExtension.class); + + if (configurationExtension.isTransactionalLock()) { + return new TransactionalExecutionTemplate(jdbcTemplate.getConnection(), true).execute(() -> execute(callable, this::tryLockTransactional)); + } else { + RuntimeException rethrow = null; + try { + return execute(callable, this::tryLock); + } catch (RuntimeException e) { + rethrow = e; + throw rethrow; + } finally { + unlock(rethrow); + } + } + } + + private T execute(Callable callable, SqlCallable tryLock) { + try { + lock(tryLock); + return callable.call(); + } catch (SQLException e) { + throw new FlywaySqlException("Unable to acquire PostgreSQL advisory lock", e); + } catch (Exception e) { + if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } + throw new FlywayException(e); + } + } + + private void lock(SqlCallable tryLock) throws SQLException { + RetryStrategy strategy = new RetryStrategy(); + strategy.doWithRetries(tryLock, "Interrupted while attempting to acquire PostgreSQL advisory lock", + "Number of retries exceeded while attempting to acquire PostgreSQL advisory lock. " + + "Configure the number of retries with the 'lockRetryCount' configuration option: " + FlywayDbWebsiteLinks.LOCK_RETRY_COUNT); + } + + private boolean tryLockTransactional() throws SQLException { + List results = jdbcTemplate.query("SELECT pg_try_advisory_xact_lock(" + lockNum + ")", rs -> rs.getBoolean("pg_try_advisory_xact_lock")); + return results.size() == 1 && results.get(0); + } + + private boolean tryLock() throws SQLException { + List results = jdbcTemplate.query("SELECT pg_try_advisory_lock(" + lockNum + ")", rs -> rs.getBoolean("pg_try_advisory_lock")); + return results.size() == 1 && results.get(0); + } + + private void unlock(RuntimeException rethrow) throws FlywaySqlException { + try { + boolean unlocked = jdbcTemplate.queryForBoolean("SELECT pg_advisory_unlock(" + lockNum + ")"); + if (!unlocked) { + if (rethrow == null) { + throw new FlywayException("Unable to release PostgreSQL advisory lock"); + } else { + LOG.error("Unable to release PostgreSQL advisory lock"); + } + } + } catch (SQLException e) { + if (rethrow == null) { + throw new FlywaySqlException("Unable to release PostgreSQL advisory lock", e); + } else { + LOG.error("Unable to release PostgreSQL advisory lock", e); + } + } + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConfigurationExtension.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConfigurationExtension.java new file mode 100644 index 0000000..8e04b4b --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConfigurationExtension.java @@ -0,0 +1,52 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import lombok.Data; +import org.flywaydb.core.extensibility.ConfigurationExtension; + +@Data +public class KingbaseConfigurationExtension implements ConfigurationExtension { + private static final String TRANSACTIONAL_LOCK = "flyway.postgresql.transactional.lock"; + + private TransactionalModel transactional = null; + + public boolean isTransactionalLock() { + // null is default, default is true, done this way for merge reasons. + return transactional == null || transactional.getLock() == null || transactional.getLock(); + } + + public void setTransactionalLock(boolean transactionalLock) { + transactional = new TransactionalModel(); + transactional.setLock(transactionalLock); + } + @Override + public String getConfigurationParameterFromEnvironmentVariable(String environmentVariable) { + if ("FLYWAY_POSTGRESQL_TRANSACTIONAL_LOCK".equals(environmentVariable)) { + return TRANSACTIONAL_LOCK; + } + return null; + } + + @Override + public String getNamespace() { + return "postgresql"; + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConnection.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConnection.java new file mode 100644 index 0000000..251b05b --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConnection.java @@ -0,0 +1,115 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import lombok.Getter; +import org.flywaydb.core.api.FlywayException; +import org.flywaydb.core.internal.database.base.Connection; +import org.flywaydb.core.internal.database.base.Schema; +import org.flywaydb.core.internal.database.base.Table; +import org.flywaydb.core.internal.exception.FlywaySqlException; +import org.flywaydb.core.internal.util.StringUtils; + +import java.sql.SQLException; +import java.util.concurrent.Callable; + +public class KingbaseConnection extends Connection { + private final String originalRole; + @Getter + private final boolean awsRds; + + protected KingbaseConnection(KingbaseDatabase database, java.sql.Connection connection) { + super(database, connection); + + try { + originalRole = jdbcTemplate.queryForString("SELECT CURRENT_USER"); + } catch (SQLException e) { + throw new FlywaySqlException("Unable to determine current user", e); + } + + awsRds = rdsAdminExists(); + } + + @Override + protected void doRestoreOriginalState() throws SQLException { + // Reset the role to its original value in case a migration or callback changed it + jdbcTemplate.execute("SET ROLE '" + originalRole + "'"); + } + + @Override + public Schema doGetCurrentSchema() throws SQLException { + String currentSchema = jdbcTemplate.queryForString("SELECT current_schema"); + String searchPath = getCurrentSchemaNameOrSearchPath(); + + if (!StringUtils.hasText(currentSchema) && !StringUtils.hasText(searchPath)) { + throw new FlywayException("Unable to determine current schema as search_path is empty. " + + "Set the current schema in currentSchema parameter of the JDBC URL or in Flyway's schemas property."); + } + + String schema = StringUtils.hasText(currentSchema) ? currentSchema : searchPath; + + return getSchema(schema); + } + + @Override + protected String getCurrentSchemaNameOrSearchPath() throws SQLException { + return jdbcTemplate.queryForString("SHOW search_path"); + } + + @Override + public void changeCurrentSchemaTo(Schema schema) { + try { + if (schema.getName().equals(originalSchemaNameOrSearchPath) || originalSchemaNameOrSearchPath.startsWith(schema.getName() + ",") || !schema.exists()) { + return; + } + + if (StringUtils.hasText(originalSchemaNameOrSearchPath)) { + doChangeCurrentSchemaOrSearchPathTo(schema + "," + originalSchemaNameOrSearchPath); + } else { + doChangeCurrentSchemaOrSearchPathTo(schema.toString()); + } + } catch (SQLException e) { + throw new FlywaySqlException("Error setting current schema to " + schema, e); + } + } + + @Override + public void doChangeCurrentSchemaOrSearchPathTo(String schema) throws SQLException { + jdbcTemplate.execute("SELECT set_config('search_path', ?, false)", schema); + } + + @Override + public Schema getSchema(String name) { + return new KingbaseSchema(jdbcTemplate, database, name); + } + + @Override + public T lock(Table table, Callable callable) { + return new KingbaseAdvisoryLockTemplate(database.getConfiguration(), jdbcTemplate, table.toString().hashCode()).execute(callable); + } + + private boolean rdsAdminExists() { + try { + return StringUtils.hasText(jdbcTemplate.queryForString("SELECT rolname FROM pg_roles WHERE rolname ILIKE 'rds_superuser';")); + } catch (Exception e) { + return false; + } + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseCopyParsedStatement.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseCopyParsedStatement.java new file mode 100644 index 0000000..e167c29 --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseCopyParsedStatement.java @@ -0,0 +1,98 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import org.flywaydb.core.api.FlywayException; +import org.flywaydb.core.api.configuration.Configuration; +import org.flywaydb.core.internal.jdbc.JdbcTemplate; +import org.flywaydb.core.internal.jdbc.Result; +import org.flywaydb.core.internal.jdbc.Results; +import org.flywaydb.core.internal.sqlscript.Delimiter; +import org.flywaydb.core.internal.sqlscript.ParsedSqlStatement; +import org.flywaydb.core.internal.sqlscript.SqlScriptExecutor; + +import java.io.Reader; +import java.io.StringReader; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.sql.Connection; +import java.sql.SQLException; + +/** + * A PostgreSQL COPY FROM STDIN statement. + */ +public class KingbaseCopyParsedStatement extends ParsedSqlStatement { + /** + * Delimiter of COPY statements. + */ + private static final Delimiter COPY_DELIMITER = new Delimiter("\\.", true + + + + ); + + private final String copyData; + + /** + * Creates a new PostgreSQL COPY ... FROM STDIN statement. + */ + public KingbaseCopyParsedStatement(int pos, int line, int col, String sql, String copyData) { + super(pos, line, col, sql, COPY_DELIMITER, true, false); + this.copyData = copyData; + } + + @Override + public Results execute(JdbcTemplate jdbcTemplate, SqlScriptExecutor sqlScriptExecutor, Configuration config) { + // #2355: Use reflection to ensure this works in cases where the PostgreSQL driver classes were loaded in a + // child URLClassLoader instead of the system classloader. + Object baseConnection; + Object copyManager; + Method copyManagerCopyInMethod; + try { + Connection connection = jdbcTemplate.getConnection(); + ClassLoader classLoader = connection.getClass().getClassLoader(); + + Class baseConnectionClass = classLoader.loadClass("org.postgresql.core.BaseConnection"); + baseConnection = connection.unwrap(baseConnectionClass); + + Class copyManagerClass = classLoader.loadClass("org.postgresql.copy.CopyManager"); + Constructor copyManagerConstructor = copyManagerClass.getConstructor(baseConnectionClass); + copyManagerCopyInMethod = copyManagerClass.getMethod("copyIn", String.class, Reader.class); + + copyManager = copyManagerConstructor.newInstance(baseConnection); + } catch (Exception e) { + throw new FlywayException("Unable to find PostgreSQL CopyManager class", e); + } + + Results results = new Results(); + try { + try { + Long updateCount = (Long) copyManagerCopyInMethod.invoke(copyManager, getSql(), new StringReader(copyData)); + results.addResult(new Result(updateCount, null, null, getSql())); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new SQLException("Unable to execute COPY operation", e); + } + } catch (SQLException e) { + jdbcTemplate.extractErrors(results, e); + } + return results; + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabase.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabase.java new file mode 100644 index 0000000..becfa04 --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabase.java @@ -0,0 +1,148 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import org.flywaydb.core.api.configuration.Configuration; +import org.flywaydb.core.extensibility.Tier; +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; +import java.sql.SQLException; + +import static org.flywaydb.core.internal.database.base.DatabaseConstants.DATABASE_HOSTING_AWS_RDS; + +public class KingbaseDatabase extends Database { + public KingbaseDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) { + super(configuration, jdbcConnectionFactory, statementInterceptor); + } + + @Override + protected KingbaseConnection doGetConnection(Connection connection) { + return new KingbaseConnection(this, connection); + } + + @Override + public void ensureSupported(Configuration configuration) { + ensureDatabaseIsRecentEnough("9.0"); + + ensureDatabaseNotOlderThanOtherwiseRecommendUpgradeToFlywayEdition("10", Tier.PREMIUM, configuration); + + recommendFlywayUpgradeIfNecessaryForMajorVersion("16"); + } + + @Override + public String getRawCreateScript(Table table, boolean baseline) { + String tablespace = configuration.getTablespace() == null + ? "" + : " TABLESPACE \"" + configuration.getTablespace() + "\""; + + return "CREATE TABLE " + table + " (\n" + + " \"installed_rank\" INT NOT NULL,\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" + + ")" + tablespace + ";\n" + + (baseline ? getBaselineStatement(table) + ";\n" : "") + + "ALTER TABLE " + table + " ADD CONSTRAINT \"" + table.getName() + "_pk\" PRIMARY KEY (\"installed_rank\")" + (configuration.getTablespace() != null ? " USING INDEX" + tablespace : "" ) + ";\n" + + "CREATE INDEX \"" + table.getName() + "_s_idx\" ON " + table + " (\"success\")" + tablespace + ";"; + } + + @Override + protected String doGetCurrentUser() throws SQLException { + return getMainConnection().getJdbcTemplate().queryForString("SELECT current_user"); + } + + @Override + public boolean supportsDdlTransactions() { + return true; + } + + @Override + public String getBooleanTrue() { + return "TRUE"; + } + + @Override + public String getBooleanFalse() { + return "FALSE"; + } + + @Override + public String doQuote(String identifier) { + return getOpenQuote() + StringUtils.replaceAll(identifier, getCloseQuote(), getEscapedQuote()) + getCloseQuote(); + } + + @Override + public String getEscapedQuote() { + return "\"\""; + } + + @Override + public boolean catalogIsSchema() { + return false; + } + + @Override + public boolean useSingleConnection() { + KingbaseConfigurationExtension configurationExtension = configuration.getPluginRegister().getPlugin(KingbaseConfigurationExtension.class); + return !configurationExtension.isTransactionalLock(); + } + + /** + * This exists to fix this issue: https://github.com/flyway/flyway/issues/2638 + * See https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html + */ + @Override + public String getSelectStatement(Table table) { + return "/*NO LOAD BALANCE*/\n" + + "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 + + " WHERE " + quote("installed_rank") + " > ?" + + " ORDER BY " + quote("installed_rank"); + } + + @Override + public String getDatabaseHosting() { + if (getMainConnection().isAwsRds()) { + return DATABASE_HOSTING_AWS_RDS; + } else { + return super.getDatabaseHosting(); + } + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabaseType.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabaseType.java new file mode 100644 index 0000000..5bed34a --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabaseType.java @@ -0,0 +1,152 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import lombok.CustomLog; +import org.flywaydb.core.api.ResourceProvider; +import org.flywaydb.core.api.configuration.Configuration; +import org.flywaydb.core.extensibility.Tier; +import org.flywaydb.core.internal.authentication.postgres.PgpassFileReader; +import org.flywaydb.core.internal.database.base.BaseDatabaseType; +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.license.FlywayEditionUpgradeRequiredException; +import org.flywaydb.core.internal.parser.Parser; +import org.flywaydb.core.internal.parser.ParsingContext; + +import java.sql.Connection; +import java.sql.Types; +import java.util.List; +import java.util.Properties; + +@CustomLog +public class KingbaseDatabaseType extends BaseDatabaseType { + + + + + @Override + public String getName() { + return "KingbaseES"; + } + + @Override + public List getSupportedEngines() { + return List.of(getName(), "KingbaseES"); + } + + @Override + public int getNullType() { + return Types.NULL; + } + + @Override + public boolean handlesJDBCUrl(String url) { + if (url.startsWith("jdbc-secretsmanager:postgresql:")) { + + + + + throw new FlywayEditionUpgradeRequiredException(Tier.ENTERPRISE, (Tier) null, "jdbc-secretsmanager"); + + } + return url.startsWith("jdbc:postgresql:") || url.startsWith("jdbc:p6spy:postgresql:"); + } + + @Override + public String getDriverClass(String url, ClassLoader classLoader) { + + + + + + if (url.startsWith("jdbc:p6spy:postgresql:")) { + return "com.p6spy.engine.spy.P6SpyDriver"; + } + return "org.postgresql.Driver"; + } + + @Override + public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection) { + return databaseProductName.startsWith("KingbaseES"); + } + + @Override + public Database createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) { + return new KingbaseDatabase(configuration, jdbcConnectionFactory, statementInterceptor); + } + + @Override + public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext) { + return new KingbaseParser(configuration, parsingContext); + } + + @Override + public void setDefaultConnectionProps(String url, Properties props, ClassLoader classLoader) { + props.put("applicationName", BaseDatabaseType.APPLICATION_NAME); + } + + @Override + public boolean detectUserRequiredByUrl(String url) { + return !url.contains("user="); + } + + @Override + public boolean detectPasswordRequiredByUrl(String url) { + + + + + + + // Postgres supports password in URL + return !url.contains("password="); + } + + @Override + public boolean externalAuthPropertiesRequired(String url, String username, String password) { + + return super.externalAuthPropertiesRequired(url, username, password); + + + + + } + + @Override + public Properties getExternalAuthProperties(String url, String username) { + PgpassFileReader pgpassFileReader = new PgpassFileReader(); + + if (pgpassFileReader.getPgpassFilePath() != null) { + LOG.info(org.flywaydb.core.internal.license.FlywayTeamsUpgradeMessage.generate( + "pgpass file '" + pgpassFileReader.getPgpassFilePath() + "'", + "use this for database authentication")); + } + return super.getExternalAuthProperties(url, username); + + + + + + + + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseParser.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseParser.java new file mode 100644 index 0000000..557145e --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseParser.java @@ -0,0 +1,155 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import lombok.CustomLog; +import org.flywaydb.core.api.configuration.Configuration; +import org.flywaydb.core.internal.parser.*; +import org.flywaydb.core.internal.sqlscript.Delimiter; +import org.flywaydb.core.internal.sqlscript.ParsedSqlStatement; + +import java.io.IOException; +import java.util.List; +import java.util.regex.Pattern; + +@CustomLog +public class KingbaseParser extends Parser { + private static final Pattern COPY_FROM_STDIN_REGEX = Pattern.compile("^COPY( .*)? FROM STDIN"); + private static final Pattern CREATE_DATABASE_TABLESPACE_SUBSCRIPTION_REGEX = Pattern.compile("^(CREATE|DROP) (DATABASE|TABLESPACE|SUBSCRIPTION)"); + private static final Pattern ALTER_SYSTEM_REGEX = Pattern.compile("^ALTER SYSTEM"); + private static final Pattern CREATE_INDEX_CONCURRENTLY_REGEX = Pattern.compile("^(CREATE|DROP)( UNIQUE)? INDEX CONCURRENTLY"); + private static final Pattern REINDEX_REGEX = Pattern.compile("^REINDEX( VERBOSE)? (SCHEMA|DATABASE|SYSTEM)"); + private static final Pattern VACUUM_REGEX = Pattern.compile("^VACUUM"); + private static final Pattern DISCARD_ALL_REGEX = Pattern.compile("^DISCARD ALL"); + private static final Pattern ALTER_TYPE_ADD_VALUE_REGEX = Pattern.compile("^ALTER TYPE( .*)? ADD VALUE"); + + private static final StatementType COPY = new StatementType(); + + public KingbaseParser(Configuration configuration, ParsingContext parsingContext) { + super(configuration, parsingContext, 3); + } + + @Override + protected char getAlternativeStringLiteralQuote() { + return '$'; + } + + @Override + protected ParsedSqlStatement createStatement(PeekingReader reader, Recorder recorder, + int statementPos, int statementLine, int statementCol, + int nonCommentPartPos, int nonCommentPartLine, int nonCommentPartCol, + StatementType statementType, boolean canExecuteInTransaction, + Delimiter delimiter, String sql + + + + , boolean batchable + ) throws IOException { + if (statementType == COPY) { + return new KingbaseCopyParsedStatement(nonCommentPartPos, nonCommentPartLine, nonCommentPartCol, + sql.substring(nonCommentPartPos - statementPos), + readCopyData(reader, recorder)); + } + return super.createStatement(reader, recorder, statementPos, statementLine, statementCol, + nonCommentPartPos, nonCommentPartLine, nonCommentPartCol, + statementType, canExecuteInTransaction, delimiter, sql + + + + , batchable + ); + } + + @Override + protected void adjustBlockDepth(ParserContext context, List tokens, Token keyword, PeekingReader reader) { + String keywordText = keyword.getText(); + + if (Parser.lastTokenIs(tokens, context.getParensDepth(), "BEGIN") && "ATOMIC".equalsIgnoreCase(keywordText)) { + context.increaseBlockDepth("ATOMIC"); + } + + if (context.getBlockDepth() > 0 && keywordText.equalsIgnoreCase("END") && "ATOMIC".equals(context.getBlockInitiator())) { + context.decreaseBlockDepth(); + } + } + + private String readCopyData(PeekingReader reader, Recorder recorder) throws IOException { + // Skip end of current line after ; + reader.readUntilIncluding('\n'); + + recorder.start(); + boolean done = false; + do { + String line = reader.readUntilIncluding('\n'); + if ("\\.".equals(line.trim())) { + done = true; + } else { + recorder.confirm(); + } + } while (!done); + + return recorder.stop(); + } + + @Override + protected StatementType detectStatementType(String simplifiedStatement, ParserContext context, PeekingReader reader) { + if (COPY_FROM_STDIN_REGEX.matcher(simplifiedStatement).matches()) { + return COPY; + } + + return super.detectStatementType(simplifiedStatement, context, reader); + } + + @Override + protected Boolean detectCanExecuteInTransaction(String simplifiedStatement, List keywords) { + if (CREATE_DATABASE_TABLESPACE_SUBSCRIPTION_REGEX.matcher(simplifiedStatement).matches() + || ALTER_SYSTEM_REGEX.matcher(simplifiedStatement).matches() + || CREATE_INDEX_CONCURRENTLY_REGEX.matcher(simplifiedStatement).matches() + || REINDEX_REGEX.matcher(simplifiedStatement).matches() + || VACUUM_REGEX.matcher(simplifiedStatement).matches() + || DISCARD_ALL_REGEX.matcher(simplifiedStatement).matches()) { + return false; + } + + boolean isDBVerUnder12 = true; + try { + isDBVerUnder12 = !parsingContext.getDatabase().getVersion().isAtLeast("12"); + } catch (Exception e) { + LOG.debug("Unable to determine database version: " + e.getMessage()); + } + + if (isDBVerUnder12 && ALTER_TYPE_ADD_VALUE_REGEX.matcher(simplifiedStatement).matches()) { + return false; + } + + return null; + } + + @SuppressWarnings("Duplicates") + @Override + protected Token handleAlternativeStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException { + // dollarQuote is required because in Postgres, literals encased in $$ can be given a label, as in: + // $label$This is a string literal$label$ + String dollarQuote = (char) reader.read() + reader.readUntilIncluding('$'); + reader.swallowUntilExcluding(dollarQuote); + reader.swallow(dollarQuote.length()); + return new Token(TokenType.STRING, pos, line, col, null, null, context.getParensDepth()); + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseSchema.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseSchema.java new file mode 100644 index 0000000..cb0beac --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseSchema.java @@ -0,0 +1,380 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import org.flywaydb.core.internal.database.base.Schema; +import org.flywaydb.core.internal.database.base.Table; +import org.flywaydb.core.internal.database.base.Type; +import org.flywaydb.core.internal.jdbc.JdbcTemplate; + +import java.sql.SQLException; +import java.util.*; + +/** + * PostgreSQL implementation of Schema. + */ +public class KingbaseSchema extends Schema { + /** + * Creates a new PostgreSQL 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 KingbaseSchema(JdbcTemplate jdbcTemplate, KingbaseDatabase database, String name) { + super(jdbcTemplate, database, name); + } + + @Override + protected boolean doExists() throws SQLException { + return jdbcTemplate.queryForInt("SELECT COUNT(*) FROM pg_namespace WHERE nspname=?", name) > 0; + } + + @Override + protected boolean doEmpty() throws SQLException { + return !jdbcTemplate.queryForBoolean("SELECT EXISTS (\n" + + " SELECT c.oid FROM pg_catalog.pg_class c\n" + + " JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + + " LEFT JOIN pg_catalog.pg_depend d ON d.objid = c.oid AND d.deptype = 'e'\n" + + " WHERE n.nspname = ? AND d.objid IS NULL AND c.relkind IN ('r', 'v', 'S', 't')\n" + + " UNION ALL\n" + + " SELECT t.oid FROM pg_catalog.pg_type t\n" + + " JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n" + + " LEFT JOIN pg_catalog.pg_depend d ON d.objid = t.oid AND d.deptype = 'e'\n" + + " WHERE n.nspname = ? AND d.objid IS NULL AND t.typcategory NOT IN ('A', 'C')\n" + + " UNION ALL\n" + + " SELECT p.oid FROM pg_catalog.pg_proc p\n" + + " JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" + + " LEFT JOIN pg_catalog.pg_depend d ON d.objid = p.oid AND d.deptype = 'e'\n" + + " WHERE n.nspname = ? AND d.objid IS NULL\n" + + ")", name, name, name); + } + + @Override + protected void doCreate() throws SQLException { + jdbcTemplate.execute("CREATE SCHEMA " + database.quote(name)); + } + + @Override + protected void doDrop() throws SQLException { + jdbcTemplate.execute("DROP SCHEMA " + database.quote(name) + " CASCADE"); + } + + @Override + protected void doClean() throws SQLException { + if (database.getVersion().isAtLeast("9.3")) { + for (String statement : generateDropStatementsForMaterializedViews()) { + jdbcTemplate.execute(statement); + } + } + + for (String statement : generateDropStatementsForViews()) { + jdbcTemplate.execute(statement); + } + + for (Table table : allTables()) { + table.drop(); + } + + for (String statement : generateDropStatementsForBaseTypes(true)) { + jdbcTemplate.execute(statement); + } + + for (String statement : generateDropStatementsForRoutines()) { + jdbcTemplate.execute(statement); + } + + for (String statement : generateDropStatementsForEnums()) { + jdbcTemplate.execute(statement); + } + + for (String statement : generateDropStatementsForDomains()) { + jdbcTemplate.execute(statement); + } + + for (String statement : generateDropStatementsForSequences()) { + jdbcTemplate.execute(statement); + } + + for (String statement : generateDropStatementsForBaseTypes(false)) { + jdbcTemplate.execute(statement); + } + + for (String statement : generateDropStatementsForExtensions()) { + jdbcTemplate.execute(statement); + } + } + + /** + * Generates the statements for dropping the extensions in this schema. + * + * @return The drop statements. + * @throws SQLException when the clean statements could not be generated. + */ + private List generateDropStatementsForExtensions() throws SQLException { + List statements = new ArrayList<>(); + + if (extensionsTableExists()) { + List extensionNames = + jdbcTemplate.queryForStringList( + "SELECT e.extname " + + "FROM pg_extension e " + + "LEFT JOIN pg_namespace n ON n.oid = e.extnamespace " + + "LEFT JOIN pg_roles r ON r.oid = e.extowner " + + "WHERE n.nspname=? AND r.rolname=?", name, database.doGetCurrentUser()); + + for (String extensionName : extensionNames) { + statements.add("DROP EXTENSION IF EXISTS " + database.quote(extensionName) + " CASCADE"); + } + } + + return statements; + } + + private boolean extensionsTableExists() throws SQLException { + return jdbcTemplate.queryForBoolean( + "SELECT EXISTS ( \n" + + "SELECT 1 \n" + + "FROM pg_tables \n" + + "WHERE tablename = 'pg_extension');"); + } + + /** + * Generates the statements for dropping the sequences in this schema. + * + * @return The drop statements. + * @throws SQLException when the clean statements could not be generated. + */ + private List generateDropStatementsForSequences() throws SQLException { + List sequenceNames = + jdbcTemplate.queryForStringList( + "SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema=?", name); + + List statements = new ArrayList<>(); + for (String sequenceName : sequenceNames) { + statements.add("DROP SEQUENCE IF EXISTS " + database.quote(name, sequenceName)); + } + + return statements; + } + + /** + * Generates the statements for dropping the types in this schema. + * + * @param recreate Flag indicating whether the types should be recreated. Necessary for type-function chicken and egg problem. + * @return The drop statements. + * @throws SQLException when the clean statements could not be generated. + */ + private List generateDropStatementsForBaseTypes(boolean recreate) throws SQLException { + List> rows = + jdbcTemplate.queryForList( + "select typname, typcategory from pg_catalog.pg_type t " + + "left join pg_depend dep on dep.objid = t.oid and dep.deptype = 'e' " + + "where (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) " + + "and NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid) " + + "and t.typnamespace in (select oid from pg_catalog.pg_namespace where nspname = ?) " + + "and dep.objid is null " + + "and t.typtype != 'd'", + name); + + List statements = new ArrayList<>(); + for (Map row : rows) { + statements.add("DROP TYPE IF EXISTS " + database.quote(name, row.get("typname")) + " CASCADE"); + } + + if (recreate) { + for (Map row : rows) { + // Only recreate Pseudo-types (P) and User-defined types (U) + if (Arrays.asList("P", "U").contains(row.get("typcategory"))) { + statements.add("CREATE TYPE " + database.quote(name, row.get("typname"))); + } + } + } + + return statements; + } + + /** + * Generates the statements for dropping the routines in this schema. + * + * @return The drop statements. + * @throws SQLException when the clean statements could not be generated. + */ + private List generateDropStatementsForRoutines() throws SQLException { + // #2193: PostgreSQL 11 removed the 'proisagg' column and replaced it with 'prokind'. + String isAggregate = database.getVersion().isAtLeast("11") ? "pg_proc.prokind = 'a'" : "pg_proc.proisagg"; + // PROCEDURE is only available from PostgreSQL 11 + String isProcedure = database.getVersion().isAtLeast("11") ? "pg_proc.prokind = 'p'" : "FALSE"; + + List> rows = + jdbcTemplate.queryForList( + // Search for all functions + "SELECT proname, oidvectortypes(proargtypes) AS args, " + isAggregate + " as agg, " + isProcedure + " as proc " + + "FROM pg_proc INNER JOIN pg_namespace ns ON (pg_proc.pronamespace = ns.oid) " + // that don't depend on an extension + + "LEFT JOIN pg_depend dep ON dep.objid = pg_proc.oid AND dep.deptype = 'e' " + + "WHERE ns.nspname = ? AND dep.objid IS NULL", + name + ); + + List statements = new ArrayList<>(); + for (Map row : rows) { + String type = "FUNCTION"; + if (isTrue(row.get("agg"))) { + type = "AGGREGATE"; + } else if (isTrue(row.get("proc"))) { + type = "PROCEDURE"; + } + statements.add("DROP " + type + " IF EXISTS " + + database.quote(name, row.get("proname")) + "(" + row.get("args") + ") CASCADE"); + } + return statements; + } + + private boolean isTrue(String agg) { + return agg != null && agg.toLowerCase(Locale.ENGLISH).startsWith("t"); + } + + /** + * Generates the statements for dropping the enums in this schema. + * + * @return The drop statements. + * @throws SQLException when the clean statements could not be generated. + */ + private List generateDropStatementsForEnums() throws SQLException { + List enumNames = + jdbcTemplate.queryForStringList( + "SELECT t.typname FROM pg_catalog.pg_type t INNER JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = ? and t.typtype = 'e'", name); + + List statements = new ArrayList<>(); + for (String enumName : enumNames) { + statements.add("DROP TYPE " + database.quote(name, enumName)); + } + + return statements; + } + + /** + * Generates the statements for dropping the domains in this schema. + * + * @return The drop statements. + * @throws SQLException when the clean statements could not be generated. + */ + private List generateDropStatementsForDomains() throws SQLException { + List domainNames = + jdbcTemplate.queryForStringList( + "SELECT t.typname as domain_name\n" + + "FROM pg_catalog.pg_type t\n" + + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n" + + " LEFT JOIN pg_depend dep ON dep.objid = t.oid AND dep.deptype = 'e'\n" + + "WHERE t.typtype = 'd'\n" + + " AND n.nspname = ?\n" + + " AND dep.objid IS NULL" + , name); + + List statements = new ArrayList<>(); + for (String domainName : domainNames) { + statements.add("DROP DOMAIN IF EXISTS " + database.quote(name, domainName) + " CASCADE"); + } + + return statements; + } + + /** + * Generates the statements for dropping the materialized views in this schema. + * + * @return The drop statements. + * @throws SQLException when the clean statements could not be generated. + */ + private List generateDropStatementsForMaterializedViews() throws SQLException { + List viewNames = + jdbcTemplate.queryForStringList( + "SELECT relname FROM pg_catalog.pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace" + + " WHERE c.relkind = 'm' AND n.nspname = ?", name); + + List statements = new ArrayList<>(); + for (String domainName : viewNames) { + statements.add("DROP MATERIALIZED VIEW IF EXISTS " + database.quote(name, domainName) + " CASCADE"); + } + + return statements; + } + + /** + * Generates the statements for dropping the views in this schema. + * + * @return The drop statements. + * @throws SQLException when the clean statements could not be generated. + */ + private List generateDropStatementsForViews() throws SQLException { + List viewNames = + jdbcTemplate.queryForStringList( + // Search for all views + "SELECT relname FROM pg_catalog.pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace" + + // that don't depend on an extension + " LEFT JOIN pg_depend dep ON dep.objid = c.oid AND dep.deptype = 'e'" + + " WHERE c.relkind = 'v' AND n.nspname = ? AND dep.objid IS NULL", + name); + List statements = new ArrayList<>(); + for (String domainName : viewNames) { + statements.add("DROP VIEW IF EXISTS " + database.quote(name, domainName) + " CASCADE"); + } + + return statements; + } + + @Override + protected KingbaseTable[] doAllTables() throws SQLException { + List tableNames = + jdbcTemplate.queryForStringList( + //Search for all the table names + "SELECT t.table_name FROM information_schema.tables t" + + // that don't depend on an extension + " LEFT JOIN pg_depend dep ON dep.objid = (quote_ident(t.table_schema)||'.'||quote_ident(t.table_name))::regclass::oid AND dep.deptype = 'e'" + + // in this schema + " WHERE table_schema=?" + + //that are real tables (as opposed to views) + " AND table_type='BASE TABLE'" + + // with no extension depending on them + " AND dep.objid IS NULL" + + // and are not child tables (= do not inherit from another table). + " AND NOT (SELECT EXISTS (SELECT inhrelid FROM pg_catalog.pg_inherits" + + " WHERE inhrelid = (quote_ident(t.table_schema)||'.'||quote_ident(t.table_name))::regclass::oid))", + name + ); + //Views and child tables are excluded as they are dropped with the parent table when using cascade. + + KingbaseTable[] tables = new KingbaseTable[tableNames.size()]; + for (int i = 0; i < tableNames.size(); i++) { + tables[i] = new KingbaseTable(jdbcTemplate, database, this, tableNames.get(i)); + } + return tables; + } + + @Override + public Table getTable(String tableName) { + return new KingbaseTable(jdbcTemplate, database, this, tableName); + } + + @Override + protected Type getType(String typeName) { + return new KingbaseType(jdbcTemplate, database, this, typeName); + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseTable.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseTable.java new file mode 100644 index 0000000..fed7304 --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseTable.java @@ -0,0 +1,64 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import org.flywaydb.core.internal.database.base.Table; +import org.flywaydb.core.internal.jdbc.JdbcTemplate; + +import java.sql.SQLException; + +/** + * PostgreSQL-specific table. + */ +public class KingbaseTable extends Table { + /** + * Creates a new PostgreSQL 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 KingbaseTable(JdbcTemplate jdbcTemplate, KingbaseDatabase database, KingbaseSchema schema, String name) { + super(jdbcTemplate, database, schema, name); + } + + @Override + protected void doDrop() throws SQLException { + jdbcTemplate.execute("DROP TABLE " + database.quote(schema.getName(), name) + " CASCADE"); + } + + @Override + protected boolean doExists() throws SQLException { + return jdbcTemplate.queryForBoolean("SELECT EXISTS (\n" + + " SELECT 1\n" + + " FROM pg_catalog.pg_class c\n" + + " JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + + " WHERE n.nspname = ?\n" + + " AND c.relname = ?\n" + + " AND c.relkind = 'r'\n" + // only tables + ")", schema.getName(), name); + } + + @Override + protected void doLock() throws SQLException { + jdbcTemplate.execute("SELECT * FROM " + this + " FOR UPDATE"); + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseType.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseType.java new file mode 100644 index 0000000..da2ea37 --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseType.java @@ -0,0 +1,47 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import org.flywaydb.core.internal.database.base.Type; +import org.flywaydb.core.internal.jdbc.JdbcTemplate; + +import java.sql.SQLException; + +/** + * PostgreSQL-specific type. + */ +public class KingbaseType extends Type { + /** + * Creates a new PostgreSQL type. + * + * @param jdbcTemplate The Jdbc Template for communicating with the DB. + * @param database The database-specific support. + * @param schema The schema this type lives in. + * @param name The name of the type. + */ + public KingbaseType(JdbcTemplate jdbcTemplate, KingbaseDatabase database, KingbaseSchema schema, String name) { + super(jdbcTemplate, database, schema, name); + } + + @Override + protected void doDrop() throws SQLException { + jdbcTemplate.execute("DROP TYPE " + database.quote(schema.getName(), name)); + } +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/TransactionalModel.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/TransactionalModel.java new file mode 100644 index 0000000..f9e9b98 --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/TransactionalModel.java @@ -0,0 +1,27 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import lombok.Data; + +@Data +public class TransactionalModel { + private Boolean lock = null; +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/package-info.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/package-info.java new file mode 100644 index 0000000..92aabb9 --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/package-info.java @@ -0,0 +1,23 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-postgresql + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ +/** + * Private API. No compatibility guarantees provided. + */ +package org.flywaydb.community.database.kingbase; diff --git a/flyway-database-kingbase/src/main/resources/META-INF/services/org.flywaydb.core.extensibility.Plugin b/flyway-database-kingbase/src/main/resources/META-INF/services/org.flywaydb.core.extensibility.Plugin new file mode 100644 index 0000000..e6e25a3 --- /dev/null +++ b/flyway-database-kingbase/src/main/resources/META-INF/services/org.flywaydb.core.extensibility.Plugin @@ -0,0 +1 @@ +org.flywaydb.community.database.kingbase.KingbaseDatabaseType \ No newline at end of file diff --git a/flyway-database-kingbase/src/main/resources/org/flywaydb/community/database/kingbase/version.txt b/flyway-database-kingbase/src/main/resources/org/flywaydb/community/database/kingbase/version.txt new file mode 100644 index 0000000..1785151 --- /dev/null +++ b/flyway-database-kingbase/src/main/resources/org/flywaydb/community/database/kingbase/version.txt @@ -0,0 +1 @@ +${pom.version} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 23a9e7a..2db4f6c 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,7 @@ flyway-database-oceanbase flyway-database-databricks flyway-database-db2zos + flyway-database-kingbase flyway-community-db-support-archetype From 60fce5d40ebd2aa2bc42150fb61382e488c76ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=98=89=E4=BF=8A?= <> Date: Wed, 11 Sep 2024 18:02:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update=20=E4=BF=AE=E6=94=B9=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 169 ++------ .../database/ClickHouseDatabaseExtension.java | 19 + .../ClickHouseConfigurationExtension.java | 19 + .../clickhouse/ClickHouseConnection.java | 19 + .../clickhouse/ClickHouseDatabase.java | 19 + .../clickhouse/ClickHouseDatabaseType.java | 19 + .../database/clickhouse/ClickHouseParser.java | 19 + .../database/clickhouse/ClickHouseSchema.java | 19 + .../database/clickhouse/ClickHouseTable.java | 19 + .../database/DatabricksDatabaseExtension.java | 19 + .../databricks/DatabricksConnection.java | 19 + .../databricks/DatabricksDatabase.java | 19 + .../databricks/DatabricksDatabaseType.java | 19 + .../database/databricks/DatabricksParser.java | 19 + .../database/databricks/DatabricksSchema.java | 19 + .../database/databricks/DatabricksTable.java | 19 + .../database/databricks/package-info.java | 19 + .../database/DB2ZDatabaseExtension.java | 19 + .../DB2ZCallProcedureParsedStatement.java | 19 + .../db2z/DB2ZConfigurationExtension.java | 19 + .../database/db2z/DB2ZConnection.java | 19 + .../community/database/db2z/DB2ZDatabase.java | 19 + .../database/db2z/DB2ZDatabaseType.java | 19 + .../community/database/db2z/DB2ZFunction.java | 19 + .../database/db2z/DB2ZJdbcTemplate.java | 19 + .../community/database/db2z/DB2ZParser.java | 19 + .../community/database/db2z/DB2ZSchema.java | 19 + .../community/database/db2z/DB2ZTable.java | 19 + .../community/database/db2z/DB2ZType.java | 19 + .../community/database/db2z/package-info.java | 19 + .../database/IgniteDatabaseExtension.java | 19 + .../ignite/thin/IgniteThinConnection.java | 21 +- .../ignite/thin/IgniteThinDatabase.java | 21 +- .../ignite/thin/IgniteThinDatabaseType.java | 19 + .../ignite/thin/IgniteThinParser.java | 21 +- .../ignite/thin/IgniteThinSchema.java | 21 +- .../database/ignite/thin/IgniteThinTable.java | 21 +- .../database/ignite/thin/package-info.java | 21 +- .../KingbaseAdvisoryLockTemplate.java | 123 ------ .../KingbaseConfigurationExtension.java | 52 --- .../database/kingbase/KingbaseConnection.java | 99 +---- .../kingbase/KingbaseCopyParsedStatement.java | 98 ----- .../database/kingbase/KingbaseDatabase.java | 131 +++---- .../kingbase/KingbaseDatabaseType.java | 132 ++----- .../kingbase/KingbaseExecutionTemplate.java | 188 +++++++++ .../database/kingbase/KingbaseParser.java | 152 +------- .../database/kingbase/KingbaseSchema.java | 365 +----------------- .../database/kingbase/KingbaseTable.java | 54 +-- .../database/kingbase/KingbaseType.java | 47 --- .../database/kingbase/TransactionalModel.java | 27 -- .../database/OceanBaseDatabaseExtension.java | 19 + .../oceanbase/OceanBaseConnection.java | 19 + .../database/oceanbase/OceanBaseDatabase.java | 19 + .../oceanbase/OceanBaseDatabaseType.java | 19 + .../oceanbase/OceanBaseJdbcUtils.java | 19 + .../database/oceanbase/package-info.java | 19 + .../database/TiDBDatabaseExtension.java | 19 + .../database/mysql/tidb/TiDBConnection.java | 21 +- .../database/mysql/tidb/TiDBDatabase.java | 21 +- .../database/mysql/tidb/TiDBDatabaseType.java | 21 +- .../database/mysql/tidb/package-info.java | 21 +- .../database/YugabyteDBDatabaseExtension.java | 19 + .../yugabytedb/YugabyteDBConnection.java | 21 +- .../yugabytedb/YugabyteDBDatabase.java | 19 + .../yugabytedb/YugabyteDBDatabaseType.java | 21 +- .../YugabyteDBExecutionTemplate.java | 19 + .../yugabytedb/YugabyteDBParser.java | 21 +- .../yugabytedb/YugabyteDBSchema.java | 21 +- .../yugabytedb/YugabyteDBTable.java | 21 +- .../postgresql/yugabytedb/package-info.java | 21 +- 70 files changed, 1491 insertions(+), 1261 deletions(-) delete mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseAdvisoryLockTemplate.java delete mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConfigurationExtension.java delete mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseCopyParsedStatement.java create mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseExecutionTemplate.java delete mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseType.java delete mode 100644 flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/TransactionalModel.java diff --git a/.gitignore b/.gitignore index 9791221..4ae1de9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,139 +1,38 @@ -### Intellij template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# AWS User-specific -.idea/**/aws.xml - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# SonarLint plugin -.idea/sonarlint/ - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### Java template -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* - -### Maven template +HELP.md target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -# https://github.com/takari/maven-wrapper#usage-without-binary-jar -.mvn/wrapper/maven-wrapper.jar +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ -# Eclipse m2e generated files -# Eclipse Core -.project -# JDT-specific (Eclipse Java Development Tools) +### STS ### +.apt_generated .classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +.fastRequest -### Git template -# Created by git for backups. To disable backups in Git: -# $ git config --global mergetool.keepBackup false -*.orig - -# Created by git when using merge tools for conflicts -*.BACKUP.* -*.BASE.* -*.LOCAL.* -*.REMOTE.* -*_BACKUP_*.txt -*_BASE_*.txt -*_LOCAL_*.txt -*_REMOTE_*.txt - +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +.version* +.back* + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ +*.log +*.gz \ No newline at end of file diff --git a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/ClickHouseDatabaseExtension.java b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/ClickHouseDatabaseExtension.java index 728ace9..96d0422 100644 --- a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/ClickHouseDatabaseExtension.java +++ b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/ClickHouseDatabaseExtension.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-clickhouse + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseConfigurationExtension.java b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseConfigurationExtension.java index 394e29b..8863ec3 100644 --- a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseConfigurationExtension.java +++ b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseConfigurationExtension.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-clickhouse + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseConnection.java b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseConnection.java index bd6e54c..1e228b1 100644 --- a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseConnection.java +++ b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseConnection.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-clickhouse + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseDatabase.java b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseDatabase.java index ccbe7c0..79dba05 100644 --- a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseDatabase.java +++ b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseDatabase.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-clickhouse + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseDatabaseType.java b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseDatabaseType.java index 8575ca6..6e9fc26 100644 --- a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseDatabaseType.java +++ b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseDatabaseType.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-clickhouse + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseParser.java b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseParser.java index 971b68d..aebff9f 100644 --- a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseParser.java +++ b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseParser.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-clickhouse + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseSchema.java b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseSchema.java index b005b57..8bdcaa5 100644 --- a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseSchema.java +++ b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseSchema.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-clickhouse + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseTable.java b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseTable.java index 9a9ecb4..00d5e08 100644 --- a/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseTable.java +++ b/flyway-database-clickhouse/src/main/java/org/flywaydb/community/database/clickhouse/ClickHouseTable.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-clickhouse + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/DatabricksDatabaseExtension.java b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/DatabricksDatabaseExtension.java index ea432ea..4ff06c2 100644 --- a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/DatabricksDatabaseExtension.java +++ b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/DatabricksDatabaseExtension.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-databricks + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksConnection.java b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksConnection.java index 0456db9..3b51f1f 100644 --- a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksConnection.java +++ b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksConnection.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-databricks + * ======================================================================== + * Copyright (C) 2010 - 2024 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.databricks; import org.flywaydb.core.api.FlywayException; diff --git a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksDatabase.java b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksDatabase.java index b96a730..ff36fac 100644 --- a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksDatabase.java +++ b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksDatabase.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-databricks + * ======================================================================== + * Copyright (C) 2010 - 2024 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.databricks; import org.flywaydb.core.api.configuration.Configuration; diff --git a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksDatabaseType.java b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksDatabaseType.java index a35e7a4..592f704 100644 --- a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksDatabaseType.java +++ b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksDatabaseType.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-databricks + * ======================================================================== + * Copyright (C) 2010 - 2024 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.databricks; import org.flywaydb.core.api.ResourceProvider; diff --git a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksParser.java b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksParser.java index 84ec10d..98bd064 100644 --- a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksParser.java +++ b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksParser.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-databricks + * ======================================================================== + * Copyright (C) 2010 - 2024 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.databricks; import org.flywaydb.core.api.configuration.Configuration; diff --git a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksSchema.java b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksSchema.java index b562998..5930511 100644 --- a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksSchema.java +++ b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksSchema.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-databricks + * ======================================================================== + * Copyright (C) 2010 - 2024 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.databricks; import org.flywaydb.core.internal.database.base.Schema; diff --git a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksTable.java b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksTable.java index 2a0bf88..f69dcec 100644 --- a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksTable.java +++ b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/DatabricksTable.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-databricks + * ======================================================================== + * Copyright (C) 2010 - 2024 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.databricks; import org.flywaydb.core.internal.database.InsertRowLock; diff --git a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/package-info.java b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/package-info.java index 25d42b2..1f101a5 100644 --- a/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/package-info.java +++ b/flyway-database-databricks/src/main/java/org/flywaydb/community/database/databricks/package-info.java @@ -1 +1,20 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-databricks + * ======================================================================== + * Copyright (C) 2010 - 2024 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.databricks; diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/DB2ZDatabaseExtension.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/DB2ZDatabaseExtension.java index b2be151..8958da3 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/DB2ZDatabaseExtension.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/DB2ZDatabaseExtension.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZCallProcedureParsedStatement.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZCallProcedureParsedStatement.java index 7872e00..7749ee7 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZCallProcedureParsedStatement.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZCallProcedureParsedStatement.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZConfigurationExtension.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZConfigurationExtension.java index 6349f77..2692bf9 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZConfigurationExtension.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZConfigurationExtension.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZConnection.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZConnection.java index 29d2d3b..4620e07 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZConnection.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZConnection.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZDatabase.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZDatabase.java index 8337262..e12a6f8 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZDatabase.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZDatabase.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZDatabaseType.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZDatabaseType.java index 2ae3516..f9485b6 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZDatabaseType.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZDatabaseType.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZFunction.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZFunction.java index 22b63ee..734d785 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZFunction.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZFunction.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZJdbcTemplate.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZJdbcTemplate.java index 8982518..46c6350 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZJdbcTemplate.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZJdbcTemplate.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZParser.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZParser.java index 4eb8210..eec3203 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZParser.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZParser.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZSchema.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZSchema.java index 37a3400..d63bdcb 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZSchema.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZSchema.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZTable.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZTable.java index db36c28..ddae939 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZTable.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZTable.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZType.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZType.java index e7c0610..ba18d36 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZType.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/DB2ZType.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/package-info.java b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/package-info.java index 43b9a17..37682ab 100644 --- a/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/package-info.java +++ b/flyway-database-db2zos/src/main/java/org/flywaydb/community/database/db2z/package-info.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-db2zos + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2022 * diff --git a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/IgniteDatabaseExtension.java b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/IgniteDatabaseExtension.java index e5b0828..18979f1 100644 --- a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/IgniteDatabaseExtension.java +++ b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/IgniteDatabaseExtension.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-ignite + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinConnection.java b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinConnection.java index 5b89cc1..92f1c00 100644 --- a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinConnection.java +++ b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinConnection.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-ignite + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -43,4 +62,4 @@ public Schema getSchema(String name) { protected String getCurrentSchemaNameOrSearchPath() throws SQLException { return getJdbcConnection().getSchema(); } -} \ No newline at end of file +} diff --git a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinDatabase.java b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinDatabase.java index 4b987ad..f086647 100644 --- a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinDatabase.java +++ b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinDatabase.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-ignite + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -160,4 +179,4 @@ public String getBooleanFalse() { public boolean catalogIsSchema() { return false; } -} \ No newline at end of file +} diff --git a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinDatabaseType.java b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinDatabaseType.java index 8f5bbab..1e29742 100644 --- a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinDatabaseType.java +++ b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinDatabaseType.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-ignite + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinParser.java b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinParser.java index 9231d8b..423fd10 100644 --- a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinParser.java +++ b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinParser.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-ignite + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -52,4 +71,4 @@ protected Token handleAlternativeStringLiteral(PeekingReader reader, ParserConte protected Boolean detectCanExecuteInTransaction(String simplifiedStatement, List keywords) { return keywords.stream().noneMatch(token -> token.getType().equals(TokenType.KEYWORD) && DDL_KEYWORDS.contains(token.getText())); } -} \ No newline at end of file +} diff --git a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinSchema.java b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinSchema.java index 7c00ddf..816d657 100644 --- a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinSchema.java +++ b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinSchema.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-ignite + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -166,4 +185,4 @@ private List listObjectNames(String objectType, String querySuffix) thro public Table getTable(String tableName) { return new IgniteThinTable(jdbcTemplate, database, this, tableName); } -} \ No newline at end of file +} diff --git a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinTable.java b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinTable.java index 9259cc8..0639edf 100644 --- a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinTable.java +++ b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/IgniteThinTable.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-ignite + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -100,4 +119,4 @@ private boolean insertLockingRow() { // Succeeded if no errors. return results.getException() == null; } -} \ No newline at end of file +} diff --git a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/package-info.java b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/package-info.java index 359c284..c0cc065 100644 --- a/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/package-info.java +++ b/flyway-database-ignite/src/main/java/org/flywaydb/community/database/ignite/thin/package-info.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-ignite + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -16,4 +35,4 @@ /** * Community-supported package. No compatibility guarantees provided. */ -package org.flywaydb.community.database.ignite.thin; \ No newline at end of file +package org.flywaydb.community.database.ignite.thin; diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseAdvisoryLockTemplate.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseAdvisoryLockTemplate.java deleted file mode 100644 index d4c5fcb..0000000 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseAdvisoryLockTemplate.java +++ /dev/null @@ -1,123 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * flyway-database-postgresql - * ======================================================================== - * Copyright (C) 2010 - 2024 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.kingbase; - -import lombok.CustomLog; -import org.flywaydb.core.api.FlywayException; -import org.flywaydb.core.api.configuration.Configuration; -import org.flywaydb.core.internal.exception.FlywaySqlException; -import org.flywaydb.core.internal.jdbc.JdbcTemplate; -import org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate; -import org.flywaydb.core.internal.strategy.RetryStrategy; -import org.flywaydb.core.internal.util.FlywayDbWebsiteLinks; -import org.flywaydb.core.internal.util.SqlCallable; - -import java.sql.SQLException; -import java.util.List; -import java.util.concurrent.Callable; - -@CustomLog -public class KingbaseAdvisoryLockTemplate { - private static final long LOCK_MAGIC_NUM = - (0x46L << 40) // F - + (0x6CL << 32) // l - + (0x79L << 24) // y - + (0x77 << 16) // w - + (0x61 << 8) // a - + 0x79; // y - - private final Configuration configuration; - private final JdbcTemplate jdbcTemplate; - private final long lockNum; - - KingbaseAdvisoryLockTemplate(Configuration configuration, JdbcTemplate jdbcTemplate, int discriminator) { - this.configuration = configuration; - this.jdbcTemplate = jdbcTemplate; - this.lockNum = LOCK_MAGIC_NUM + discriminator; - } - - public T execute(Callable callable) { - KingbaseConfigurationExtension configurationExtension = configuration.getPluginRegister().getPlugin(KingbaseConfigurationExtension.class); - - if (configurationExtension.isTransactionalLock()) { - return new TransactionalExecutionTemplate(jdbcTemplate.getConnection(), true).execute(() -> execute(callable, this::tryLockTransactional)); - } else { - RuntimeException rethrow = null; - try { - return execute(callable, this::tryLock); - } catch (RuntimeException e) { - rethrow = e; - throw rethrow; - } finally { - unlock(rethrow); - } - } - } - - private T execute(Callable callable, SqlCallable tryLock) { - try { - lock(tryLock); - return callable.call(); - } catch (SQLException e) { - throw new FlywaySqlException("Unable to acquire PostgreSQL advisory lock", e); - } catch (Exception e) { - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - throw new FlywayException(e); - } - } - - private void lock(SqlCallable tryLock) throws SQLException { - RetryStrategy strategy = new RetryStrategy(); - strategy.doWithRetries(tryLock, "Interrupted while attempting to acquire PostgreSQL advisory lock", - "Number of retries exceeded while attempting to acquire PostgreSQL advisory lock. " + - "Configure the number of retries with the 'lockRetryCount' configuration option: " + FlywayDbWebsiteLinks.LOCK_RETRY_COUNT); - } - - private boolean tryLockTransactional() throws SQLException { - List results = jdbcTemplate.query("SELECT pg_try_advisory_xact_lock(" + lockNum + ")", rs -> rs.getBoolean("pg_try_advisory_xact_lock")); - return results.size() == 1 && results.get(0); - } - - private boolean tryLock() throws SQLException { - List results = jdbcTemplate.query("SELECT pg_try_advisory_lock(" + lockNum + ")", rs -> rs.getBoolean("pg_try_advisory_lock")); - return results.size() == 1 && results.get(0); - } - - private void unlock(RuntimeException rethrow) throws FlywaySqlException { - try { - boolean unlocked = jdbcTemplate.queryForBoolean("SELECT pg_advisory_unlock(" + lockNum + ")"); - if (!unlocked) { - if (rethrow == null) { - throw new FlywayException("Unable to release PostgreSQL advisory lock"); - } else { - LOG.error("Unable to release PostgreSQL advisory lock"); - } - } - } catch (SQLException e) { - if (rethrow == null) { - throw new FlywaySqlException("Unable to release PostgreSQL advisory lock", e); - } else { - LOG.error("Unable to release PostgreSQL advisory lock", e); - } - } - } -} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConfigurationExtension.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConfigurationExtension.java deleted file mode 100644 index 8e04b4b..0000000 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConfigurationExtension.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * flyway-database-postgresql - * ======================================================================== - * Copyright (C) 2010 - 2024 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.kingbase; - -import lombok.Data; -import org.flywaydb.core.extensibility.ConfigurationExtension; - -@Data -public class KingbaseConfigurationExtension implements ConfigurationExtension { - private static final String TRANSACTIONAL_LOCK = "flyway.postgresql.transactional.lock"; - - private TransactionalModel transactional = null; - - public boolean isTransactionalLock() { - // null is default, default is true, done this way for merge reasons. - return transactional == null || transactional.getLock() == null || transactional.getLock(); - } - - public void setTransactionalLock(boolean transactionalLock) { - transactional = new TransactionalModel(); - transactional.setLock(transactionalLock); - } - @Override - public String getConfigurationParameterFromEnvironmentVariable(String environmentVariable) { - if ("FLYWAY_POSTGRESQL_TRANSACTIONAL_LOCK".equals(environmentVariable)) { - return TRANSACTIONAL_LOCK; - } - return null; - } - - @Override - public String getNamespace() { - return "postgresql"; - } -} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConnection.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConnection.java index 251b05b..cc61127 100644 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConnection.java +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseConnection.java @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * flyway-database-postgresql + * flyway-database-yugabytedb * ======================================================================== * Copyright (C) 2010 - 2024 Red Gate Software Ltd * ======================================================================== @@ -17,99 +17,42 @@ * limitations under the License. * =========================LICENSE_END================================== */ +/* + * 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. + */ package org.flywaydb.community.database.kingbase; -import lombok.Getter; -import org.flywaydb.core.api.FlywayException; -import org.flywaydb.core.internal.database.base.Connection; import org.flywaydb.core.internal.database.base.Schema; import org.flywaydb.core.internal.database.base.Table; -import org.flywaydb.core.internal.exception.FlywaySqlException; -import org.flywaydb.core.internal.util.StringUtils; +import org.flywaydb.database.postgresql.PostgreSQLConnection; -import java.sql.SQLException; import java.util.concurrent.Callable; -public class KingbaseConnection extends Connection { - private final String originalRole; - @Getter - private final boolean awsRds; +public class KingbaseConnection extends PostgreSQLConnection { - protected KingbaseConnection(KingbaseDatabase database, java.sql.Connection connection) { + KingbaseConnection(KingbaseDatabase database, java.sql.Connection connection) { super(database, connection); - - try { - originalRole = jdbcTemplate.queryForString("SELECT CURRENT_USER"); - } catch (SQLException e) { - throw new FlywaySqlException("Unable to determine current user", e); - } - - awsRds = rdsAdminExists(); - } - - @Override - protected void doRestoreOriginalState() throws SQLException { - // Reset the role to its original value in case a migration or callback changed it - jdbcTemplate.execute("SET ROLE '" + originalRole + "'"); - } - - @Override - public Schema doGetCurrentSchema() throws SQLException { - String currentSchema = jdbcTemplate.queryForString("SELECT current_schema"); - String searchPath = getCurrentSchemaNameOrSearchPath(); - - if (!StringUtils.hasText(currentSchema) && !StringUtils.hasText(searchPath)) { - throw new FlywayException("Unable to determine current schema as search_path is empty. " + - "Set the current schema in currentSchema parameter of the JDBC URL or in Flyway's schemas property."); - } - - String schema = StringUtils.hasText(currentSchema) ? currentSchema : searchPath; - - return getSchema(schema); - } - - @Override - protected String getCurrentSchemaNameOrSearchPath() throws SQLException { - return jdbcTemplate.queryForString("SHOW search_path"); - } - - @Override - public void changeCurrentSchemaTo(Schema schema) { - try { - if (schema.getName().equals(originalSchemaNameOrSearchPath) || originalSchemaNameOrSearchPath.startsWith(schema.getName() + ",") || !schema.exists()) { - return; - } - - if (StringUtils.hasText(originalSchemaNameOrSearchPath)) { - doChangeCurrentSchemaOrSearchPathTo(schema + "," + originalSchemaNameOrSearchPath); - } else { - doChangeCurrentSchemaOrSearchPathTo(schema.toString()); - } - } catch (SQLException e) { - throw new FlywaySqlException("Error setting current schema to " + schema, e); - } - } - - @Override - public void doChangeCurrentSchemaOrSearchPathTo(String schema) throws SQLException { - jdbcTemplate.execute("SELECT set_config('search_path', ?, false)", schema); } @Override public Schema getSchema(String name) { - return new KingbaseSchema(jdbcTemplate, database, name); + return new KingbaseSchema(jdbcTemplate, (KingbaseDatabase) database, name); } @Override public T lock(Table table, Callable callable) { - return new KingbaseAdvisoryLockTemplate(database.getConfiguration(), jdbcTemplate, table.toString().hashCode()).execute(callable); - } - - private boolean rdsAdminExists() { - try { - return StringUtils.hasText(jdbcTemplate.queryForString("SELECT rolname FROM pg_roles WHERE rolname ILIKE 'rds_superuser';")); - } catch (Exception e) { - return false; - } + return new KingbaseExecutionTemplate(jdbcTemplate, table.toString()).execute(callable); } } diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseCopyParsedStatement.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseCopyParsedStatement.java deleted file mode 100644 index e167c29..0000000 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseCopyParsedStatement.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * flyway-database-postgresql - * ======================================================================== - * Copyright (C) 2010 - 2024 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.kingbase; - -import org.flywaydb.core.api.FlywayException; -import org.flywaydb.core.api.configuration.Configuration; -import org.flywaydb.core.internal.jdbc.JdbcTemplate; -import org.flywaydb.core.internal.jdbc.Result; -import org.flywaydb.core.internal.jdbc.Results; -import org.flywaydb.core.internal.sqlscript.Delimiter; -import org.flywaydb.core.internal.sqlscript.ParsedSqlStatement; -import org.flywaydb.core.internal.sqlscript.SqlScriptExecutor; - -import java.io.Reader; -import java.io.StringReader; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.sql.Connection; -import java.sql.SQLException; - -/** - * A PostgreSQL COPY FROM STDIN statement. - */ -public class KingbaseCopyParsedStatement extends ParsedSqlStatement { - /** - * Delimiter of COPY statements. - */ - private static final Delimiter COPY_DELIMITER = new Delimiter("\\.", true - - - - ); - - private final String copyData; - - /** - * Creates a new PostgreSQL COPY ... FROM STDIN statement. - */ - public KingbaseCopyParsedStatement(int pos, int line, int col, String sql, String copyData) { - super(pos, line, col, sql, COPY_DELIMITER, true, false); - this.copyData = copyData; - } - - @Override - public Results execute(JdbcTemplate jdbcTemplate, SqlScriptExecutor sqlScriptExecutor, Configuration config) { - // #2355: Use reflection to ensure this works in cases where the PostgreSQL driver classes were loaded in a - // child URLClassLoader instead of the system classloader. - Object baseConnection; - Object copyManager; - Method copyManagerCopyInMethod; - try { - Connection connection = jdbcTemplate.getConnection(); - ClassLoader classLoader = connection.getClass().getClassLoader(); - - Class baseConnectionClass = classLoader.loadClass("org.postgresql.core.BaseConnection"); - baseConnection = connection.unwrap(baseConnectionClass); - - Class copyManagerClass = classLoader.loadClass("org.postgresql.copy.CopyManager"); - Constructor copyManagerConstructor = copyManagerClass.getConstructor(baseConnectionClass); - copyManagerCopyInMethod = copyManagerClass.getMethod("copyIn", String.class, Reader.class); - - copyManager = copyManagerConstructor.newInstance(baseConnection); - } catch (Exception e) { - throw new FlywayException("Unable to find PostgreSQL CopyManager class", e); - } - - Results results = new Results(); - try { - try { - Long updateCount = (Long) copyManagerCopyInMethod.invoke(copyManager, getSql(), new StringReader(copyData)); - results.addResult(new Result(updateCount, null, null, getSql())); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new SQLException("Unable to execute COPY operation", e); - } - } catch (SQLException e) { - jdbcTemplate.extractErrors(results, e); - } - return results; - } -} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabase.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabase.java index becfa04..6e4738a 100644 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabase.java +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabase.java @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * flyway-database-postgresql + * flyway-database-yugabytedb * ======================================================================== * Copyright (C) 2010 - 2024 Red Gate Software Ltd * ======================================================================== @@ -17,24 +17,49 @@ * limitations under the License. * =========================LICENSE_END================================== */ +/* + * 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. + */ package org.flywaydb.community.database.kingbase; +import lombok.CustomLog; import org.flywaydb.core.api.configuration.Configuration; -import org.flywaydb.core.extensibility.Tier; -import org.flywaydb.core.internal.database.base.Database; import org.flywaydb.core.internal.database.base.Table; +import org.flywaydb.core.internal.exception.FlywaySqlException; import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory; import org.flywaydb.core.internal.jdbc.StatementInterceptor; -import org.flywaydb.core.internal.util.StringUtils; +import org.flywaydb.database.postgresql.PostgreSQLDatabase; import java.sql.Connection; import java.sql.SQLException; -import static org.flywaydb.core.internal.database.base.DatabaseConstants.DATABASE_HOSTING_AWS_RDS; -public class KingbaseDatabase extends Database { +@CustomLog +public class KingbaseDatabase extends PostgreSQLDatabase { + + public static final String LOCK_TABLE_NAME = "YB_FLYWAY_LOCK_TABLE"; + /** + * This table is used to enforce locking through SELECT ... FOR UPDATE on a + * token row inserted in this table. The token row is inserted with the name + * of the Flyway's migration history table as a token for simplicity. + */ + private static final String CREATE_LOCK_TABLE_DDL = "CREATE TABLE IF NOT EXISTS " + LOCK_TABLE_NAME + " (table_name varchar PRIMARY KEY, locked bool)"; + public KingbaseDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) { super(configuration, jdbcConnectionFactory, statementInterceptor); + createLockTable(); } @Override @@ -44,21 +69,19 @@ protected KingbaseConnection doGetConnection(Connection connection) { @Override public void ensureSupported(Configuration configuration) { - ensureDatabaseIsRecentEnough("9.0"); - - ensureDatabaseNotOlderThanOtherwiseRecommendUpgradeToFlywayEdition("10", Tier.PREMIUM, configuration); + // Checks the Postgres version + ensureDatabaseIsRecentEnough("11.2"); + } - recommendFlywayUpgradeIfNecessaryForMajorVersion("16"); + @Override + public boolean supportsDdlTransactions() { + return false; } @Override public String getRawCreateScript(Table table, boolean baseline) { - String tablespace = configuration.getTablespace() == null - ? "" - : " TABLESPACE \"" + configuration.getTablespace() + "\""; - - return "CREATE TABLE " + table + " (\n" + - " \"installed_rank\" INT NOT NULL,\n" + + 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" + @@ -68,81 +91,21 @@ public String getRawCreateScript(Table table, boolean baseline) { " \"installed_on\" TIMESTAMP NOT NULL DEFAULT now(),\n" + " \"execution_time\" INTEGER NOT NULL,\n" + " \"success\" BOOLEAN NOT NULL\n" + - ")" + tablespace + ";\n" + + ");\n" + (baseline ? getBaselineStatement(table) + ";\n" : "") + - "ALTER TABLE " + table + " ADD CONSTRAINT \"" + table.getName() + "_pk\" PRIMARY KEY (\"installed_rank\")" + (configuration.getTablespace() != null ? " USING INDEX" + tablespace : "" ) + ";\n" + - "CREATE INDEX \"" + table.getName() + "_s_idx\" ON " + table + " (\"success\")" + tablespace + ";"; - } - - @Override - protected String doGetCurrentUser() throws SQLException { - return getMainConnection().getJdbcTemplate().queryForString("SELECT current_user"); - } - - @Override - public boolean supportsDdlTransactions() { - return true; - } - - @Override - public String getBooleanTrue() { - return "TRUE"; - } - - @Override - public String getBooleanFalse() { - return "FALSE"; - } - - @Override - public String doQuote(String identifier) { - return getOpenQuote() + StringUtils.replaceAll(identifier, getCloseQuote(), getEscapedQuote()) + getCloseQuote(); - } - - @Override - public String getEscapedQuote() { - return "\"\""; - } - - @Override - public boolean catalogIsSchema() { - return false; + "CREATE INDEX IF NOT EXISTS \"" + table.getName() + "_s_idx\" ON " + table + " (\"success\");"; } @Override public boolean useSingleConnection() { - KingbaseConfigurationExtension configurationExtension = configuration.getPluginRegister().getPlugin(KingbaseConfigurationExtension.class); - return !configurationExtension.isTransactionalLock(); - } - - /** - * This exists to fix this issue: https://github.com/flyway/flyway/issues/2638 - * See https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html - */ - @Override - public String getSelectStatement(Table table) { - return "/*NO LOAD BALANCE*/\n" - + "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 - + " WHERE " + quote("installed_rank") + " > ?" - + " ORDER BY " + quote("installed_rank"); + return true; } - @Override - public String getDatabaseHosting() { - if (getMainConnection().isAwsRds()) { - return DATABASE_HOSTING_AWS_RDS; - } else { - return super.getDatabaseHosting(); + private void createLockTable() { + try { + jdbcTemplate.execute(CREATE_LOCK_TABLE_DDL); + } catch (SQLException e) { + throw new FlywaySqlException("Unable to initialize the lock table", e); } } } diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabaseType.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabaseType.java index 5bed34a..37acb85 100644 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabaseType.java +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseDatabaseType.java @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * flyway-database-postgresql + * flyway-database-yugabytedb * ======================================================================== * Copyright (C) 2010 - 2024 Red Gate Software Ltd * ======================================================================== @@ -17,76 +17,58 @@ * limitations under the License. * =========================LICENSE_END================================== */ +/* + * 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. + */ package org.flywaydb.community.database.kingbase; -import lombok.CustomLog; +import org.flywaydb.community.database.KingbaseDatabaseExtension; import org.flywaydb.core.api.ResourceProvider; import org.flywaydb.core.api.configuration.Configuration; -import org.flywaydb.core.extensibility.Tier; -import org.flywaydb.core.internal.authentication.postgres.PgpassFileReader; -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.license.FlywayEditionUpgradeRequiredException; import org.flywaydb.core.internal.parser.Parser; import org.flywaydb.core.internal.parser.ParsingContext; +import org.flywaydb.database.postgresql.PostgreSQLDatabaseType; import java.sql.Connection; -import java.sql.Types; -import java.util.List; -import java.util.Properties; - -@CustomLog -public class KingbaseDatabaseType extends BaseDatabaseType { - - - +import java.util.regex.Pattern; +public class KingbaseDatabaseType extends PostgreSQLDatabaseType implements CommunityDatabaseType { @Override public String getName() { - return "KingbaseES"; - } - - @Override - public List getSupportedEngines() { - return List.of(getName(), "KingbaseES"); - } - - @Override - public int getNullType() { - return Types.NULL; + return "Kingbase"; } @Override public boolean handlesJDBCUrl(String url) { - if (url.startsWith("jdbc-secretsmanager:postgresql:")) { - - - - - throw new FlywayEditionUpgradeRequiredException(Tier.ENTERPRISE, (Tier) null, "jdbc-secretsmanager"); - - } - return url.startsWith("jdbc:postgresql:") || url.startsWith("jdbc:p6spy:postgresql:"); + return url.startsWith("jdbc:kingbase8:") || url.startsWith("jdbc:postgresql:") || url.startsWith("jdbc:p6spy:postgresql:"); } @Override - public String getDriverClass(String url, ClassLoader classLoader) { - - - - - - if (url.startsWith("jdbc:p6spy:postgresql:")) { - return "com.p6spy.engine.spy.P6SpyDriver"; - } - return "org.postgresql.Driver"; + public int getPriority() { + // Should be checked before plain PostgreSQL + return 1; } @Override public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection) { - return databaseProductName.startsWith("KingbaseES"); + // The YB is what distinguishes Yugabyte + return databaseProductName.startsWith("Kingbase"); } @Override @@ -100,53 +82,21 @@ public Parser createParser(Configuration configuration, ResourceProvider resourc } @Override - public void setDefaultConnectionProps(String url, Properties props, ClassLoader classLoader) { - props.put("applicationName", BaseDatabaseType.APPLICATION_NAME); + public String getPluginVersion(Configuration config) { + return KingbaseDatabaseExtension.readVersion(); } + /** + * Returns the YugabyteDB Smart driver classname if the smart driver is + * being used. The plugin will work with the Postgresql JDBC driver also + * since the url in that case would start with 'jdbc:postgresql' which would + * return the PG JDBC driver class name. + * @param url + * @param classLoader + * @return "com.yugabyte.Driver" if url starts with "jdbc:yugabytedb:" + */ @Override - public boolean detectUserRequiredByUrl(String url) { - return !url.contains("user="); - } - - @Override - public boolean detectPasswordRequiredByUrl(String url) { - - - - - - - // Postgres supports password in URL - return !url.contains("password="); - } - - @Override - public boolean externalAuthPropertiesRequired(String url, String username, String password) { - - return super.externalAuthPropertiesRequired(url, username, password); - - - - - } - - @Override - public Properties getExternalAuthProperties(String url, String username) { - PgpassFileReader pgpassFileReader = new PgpassFileReader(); - - if (pgpassFileReader.getPgpassFilePath() != null) { - LOG.info(org.flywaydb.core.internal.license.FlywayTeamsUpgradeMessage.generate( - "pgpass file '" + pgpassFileReader.getPgpassFilePath() + "'", - "use this for database authentication")); - } - return super.getExternalAuthProperties(url, username); - - - - - - - + public String getDriverClass(String url, ClassLoader classLoader) { + return url.startsWith("com.kingbase8.Driver") ? "com.kingbase8.Driver" : super.getDriverClass(url, classLoader); } } diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseExecutionTemplate.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseExecutionTemplate.java new file mode 100644 index 0000000..b1a34e1 --- /dev/null +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseExecutionTemplate.java @@ -0,0 +1,188 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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.kingbase; + +import lombok.CustomLog; +import org.flywaydb.core.api.FlywayException; +import org.flywaydb.core.internal.exception.FlywaySqlException; +import org.flywaydb.core.internal.jdbc.JdbcTemplate; +import org.flywaydb.core.internal.strategy.RetryStrategy; +import org.flywaydb.core.internal.util.FlywayDbWebsiteLinks; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; + +@CustomLog +public class KingbaseExecutionTemplate { + + private final JdbcTemplate jdbcTemplate; + private final String tableName; + private static final Map tableEntries = new ConcurrentHashMap<>(); + + KingbaseExecutionTemplate(JdbcTemplate jdbcTemplate, String tableName) { + this.jdbcTemplate = jdbcTemplate; + this.tableName = tableName; + } + + public T execute(Callable callable) { + Exception error = null; + try { + lock(); + return callable.call(); + } catch (RuntimeException e) { + error = e; + throw e; + } catch (Exception e) { + error = e; + throw new FlywayException(e); + } finally { + unlock(error); + } + } + + private void lock() throws SQLException { + RetryStrategy strategy = new RetryStrategy(); + strategy.doWithRetries(this::tryLock, "Interrupted while attempting to acquire lock through SELECT ... FOR UPDATE", + "Number of retries exceeded while attempting to acquire lock through SELECT ... FOR UPDATE. " + + "Configure the number of retries with the 'lockRetryCount' configuration option: " + FlywayDbWebsiteLinks.LOCK_RETRY_COUNT); + + } + + private boolean tryLock() { + Exception exception = null; + boolean txStarted = false, success = false; + Statement statement = null; + try { + statement = jdbcTemplate.getConnection().createStatement(); + + if (!tableEntries.containsKey(tableName)) { + try { + statement.executeUpdate("INSERT INTO " + + KingbaseDatabase.LOCK_TABLE_NAME + + " VALUES ('" + tableName + "', 'false')"); + tableEntries.put(tableName, true); + LOG.info(Thread.currentThread().getName() + "> Inserted a token row for " + tableName + " in " + KingbaseDatabase.LOCK_TABLE_NAME); + } catch (SQLException e) { + if ("23505".equals(e.getSQLState())) { + // 23505 == UNIQUE_VIOLATION + LOG.debug(Thread.currentThread().getName() + "> Token row already added for " + tableName); + } else { + throw new FlywaySqlException("Could not add token row for " + tableName + " in table " + KingbaseDatabase.LOCK_TABLE_NAME, e); + } + } + } + + boolean locked; + String selectForUpdate = "SELECT locked FROM " + + KingbaseDatabase.LOCK_TABLE_NAME + + " WHERE table_name = '" + + tableName + + "' FOR UPDATE"; + String updateLocked = "UPDATE " + KingbaseDatabase.LOCK_TABLE_NAME + + " SET locked = true WHERE table_name = '" + + tableName + "'"; + + statement.execute("BEGIN"); + txStarted = true; + ResultSet rs = statement.executeQuery(selectForUpdate); + if (rs.next()) { + locked = rs.getBoolean("locked"); + + if (locked) { + statement.execute("COMMIT"); + txStarted = false; + LOG.debug(Thread.currentThread().getName() + "> Another Flyway operation is in progress. Allowing it to complete"); + } else { + LOG.debug(Thread.currentThread().getName() + "> Setting locked = true"); + statement.executeUpdate(updateLocked); + success = true; + } + } else { + // For some reason the record was not found, retry + tableEntries.remove(tableName); + } + + } catch (SQLException e) { + LOG.warn(Thread.currentThread().getName() + "> Unable to perform lock action, SQLState: " + e.getSQLState()); + if (!"40001".equalsIgnoreCase(e.getSQLState())) { + exception = new FlywaySqlException("Unable to perform lock action", e); + throw (FlywaySqlException) exception; + } // else retry + } finally { + if (txStarted) { + try { + statement.execute("COMMIT"); + LOG.debug(Thread.currentThread().getName() + "> Completed the tx to set locked = true"); + } catch (SQLException e) { + if (exception == null) { + throw new FlywaySqlException("Failed to commit the tx to set locked = true", e); + } + LOG.warn(Thread.currentThread().getName() + "> Failed to commit the tx to set locked = true: " + e); + } + } + } + return success; + } + + private void unlock(Exception rethrow) { + Statement statement = null; + try { + statement = jdbcTemplate.getConnection().createStatement(); + statement.execute("BEGIN"); + ResultSet rs = statement.executeQuery("SELECT locked FROM " + KingbaseDatabase.LOCK_TABLE_NAME + " WHERE table_name = '" + tableName + "' FOR UPDATE"); + + if (rs.next()) { + boolean locked = rs.getBoolean("locked"); + if (locked) { + statement.executeUpdate("UPDATE " + KingbaseDatabase.LOCK_TABLE_NAME + " SET locked = false WHERE table_name = '" + tableName + "'"); + } else { + // Unexpected. This may happen only when callable took too long to complete + // and another thread forcefully reset it. + String msg = "Unlock failed but the Flyway operation may have succeeded. Check your Flyway operation before re-trying"; + LOG.warn(Thread.currentThread().getName() + "> " + msg); + if (rethrow == null) { + throw new FlywayException(msg); + } + } + } + } catch (SQLException e) { + if (rethrow == null) { + rethrow = new FlywayException("Unable to perform unlock action", e); + throw (FlywaySqlException) rethrow; + } + LOG.warn("Unable to perform unlock action " + e); + } finally { + try { + statement.execute("COMMIT"); + LOG.debug(Thread.currentThread().getName() + "> Completed the tx to set locked = false"); + } catch (SQLException e) { + if (rethrow == null) { + throw new FlywaySqlException("Failed to commit unlock action", e); + } + LOG.warn("Failed to commit unlock action: " + e); + } + } + } + +} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseParser.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseParser.java index 557145e..abecfe8 100644 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseParser.java +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseParser.java @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * flyway-database-postgresql + * flyway-database-yugabytedb * ======================================================================== * Copyright (C) 2010 - 2024 Red Gate Software Ltd * ======================================================================== @@ -17,139 +17,29 @@ * limitations under the License. * =========================LICENSE_END================================== */ +/* + * 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. + */ package org.flywaydb.community.database.kingbase; -import lombok.CustomLog; import org.flywaydb.core.api.configuration.Configuration; -import org.flywaydb.core.internal.parser.*; -import org.flywaydb.core.internal.sqlscript.Delimiter; -import org.flywaydb.core.internal.sqlscript.ParsedSqlStatement; - -import java.io.IOException; -import java.util.List; -import java.util.regex.Pattern; - -@CustomLog -public class KingbaseParser extends Parser { - private static final Pattern COPY_FROM_STDIN_REGEX = Pattern.compile("^COPY( .*)? FROM STDIN"); - private static final Pattern CREATE_DATABASE_TABLESPACE_SUBSCRIPTION_REGEX = Pattern.compile("^(CREATE|DROP) (DATABASE|TABLESPACE|SUBSCRIPTION)"); - private static final Pattern ALTER_SYSTEM_REGEX = Pattern.compile("^ALTER SYSTEM"); - private static final Pattern CREATE_INDEX_CONCURRENTLY_REGEX = Pattern.compile("^(CREATE|DROP)( UNIQUE)? INDEX CONCURRENTLY"); - private static final Pattern REINDEX_REGEX = Pattern.compile("^REINDEX( VERBOSE)? (SCHEMA|DATABASE|SYSTEM)"); - private static final Pattern VACUUM_REGEX = Pattern.compile("^VACUUM"); - private static final Pattern DISCARD_ALL_REGEX = Pattern.compile("^DISCARD ALL"); - private static final Pattern ALTER_TYPE_ADD_VALUE_REGEX = Pattern.compile("^ALTER TYPE( .*)? ADD VALUE"); - - private static final StatementType COPY = new StatementType(); - - public KingbaseParser(Configuration configuration, ParsingContext parsingContext) { - super(configuration, parsingContext, 3); - } - - @Override - protected char getAlternativeStringLiteralQuote() { - return '$'; - } - - @Override - protected ParsedSqlStatement createStatement(PeekingReader reader, Recorder recorder, - int statementPos, int statementLine, int statementCol, - int nonCommentPartPos, int nonCommentPartLine, int nonCommentPartCol, - StatementType statementType, boolean canExecuteInTransaction, - Delimiter delimiter, String sql - - - - , boolean batchable - ) throws IOException { - if (statementType == COPY) { - return new KingbaseCopyParsedStatement(nonCommentPartPos, nonCommentPartLine, nonCommentPartCol, - sql.substring(nonCommentPartPos - statementPos), - readCopyData(reader, recorder)); - } - return super.createStatement(reader, recorder, statementPos, statementLine, statementCol, - nonCommentPartPos, nonCommentPartLine, nonCommentPartCol, - statementType, canExecuteInTransaction, delimiter, sql - - - - , batchable - ); - } - - @Override - protected void adjustBlockDepth(ParserContext context, List tokens, Token keyword, PeekingReader reader) { - String keywordText = keyword.getText(); - - if (Parser.lastTokenIs(tokens, context.getParensDepth(), "BEGIN") && "ATOMIC".equalsIgnoreCase(keywordText)) { - context.increaseBlockDepth("ATOMIC"); - } - - if (context.getBlockDepth() > 0 && keywordText.equalsIgnoreCase("END") && "ATOMIC".equals(context.getBlockInitiator())) { - context.decreaseBlockDepth(); - } - } - - private String readCopyData(PeekingReader reader, Recorder recorder) throws IOException { - // Skip end of current line after ; - reader.readUntilIncluding('\n'); - - recorder.start(); - boolean done = false; - do { - String line = reader.readUntilIncluding('\n'); - if ("\\.".equals(line.trim())) { - done = true; - } else { - recorder.confirm(); - } - } while (!done); - - return recorder.stop(); - } - - @Override - protected StatementType detectStatementType(String simplifiedStatement, ParserContext context, PeekingReader reader) { - if (COPY_FROM_STDIN_REGEX.matcher(simplifiedStatement).matches()) { - return COPY; - } - - return super.detectStatementType(simplifiedStatement, context, reader); - } - - @Override - protected Boolean detectCanExecuteInTransaction(String simplifiedStatement, List keywords) { - if (CREATE_DATABASE_TABLESPACE_SUBSCRIPTION_REGEX.matcher(simplifiedStatement).matches() - || ALTER_SYSTEM_REGEX.matcher(simplifiedStatement).matches() - || CREATE_INDEX_CONCURRENTLY_REGEX.matcher(simplifiedStatement).matches() - || REINDEX_REGEX.matcher(simplifiedStatement).matches() - || VACUUM_REGEX.matcher(simplifiedStatement).matches() - || DISCARD_ALL_REGEX.matcher(simplifiedStatement).matches()) { - return false; - } - - boolean isDBVerUnder12 = true; - try { - isDBVerUnder12 = !parsingContext.getDatabase().getVersion().isAtLeast("12"); - } catch (Exception e) { - LOG.debug("Unable to determine database version: " + e.getMessage()); - } - - if (isDBVerUnder12 && ALTER_TYPE_ADD_VALUE_REGEX.matcher(simplifiedStatement).matches()) { - return false; - } - - return null; - } +import org.flywaydb.core.internal.parser.ParsingContext; +import org.flywaydb.database.postgresql.PostgreSQLParser; - @SuppressWarnings("Duplicates") - @Override - protected Token handleAlternativeStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException { - // dollarQuote is required because in Postgres, literals encased in $$ can be given a label, as in: - // $label$This is a string literal$label$ - String dollarQuote = (char) reader.read() + reader.readUntilIncluding('$'); - reader.swallowUntilExcluding(dollarQuote); - reader.swallow(dollarQuote.length()); - return new Token(TokenType.STRING, pos, line, col, null, null, context.getParensDepth()); +public class KingbaseParser extends PostgreSQLParser { + protected KingbaseParser(Configuration configuration, ParsingContext parsingContext) { + super(configuration, parsingContext); } } diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseSchema.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseSchema.java index cb0beac..8ea9930 100644 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseSchema.java +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseSchema.java @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * flyway-database-postgresql + * flyway-database-yugabytedb * ======================================================================== * Copyright (C) 2010 - 2024 Red Gate Software Ltd * ======================================================================== @@ -17,364 +17,39 @@ * limitations under the License. * =========================LICENSE_END================================== */ +/* + * 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. + */ package org.flywaydb.community.database.kingbase; -import org.flywaydb.core.internal.database.base.Schema; import org.flywaydb.core.internal.database.base.Table; -import org.flywaydb.core.internal.database.base.Type; import org.flywaydb.core.internal.jdbc.JdbcTemplate; +import org.flywaydb.database.postgresql.PostgreSQLSchema; -import java.sql.SQLException; -import java.util.*; - -/** - * PostgreSQL implementation of Schema. - */ -public class KingbaseSchema extends Schema { +public class KingbaseSchema extends PostgreSQLSchema { /** - * Creates a new PostgreSQL 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 KingbaseSchema(JdbcTemplate jdbcTemplate, KingbaseDatabase database, String name) { + public KingbaseSchema(JdbcTemplate jdbcTemplate, KingbaseDatabase database, String name) { super(jdbcTemplate, database, name); } - @Override - protected boolean doExists() throws SQLException { - return jdbcTemplate.queryForInt("SELECT COUNT(*) FROM pg_namespace WHERE nspname=?", name) > 0; - } - - @Override - protected boolean doEmpty() throws SQLException { - return !jdbcTemplate.queryForBoolean("SELECT EXISTS (\n" + - " SELECT c.oid FROM pg_catalog.pg_class c\n" + - " JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + - " LEFT JOIN pg_catalog.pg_depend d ON d.objid = c.oid AND d.deptype = 'e'\n" + - " WHERE n.nspname = ? AND d.objid IS NULL AND c.relkind IN ('r', 'v', 'S', 't')\n" + - " UNION ALL\n" + - " SELECT t.oid FROM pg_catalog.pg_type t\n" + - " JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n" + - " LEFT JOIN pg_catalog.pg_depend d ON d.objid = t.oid AND d.deptype = 'e'\n" + - " WHERE n.nspname = ? AND d.objid IS NULL AND t.typcategory NOT IN ('A', 'C')\n" + - " UNION ALL\n" + - " SELECT p.oid FROM pg_catalog.pg_proc p\n" + - " JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" + - " LEFT JOIN pg_catalog.pg_depend d ON d.objid = p.oid AND d.deptype = 'e'\n" + - " WHERE n.nspname = ? AND d.objid IS NULL\n" + - ")", name, name, name); - } - - @Override - protected void doCreate() throws SQLException { - jdbcTemplate.execute("CREATE SCHEMA " + database.quote(name)); - } - - @Override - protected void doDrop() throws SQLException { - jdbcTemplate.execute("DROP SCHEMA " + database.quote(name) + " CASCADE"); - } - - @Override - protected void doClean() throws SQLException { - if (database.getVersion().isAtLeast("9.3")) { - for (String statement : generateDropStatementsForMaterializedViews()) { - jdbcTemplate.execute(statement); - } - } - - for (String statement : generateDropStatementsForViews()) { - jdbcTemplate.execute(statement); - } - - for (Table table : allTables()) { - table.drop(); - } - - for (String statement : generateDropStatementsForBaseTypes(true)) { - jdbcTemplate.execute(statement); - } - - for (String statement : generateDropStatementsForRoutines()) { - jdbcTemplate.execute(statement); - } - - for (String statement : generateDropStatementsForEnums()) { - jdbcTemplate.execute(statement); - } - - for (String statement : generateDropStatementsForDomains()) { - jdbcTemplate.execute(statement); - } - - for (String statement : generateDropStatementsForSequences()) { - jdbcTemplate.execute(statement); - } - - for (String statement : generateDropStatementsForBaseTypes(false)) { - jdbcTemplate.execute(statement); - } - - for (String statement : generateDropStatementsForExtensions()) { - jdbcTemplate.execute(statement); - } - } - - /** - * Generates the statements for dropping the extensions in this schema. - * - * @return The drop statements. - * @throws SQLException when the clean statements could not be generated. - */ - private List generateDropStatementsForExtensions() throws SQLException { - List statements = new ArrayList<>(); - - if (extensionsTableExists()) { - List extensionNames = - jdbcTemplate.queryForStringList( - "SELECT e.extname " + - "FROM pg_extension e " + - "LEFT JOIN pg_namespace n ON n.oid = e.extnamespace " + - "LEFT JOIN pg_roles r ON r.oid = e.extowner " + - "WHERE n.nspname=? AND r.rolname=?", name, database.doGetCurrentUser()); - - for (String extensionName : extensionNames) { - statements.add("DROP EXTENSION IF EXISTS " + database.quote(extensionName) + " CASCADE"); - } - } - - return statements; - } - - private boolean extensionsTableExists() throws SQLException { - return jdbcTemplate.queryForBoolean( - "SELECT EXISTS ( \n" + - "SELECT 1 \n" + - "FROM pg_tables \n" + - "WHERE tablename = 'pg_extension');"); - } - - /** - * Generates the statements for dropping the sequences in this schema. - * - * @return The drop statements. - * @throws SQLException when the clean statements could not be generated. - */ - private List generateDropStatementsForSequences() throws SQLException { - List sequenceNames = - jdbcTemplate.queryForStringList( - "SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema=?", name); - - List statements = new ArrayList<>(); - for (String sequenceName : sequenceNames) { - statements.add("DROP SEQUENCE IF EXISTS " + database.quote(name, sequenceName)); - } - - return statements; - } - - /** - * Generates the statements for dropping the types in this schema. - * - * @param recreate Flag indicating whether the types should be recreated. Necessary for type-function chicken and egg problem. - * @return The drop statements. - * @throws SQLException when the clean statements could not be generated. - */ - private List generateDropStatementsForBaseTypes(boolean recreate) throws SQLException { - List> rows = - jdbcTemplate.queryForList( - "select typname, typcategory from pg_catalog.pg_type t " - + "left join pg_depend dep on dep.objid = t.oid and dep.deptype = 'e' " - + "where (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) " - + "and NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid) " - + "and t.typnamespace in (select oid from pg_catalog.pg_namespace where nspname = ?) " - + "and dep.objid is null " - + "and t.typtype != 'd'", - name); - - List statements = new ArrayList<>(); - for (Map row : rows) { - statements.add("DROP TYPE IF EXISTS " + database.quote(name, row.get("typname")) + " CASCADE"); - } - - if (recreate) { - for (Map row : rows) { - // Only recreate Pseudo-types (P) and User-defined types (U) - if (Arrays.asList("P", "U").contains(row.get("typcategory"))) { - statements.add("CREATE TYPE " + database.quote(name, row.get("typname"))); - } - } - } - - return statements; - } - - /** - * Generates the statements for dropping the routines in this schema. - * - * @return The drop statements. - * @throws SQLException when the clean statements could not be generated. - */ - private List generateDropStatementsForRoutines() throws SQLException { - // #2193: PostgreSQL 11 removed the 'proisagg' column and replaced it with 'prokind'. - String isAggregate = database.getVersion().isAtLeast("11") ? "pg_proc.prokind = 'a'" : "pg_proc.proisagg"; - // PROCEDURE is only available from PostgreSQL 11 - String isProcedure = database.getVersion().isAtLeast("11") ? "pg_proc.prokind = 'p'" : "FALSE"; - - List> rows = - jdbcTemplate.queryForList( - // Search for all functions - "SELECT proname, oidvectortypes(proargtypes) AS args, " + isAggregate + " as agg, " + isProcedure + " as proc " - + "FROM pg_proc INNER JOIN pg_namespace ns ON (pg_proc.pronamespace = ns.oid) " - // that don't depend on an extension - + "LEFT JOIN pg_depend dep ON dep.objid = pg_proc.oid AND dep.deptype = 'e' " - + "WHERE ns.nspname = ? AND dep.objid IS NULL", - name - ); - - List statements = new ArrayList<>(); - for (Map row : rows) { - String type = "FUNCTION"; - if (isTrue(row.get("agg"))) { - type = "AGGREGATE"; - } else if (isTrue(row.get("proc"))) { - type = "PROCEDURE"; - } - statements.add("DROP " + type + " IF EXISTS " - + database.quote(name, row.get("proname")) + "(" + row.get("args") + ") CASCADE"); - } - return statements; - } - - private boolean isTrue(String agg) { - return agg != null && agg.toLowerCase(Locale.ENGLISH).startsWith("t"); - } - - /** - * Generates the statements for dropping the enums in this schema. - * - * @return The drop statements. - * @throws SQLException when the clean statements could not be generated. - */ - private List generateDropStatementsForEnums() throws SQLException { - List enumNames = - jdbcTemplate.queryForStringList( - "SELECT t.typname FROM pg_catalog.pg_type t INNER JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = ? and t.typtype = 'e'", name); - - List statements = new ArrayList<>(); - for (String enumName : enumNames) { - statements.add("DROP TYPE " + database.quote(name, enumName)); - } - - return statements; - } - - /** - * Generates the statements for dropping the domains in this schema. - * - * @return The drop statements. - * @throws SQLException when the clean statements could not be generated. - */ - private List generateDropStatementsForDomains() throws SQLException { - List domainNames = - jdbcTemplate.queryForStringList( - "SELECT t.typname as domain_name\n" + - "FROM pg_catalog.pg_type t\n" + - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n" + - " LEFT JOIN pg_depend dep ON dep.objid = t.oid AND dep.deptype = 'e'\n" + - "WHERE t.typtype = 'd'\n" + - " AND n.nspname = ?\n" + - " AND dep.objid IS NULL" - , name); - - List statements = new ArrayList<>(); - for (String domainName : domainNames) { - statements.add("DROP DOMAIN IF EXISTS " + database.quote(name, domainName) + " CASCADE"); - } - - return statements; - } - - /** - * Generates the statements for dropping the materialized views in this schema. - * - * @return The drop statements. - * @throws SQLException when the clean statements could not be generated. - */ - private List generateDropStatementsForMaterializedViews() throws SQLException { - List viewNames = - jdbcTemplate.queryForStringList( - "SELECT relname FROM pg_catalog.pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace" - + " WHERE c.relkind = 'm' AND n.nspname = ?", name); - - List statements = new ArrayList<>(); - for (String domainName : viewNames) { - statements.add("DROP MATERIALIZED VIEW IF EXISTS " + database.quote(name, domainName) + " CASCADE"); - } - - return statements; - } - - /** - * Generates the statements for dropping the views in this schema. - * - * @return The drop statements. - * @throws SQLException when the clean statements could not be generated. - */ - private List generateDropStatementsForViews() throws SQLException { - List viewNames = - jdbcTemplate.queryForStringList( - // Search for all views - "SELECT relname FROM pg_catalog.pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace" + - // that don't depend on an extension - " LEFT JOIN pg_depend dep ON dep.objid = c.oid AND dep.deptype = 'e'" + - " WHERE c.relkind = 'v' AND n.nspname = ? AND dep.objid IS NULL", - name); - List statements = new ArrayList<>(); - for (String domainName : viewNames) { - statements.add("DROP VIEW IF EXISTS " + database.quote(name, domainName) + " CASCADE"); - } - - return statements; - } - - @Override - protected KingbaseTable[] doAllTables() throws SQLException { - List tableNames = - jdbcTemplate.queryForStringList( - //Search for all the table names - "SELECT t.table_name FROM information_schema.tables t" + - // that don't depend on an extension - " LEFT JOIN pg_depend dep ON dep.objid = (quote_ident(t.table_schema)||'.'||quote_ident(t.table_name))::regclass::oid AND dep.deptype = 'e'" + - // in this schema - " WHERE table_schema=?" + - //that are real tables (as opposed to views) - " AND table_type='BASE TABLE'" + - // with no extension depending on them - " AND dep.objid IS NULL" + - // and are not child tables (= do not inherit from another table). - " AND NOT (SELECT EXISTS (SELECT inhrelid FROM pg_catalog.pg_inherits" + - " WHERE inhrelid = (quote_ident(t.table_schema)||'.'||quote_ident(t.table_name))::regclass::oid))", - name - ); - //Views and child tables are excluded as they are dropped with the parent table when using cascade. - - KingbaseTable[] tables = new KingbaseTable[tableNames.size()]; - for (int i = 0; i < tableNames.size(); i++) { - tables[i] = new KingbaseTable(jdbcTemplate, database, this, tableNames.get(i)); - } - return tables; - } - @Override public Table getTable(String tableName) { - return new KingbaseTable(jdbcTemplate, database, this, tableName); - } - - @Override - protected Type getType(String typeName) { - return new KingbaseType(jdbcTemplate, database, this, typeName); + return new KingbaseTable(jdbcTemplate, (KingbaseDatabase) database, this, tableName); } } diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseTable.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseTable.java index fed7304..4606604 100644 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseTable.java +++ b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseTable.java @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * flyway-database-postgresql + * flyway-database-yugabytedb * ======================================================================== * Copyright (C) 2010 - 2024 Red Gate Software Ltd * ======================================================================== @@ -17,48 +17,34 @@ * limitations under the License. * =========================LICENSE_END================================== */ +/* + * 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. + */ package org.flywaydb.community.database.kingbase; -import org.flywaydb.core.internal.database.base.Table; import org.flywaydb.core.internal.jdbc.JdbcTemplate; +import org.flywaydb.database.postgresql.PostgreSQLTable; -import java.sql.SQLException; - -/** - * PostgreSQL-specific table. - */ -public class KingbaseTable extends Table { +public class KingbaseTable extends PostgreSQLTable { /** - * Creates a new PostgreSQL table. - * - * @param jdbcTemplate The Jdbc Template for communicating with the DB. + * @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 KingbaseTable(JdbcTemplate jdbcTemplate, KingbaseDatabase database, KingbaseSchema schema, String name) { + public KingbaseTable(JdbcTemplate jdbcTemplate, KingbaseDatabase database, KingbaseSchema schema, String name) { super(jdbcTemplate, database, schema, name); } - - @Override - protected void doDrop() throws SQLException { - jdbcTemplate.execute("DROP TABLE " + database.quote(schema.getName(), name) + " CASCADE"); - } - - @Override - protected boolean doExists() throws SQLException { - return jdbcTemplate.queryForBoolean("SELECT EXISTS (\n" + - " SELECT 1\n" + - " FROM pg_catalog.pg_class c\n" + - " JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + - " WHERE n.nspname = ?\n" + - " AND c.relname = ?\n" + - " AND c.relkind = 'r'\n" + // only tables - ")", schema.getName(), name); - } - - @Override - protected void doLock() throws SQLException { - jdbcTemplate.execute("SELECT * FROM " + this + " FOR UPDATE"); - } } diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseType.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseType.java deleted file mode 100644 index da2ea37..0000000 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/KingbaseType.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * flyway-database-postgresql - * ======================================================================== - * Copyright (C) 2010 - 2024 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.kingbase; - -import org.flywaydb.core.internal.database.base.Type; -import org.flywaydb.core.internal.jdbc.JdbcTemplate; - -import java.sql.SQLException; - -/** - * PostgreSQL-specific type. - */ -public class KingbaseType extends Type { - /** - * Creates a new PostgreSQL type. - * - * @param jdbcTemplate The Jdbc Template for communicating with the DB. - * @param database The database-specific support. - * @param schema The schema this type lives in. - * @param name The name of the type. - */ - public KingbaseType(JdbcTemplate jdbcTemplate, KingbaseDatabase database, KingbaseSchema schema, String name) { - super(jdbcTemplate, database, schema, name); - } - - @Override - protected void doDrop() throws SQLException { - jdbcTemplate.execute("DROP TYPE " + database.quote(schema.getName(), name)); - } -} diff --git a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/TransactionalModel.java b/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/TransactionalModel.java deleted file mode 100644 index f9e9b98..0000000 --- a/flyway-database-kingbase/src/main/java/org/flywaydb/community/database/kingbase/TransactionalModel.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * flyway-database-postgresql - * ======================================================================== - * Copyright (C) 2010 - 2024 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.kingbase; - -import lombok.Data; - -@Data -public class TransactionalModel { - private Boolean lock = null; -} diff --git a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/OceanBaseDatabaseExtension.java b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/OceanBaseDatabaseExtension.java index 83f87f8..c071da0 100644 --- a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/OceanBaseDatabaseExtension.java +++ b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/OceanBaseDatabaseExtension.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-oceanbase + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseConnection.java b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseConnection.java index 7d09cd1..31b61c9 100644 --- a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseConnection.java +++ b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseConnection.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-oceanbase + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseDatabase.java b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseDatabase.java index c5f70e1..7de752f 100644 --- a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseDatabase.java +++ b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseDatabase.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-oceanbase + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseDatabaseType.java b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseDatabaseType.java index 53a6642..1013a3b 100644 --- a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseDatabaseType.java +++ b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseDatabaseType.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-oceanbase + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseJdbcUtils.java b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseJdbcUtils.java index 85f0752..08beb75 100644 --- a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseJdbcUtils.java +++ b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/OceanBaseJdbcUtils.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-oceanbase + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/package-info.java b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/package-info.java index 6ae21ee..fd2417a 100644 --- a/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/package-info.java +++ b/flyway-database-oceanbase/src/main/java/org/flywaydb/community/database/oceanbase/package-info.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-oceanbase + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/TiDBDatabaseExtension.java b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/TiDBDatabaseExtension.java index 3e6b0b1..b34ad3a 100644 --- a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/TiDBDatabaseExtension.java +++ b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/TiDBDatabaseExtension.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-tidb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBConnection.java b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBConnection.java index 397da64..5d23b89 100644 --- a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBConnection.java +++ b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBConnection.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-tidb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -49,4 +68,4 @@ public T lock(Table table, Callable callable) { @Override protected boolean canUseNamedLockTemplate() {return false;} -} \ No newline at end of file +} diff --git a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBDatabase.java b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBDatabase.java index f210177..0ca2bd4 100644 --- a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBDatabase.java +++ b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBDatabase.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-tidb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -42,4 +61,4 @@ public void ensureSupported(Configuration configuration) { ensureDatabaseIsRecentEnough("5.0"); recommendFlywayUpgradeIfNecessary("5.0"); } -} \ No newline at end of file +} diff --git a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBDatabaseType.java b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBDatabaseType.java index 8344e56..7404d68 100644 --- a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBDatabaseType.java +++ b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/TiDBDatabaseType.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-tidb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -53,4 +72,4 @@ public Database createDatabase(Configuration configuration, JdbcConnectionFactor public String getPluginVersion(Configuration config) { return TiDBDatabaseExtension.readVersion(); } -} \ No newline at end of file +} diff --git a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/package-info.java b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/package-info.java index a506485..b7c5736 100644 --- a/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/package-info.java +++ b/flyway-database-tidb/src/main/java/org/flywaydb/community/database/mysql/tidb/package-info.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-tidb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -16,4 +35,4 @@ /** * Community-supported package. No compatibility guarantees provided. */ -package org.flywaydb.community.database.mysql.tidb; \ No newline at end of file +package org.flywaydb.community.database.mysql.tidb; diff --git a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/YugabyteDBDatabaseExtension.java b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/YugabyteDBDatabaseExtension.java index 54920b1..1e3be1f 100644 --- a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/YugabyteDBDatabaseExtension.java +++ b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/YugabyteDBDatabaseExtension.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBConnection.java b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBConnection.java index a5d517b..835806f 100644 --- a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBConnection.java +++ b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBConnection.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -36,4 +55,4 @@ public Schema getSchema(String name) { public T lock(Table table, Callable callable) { return new YugabyteDBExecutionTemplate(jdbcTemplate, table.toString()).execute(callable); } -} \ No newline at end of file +} diff --git a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBDatabase.java b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBDatabase.java index 50d9ca3..ad2bfa7 100644 --- a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBDatabase.java +++ b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBDatabase.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * diff --git a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBDatabaseType.java b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBDatabaseType.java index a45726e..c2146a0 100644 --- a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBDatabaseType.java +++ b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBDatabaseType.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -81,4 +100,4 @@ public String getPluginVersion(Configuration config) { public String getDriverClass(String url, ClassLoader classLoader) { return url.startsWith("jdbc:yugabytedb:") ? "com.yugabyte.Driver" : super.getDriverClass(url, classLoader); } -} \ No newline at end of file +} diff --git a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBExecutionTemplate.java b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBExecutionTemplate.java index 920b487..eb15368 100644 --- a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBExecutionTemplate.java +++ b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBExecutionTemplate.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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.postgresql.yugabytedb; import lombok.CustomLog; diff --git a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBParser.java b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBParser.java index 289e698..c0e4b77 100644 --- a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBParser.java +++ b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBParser.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -23,4 +42,4 @@ public class YugabyteDBParser extends PostgreSQLParser { protected YugabyteDBParser(Configuration configuration, ParsingContext parsingContext) { super(configuration, parsingContext); } -} \ No newline at end of file +} diff --git a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBSchema.java b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBSchema.java index 2b9b5f6..17a3214 100644 --- a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBSchema.java +++ b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBSchema.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -33,4 +52,4 @@ public YugabyteDBSchema(JdbcTemplate jdbcTemplate, YugabyteDBDatabase database, public Table getTable(String tableName) { return new YugabyteDBTable(jdbcTemplate, (YugabyteDBDatabase) database, this, tableName); } -} \ No newline at end of file +} diff --git a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBTable.java b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBTable.java index 7d8061a..2dab405 100644 --- a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBTable.java +++ b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/YugabyteDBTable.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -28,4 +47,4 @@ public class YugabyteDBTable extends PostgreSQLTable { public YugabyteDBTable(JdbcTemplate jdbcTemplate, YugabyteDBDatabase database, YugabyteDBSchema schema, String name) { super(jdbcTemplate, database, schema, name); } -} \ No newline at end of file +} diff --git a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/package-info.java b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/package-info.java index a368798..e0bbd5e 100644 --- a/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/package-info.java +++ b/flyway-database-yugabytedb/src/main/java/org/flywaydb/community/database/postgresql/yugabytedb/package-info.java @@ -1,3 +1,22 @@ +/*- + * ========================LICENSE_START================================= + * flyway-database-yugabytedb + * ======================================================================== + * Copyright (C) 2010 - 2024 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================================== + */ /* * Copyright (C) Red Gate Software Ltd 2010-2024 * @@ -16,4 +35,4 @@ /** * Community-supported package. No compatibility guarantees provided. */ -package org.flywaydb.community.database.postgresql.yugabytedb; \ No newline at end of file +package org.flywaydb.community.database.postgresql.yugabytedb;