Skip to content

Commit e74d47a

Browse files
committed
Added support for InterSystems IRIS
1 parent 4807c2c commit e74d47a

File tree

11 files changed

+608
-0
lines changed

11 files changed

+608
-0
lines changed

flyway-database-iris/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.flywaydb</groupId>
9+
<artifactId>flyway-community-db-support</artifactId>
10+
<version>10.17.0</version>
11+
</parent>
12+
13+
<artifactId>flyway-database-iris</artifactId>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.release>17</maven.compiler.release>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>${project.groupId}</groupId>
23+
<artifactId>flyway-core</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.projectlombok</groupId>
27+
<artifactId>lombok</artifactId>
28+
</dependency>
29+
</dependencies>
30+
31+
<build>
32+
<resources>
33+
<resource>
34+
<directory>src/main/resources</directory>
35+
<filtering>true</filtering>
36+
</resource>
37+
</resources>
38+
<plugins>
39+
<plugin>
40+
<artifactId>maven-resources-plugin</artifactId>
41+
</plugin>
42+
<plugin>
43+
<artifactId>maven-jar-plugin</artifactId>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
</project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-iris
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
/*
21+
* Copyright (C) Red Gate Software Ltd 2010-2024
22+
*
23+
* Licensed under the Apache License, Version 2.0 (the "License");
24+
* you may not use this file except in compliance with the License.
25+
* You may obtain a copy of the License at
26+
*
27+
* http://www.apache.org/licenses/LICENSE-2.0
28+
*
29+
* Unless required by applicable law or agreed to in writing, software
30+
* distributed under the License is distributed on an "AS IS" BASIS,
31+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32+
* See the License for the specific language governing permissions and
33+
* limitations under the License.
34+
*/
35+
package org.flywaydb.community.database;
36+
37+
import org.flywaydb.core.api.FlywayException;
38+
import org.flywaydb.core.extensibility.PluginMetadata;
39+
import org.flywaydb.core.internal.util.FileUtils;
40+
41+
import java.io.IOException;
42+
import java.nio.charset.StandardCharsets;
43+
import java.util.Objects;
44+
45+
public class IRISDatabaseExtension implements PluginMetadata {
46+
public String getDescription() {
47+
return "Community-contributed InterSystems IRIS database support extension " + readVersion() + " by Redgate";
48+
}
49+
50+
public static String readVersion() {
51+
try {
52+
return FileUtils.copyToString(
53+
Objects.requireNonNull(IRISDatabaseExtension.class.getClassLoader().getResourceAsStream("org/flywaydb/community/database/iris/version.txt")),
54+
StandardCharsets.UTF_8);
55+
} catch (IOException e) {
56+
throw new FlywayException("Unable to read extension version: " + e.getMessage(), e);
57+
}
58+
}
59+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-iris
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
package org.flywaydb.community.database.iris;
21+
22+
import lombok.CustomLog;
23+
24+
import org.flywaydb.core.api.callback.Callback;
25+
import org.flywaydb.core.api.callback.Context;
26+
import org.flywaydb.core.api.callback.Event;
27+
import org.flywaydb.core.internal.jdbc.JdbcTemplate;
28+
import org.flywaydb.core.internal.jdbc.JdbcUtils;
29+
30+
import java.sql.PreparedStatement;
31+
import java.util.stream.IntStream;
32+
33+
@CustomLog
34+
public class IRISCallback implements Callback {
35+
36+
@Override
37+
public boolean supports(Event event, Context context) {
38+
return true;
39+
}
40+
41+
@Override
42+
public boolean canHandleInTransaction(Event event, Context context) {
43+
return false;
44+
}
45+
46+
@Override
47+
public void handle(Event event, Context context) {
48+
if (event.equals(Event.AFTER_MIGRATE)) {
49+
IntStream.range(0, IRISTable.totalLocks.get()).forEach(i -> {
50+
unlock(IRISTable.lockedJdbcTemplate);
51+
});
52+
IRISTable.totalLocks.set(0);
53+
}
54+
IRISTable.lockedJdbcTemplate = null;
55+
IRISTable.lockedTable = null;
56+
}
57+
58+
@Override
59+
public String getCallbackName() {
60+
return this.getClass().getSimpleName();
61+
}
62+
63+
private void unlock(JdbcTemplate jdbcTemplate) {
64+
PreparedStatement preparedStatement = null;
65+
try {
66+
preparedStatement = jdbcTemplate.getConnection().prepareStatement("UNLOCK " + IRISTable.lockedTable + " IN EXCLUSIVE MODE");
67+
preparedStatement.execute();
68+
} catch (Exception e) {
69+
throw new IllegalStateException(e);
70+
} finally {
71+
JdbcUtils.closeStatement(preparedStatement);
72+
}
73+
}
74+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-iris
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
package org.flywaydb.community.database.iris;
21+
22+
import org.flywaydb.core.internal.database.base.Connection;
23+
24+
import java.sql.SQLException;
25+
26+
public class IRISConnection extends Connection<IRISDatabase> {
27+
protected IRISConnection(IRISDatabase database, java.sql.Connection connection) {
28+
super(database, connection);
29+
}
30+
31+
@Override
32+
public void doChangeCurrentSchemaOrSearchPathTo(String schema) throws SQLException {
33+
getJdbcConnection().setSchema(schema);
34+
}
35+
36+
@Override
37+
protected String getCurrentSchemaNameOrSearchPath() throws SQLException {
38+
return "SQLUser";
39+
}
40+
41+
@Override
42+
public IRISSchema getSchema(String name) {
43+
return new IRISSchema(jdbcTemplate, database, name);
44+
}
45+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-iris
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
package org.flywaydb.community.database.iris;
21+
22+
import org.flywaydb.core.api.MigrationVersion;
23+
import org.flywaydb.core.api.configuration.Configuration;
24+
import org.flywaydb.core.internal.database.base.Database;
25+
import org.flywaydb.core.internal.database.base.Table;
26+
import org.flywaydb.core.internal.exception.FlywayDbUpgradeRequiredException;
27+
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
28+
import org.flywaydb.core.internal.jdbc.StatementInterceptor;
29+
30+
import java.math.BigInteger;
31+
import java.sql.Connection;
32+
33+
public class IRISDatabase extends Database<IRISConnection> {
34+
public IRISDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {
35+
super(configuration, jdbcConnectionFactory, statementInterceptor);
36+
}
37+
38+
@Override
39+
protected IRISConnection doGetConnection(Connection connection) {
40+
return new IRISConnection(this, connection);
41+
}
42+
43+
@Override
44+
public void ensureSupported(Configuration configuration) {
45+
MigrationVersion version = getVersion();
46+
if (Integer.parseInt(version.getMajorAsString()) < 2019) {
47+
throw new FlywayDbUpgradeRequiredException(new IRISDatabaseType(), version.toString(), "2019.1");
48+
}
49+
}
50+
51+
@Override
52+
public boolean supportsDdlTransactions() {
53+
return true;
54+
}
55+
56+
@Override
57+
public String getBooleanTrue() {
58+
return "1";
59+
}
60+
61+
@Override
62+
public String getBooleanFalse() {
63+
return "0";
64+
}
65+
66+
@Override
67+
public boolean catalogIsSchema() {
68+
return false;
69+
}
70+
71+
@Override
72+
public String getRawCreateScript(Table table, boolean baseline) {
73+
String schemaName = table.getSchema().getName();
74+
String tableName = table.getName();
75+
76+
return "CREATE TABLE \"" + schemaName + "\".\"" + tableName + "\" (\n" +
77+
" \"installed_rank\" INTEGER NOT NULL,\n" +
78+
" \"version\" VARCHAR(50),\n" +
79+
" \"description\" VARCHAR(200) NOT NULL,\n" +
80+
" \"type\" VARCHAR(20) NOT NULL,\n" +
81+
" \"script\" VARCHAR(1000) NOT NULL,\n" +
82+
" \"checksum\" INTEGER,\n" +
83+
" \"installed_by\" VARCHAR(100) NOT NULL,\n" +
84+
" \"installed_on\" TIMESTAMP NOT NULL DEFAULT getdate(),\n" +
85+
" \"execution_time\" INTEGER NOT NULL,\n" +
86+
" \"success\" BIT NOT NULL\n" +
87+
");\n" +
88+
"ALTER TABLE \"" + schemaName + "\".\"" + tableName + "\" ADD CONSTRAINT \"" + tableName + "_pk\" PRIMARY KEY (\"installed_rank\");";
89+
}
90+
}

0 commit comments

Comments
 (0)