Skip to content

Support for InterSystems IRIS #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions flyway-database-iris/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-community-db-support</artifactId>
<version>10.17.0</version>
</parent>

<artifactId>flyway-database-iris</artifactId>

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

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-iris
* ========================================================================
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
/*
* 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;
import java.util.Objects;

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

public static String readVersion() {
try {
return FileUtils.copyToString(
Objects.requireNonNull(IRISDatabaseExtension.class.getClassLoader().getResourceAsStream("org/flywaydb/community/database/iris/version.txt")),
StandardCharsets.UTF_8);
} catch (IOException e) {
throw new FlywayException("Unable to read extension version: " + e.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-iris
* ========================================================================
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package org.flywaydb.community.database.iris;

import lombok.CustomLog;

import org.flywaydb.core.api.callback.Callback;
import org.flywaydb.core.api.callback.Context;
import org.flywaydb.core.api.callback.Event;
import org.flywaydb.core.internal.jdbc.JdbcTemplate;
import org.flywaydb.core.internal.jdbc.JdbcUtils;

import java.sql.PreparedStatement;
import java.util.stream.IntStream;

@CustomLog
public class IRISCallback implements Callback {

@Override
public boolean supports(Event event, Context context) {
return true;
}

@Override
public boolean canHandleInTransaction(Event event, Context context) {
return false;
}

@Override
public void handle(Event event, Context context) {
if (event.equals(Event.AFTER_MIGRATE)) {
IntStream.range(0, IRISTable.totalLocks.get()).forEach(i -> {
unlock(IRISTable.lockedJdbcTemplate);
});
IRISTable.totalLocks.set(0);
}
IRISTable.lockedJdbcTemplate = null;
IRISTable.lockedTable = null;
}

@Override
public String getCallbackName() {
return this.getClass().getSimpleName();
}

private void unlock(JdbcTemplate jdbcTemplate) {
PreparedStatement preparedStatement = null;
try {
preparedStatement = jdbcTemplate.getConnection().prepareStatement("UNLOCK " + IRISTable.lockedTable + " IN EXCLUSIVE MODE");
preparedStatement.execute();
} catch (Exception e) {
throw new IllegalStateException(e);
} finally {
JdbcUtils.closeStatement(preparedStatement);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-iris
* ========================================================================
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package org.flywaydb.community.database.iris;

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

import java.sql.SQLException;

public class IRISConnection extends Connection<IRISDatabase> {
protected IRISConnection(IRISDatabase database, java.sql.Connection connection) {
super(database, connection);
}

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

@Override
protected String getCurrentSchemaNameOrSearchPath() throws SQLException {
return "SQLUser";
}

@Override
public IRISSchema getSchema(String name) {
return new IRISSchema(jdbcTemplate, database, name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*-
* ========================LICENSE_START=================================
* flyway-database-iris
* ========================================================================
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
* ========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package org.flywaydb.community.database.iris;

import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.database.base.Database;
import org.flywaydb.core.internal.database.base.Table;
import org.flywaydb.core.internal.exception.FlywayDbUpgradeRequiredException;
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
import org.flywaydb.core.internal.jdbc.StatementInterceptor;

import java.math.BigInteger;
import java.sql.Connection;

public class IRISDatabase extends Database<IRISConnection> {
public IRISDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {
super(configuration, jdbcConnectionFactory, statementInterceptor);
}

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

@Override
public void ensureSupported(Configuration configuration) {
MigrationVersion version = getVersion();
if (Integer.parseInt(version.getMajorAsString()) < 2019) {
throw new FlywayDbUpgradeRequiredException(new IRISDatabaseType(), version.toString(), "2019.1");
}
}

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

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

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

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

@Override
public String getRawCreateScript(Table table, boolean baseline) {
String schemaName = table.getSchema().getName();
String tableName = table.getName();

return "CREATE TABLE \"" + schemaName + "\".\"" + tableName + "\" (\n" +
" \"installed_rank\" INTEGER 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 getdate(),\n" +
" \"execution_time\" INTEGER NOT NULL,\n" +
" \"success\" BIT NOT NULL\n" +
");\n" +
"ALTER TABLE \"" + schemaName + "\".\"" + tableName + "\" ADD CONSTRAINT \"" + tableName + "_pk\" PRIMARY KEY (\"installed_rank\");";
}
}
Loading