Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Postgres upgrade (non breaking change) (#2184)

Michael Rademakera19ad5deb97e
diff --git a/container/src/main/java/org/openremote/container/persistence/PersistenceService.java b/container/src/main/java/org/openremote/container/persistence/PersistenceService.java
index ee1b273fe..ff04df17f 100644
--- a/container/src/main/java/org/openremote/container/persistence/PersistenceService.java
+++ b/container/src/main/java/org/openremote/container/persistence/PersistenceService.java
@@ -328,7 +328,7 @@ public class PersistenceService implements ContainerService, Consumer<Persistenc
}
openDatabase(container, database, dbUsername, dbPassword, connectionUrl);
- prepareSchema(container, connectionUrl, dbUsername, dbPassword, dbSchema);
+ prepareSchema(container, connectionUrl, dbUsername, dbPassword, dbSchema, dbName);
}
protected EntityManagerFactory getEntityManagerFactory(Properties properties, List<String> classNames) {
@@ -510,7 +510,7 @@ public class PersistenceService implements ContainerService, Consumer<Persistenc
database.open(persistenceUnitProperties, connectionUrl, username, password, connectionTimeoutSeconds, databaseMinPoolSize, databaseMaxPoolSize);
}
- protected void prepareSchema(Container container, String connectionUrl, String databaseUsername, String databasePassword, String schemaName) {
+ protected void prepareSchema(Container container, String connectionUrl, String databaseUsername, String databasePassword, String schemaName, String databaseName) {
boolean outOfOrder = getBoolean(container.getConfig(), OR_DB_FLYWAY_OUT_OF_ORDER, false);
@@ -525,10 +525,12 @@ public class PersistenceService implements ContainerService, Consumer<Persistenc
// Excluding the extension(s) in the cleanup process will not be added soon https://github.com/flyway/flyway/issues/2271
// Now applied it here (so it is excluded for the migration process), to prevent that flyway drops the extension during cleanup.
StringBuilder initSql = new StringBuilder();
+
+ // CRITICAL: Set at DATABASE level (higher priority than role level)
+ initSql.append("ALTER DATABASE ").append(databaseName).append(" SET search_path TO ").append(schemaName).append(", public, topology;");
+
initSql.append("CREATE EXTENSION IF NOT EXISTS timescaledb SCHEMA public cascade;");
-// initSql.append("ALTER EXTENSION timescaledb UPDATE;");
initSql.append("CREATE EXTENSION IF NOT EXISTS timescaledb_toolkit SCHEMA public cascade;");
-// initSql.append("ALTER EXTENSION timescaledb_toolkit UPDATE;");
flyway = Flyway.configure()
.cleanDisabled(false)
@@ -539,13 +541,14 @@ public class PersistenceService implements ContainerService, Consumer<Persistenc
.initSql(initSql.toString())
.baselineOnMigrate(true)
.outOfOrder(outOfOrder)
+ .placeholders(Map.of("schemaName", schemaName))
.load();
MigrationInfo currentMigration;
try {
currentMigration = flyway.info().current();
} catch (FlywaySqlScriptException fssex) {
- if(fssex.getStatement().contains("CREATE EXTENSION IF NOT EXISTS timescaledb")) { // ... SCHEMA public cascade;
+ if (fssex.getStatement().contains("CREATE EXTENSION IF NOT EXISTS timescaledb")) { // ... SCHEMA public cascade;
LOG.severe("Timescale DB extension not found; please ensure you are using a postgres image with timescale DB extension included.");
}
throw fssex;
diff --git a/gradle.properties b/gradle.properties
index 424d5540a..c9b159403 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -25,7 +25,7 @@ sqliteVersion = 3.50.3.0
hibernateVersion = 6.6.11.Final
hibernateValidatorVersion = 8.0.2.Final
hikaricpVersion = 6.2.1
-postgresJdbcVersion = 42.7.7
+postgresJdbcVersion = 42.7.8
spockVersion = 2.4-M5-groovy-4.0
byteBuddyVersion = 1.16.1
objenesisVersion = 3.4
@@ -38,7 +38,7 @@ jSerialCommVersion = 2.11.0
saxonHEVersion = 12.5
exp4jVersion = 0.4.13
nettyVersion = 4.2.6.Final
-flywaydbVersion = 11.2.0
+flywaydbVersion = 11.13.1
ical4jVersion = 4.2.0
friendlyIdVersion = 1.0.1
geotoolsVersion = 33.2
diff --git a/manager/src/main/resources/org/openremote/manager/setup/database/V20240722_01__Indexes.sql b/manager/src/main/resources/org/openremote/manager/setup/database/V20240722_01__Indexes.sql
index f7efab08f..eea761618 100644
--- a/manager/src/main/resources/org/openremote/manager/setup/database/V20240722_01__Indexes.sql
+++ b/manager/src/main/resources/org/openremote/manager/setup/database/V20240722_01__Indexes.sql
@@ -19,5 +19,5 @@
*/
/* Add an index for entity ID, attribute name and timestamp to improve data point retrieval */
-CREATE index if not exists asset_datapoint_entity_id_attribute_name_timestamp_idx on openremote.asset_datapoint (entity_id, attribute_name, timestamp DESC);
-CREATE index if not exists asset_predicted_datapoint_entity_id_attribute_name_timestamp_idx on openremote.asset_predicted_datapoint (entity_id, attribute_name, timestamp DESC);
+CREATE index if not exists asset_datapoint_entity_id_attribute_name_timestamp_idx on ${schemaName}.asset_datapoint (entity_id, attribute_name, timestamp DESC);
+CREATE index if not exists asset_predicted_datapoint_entity_id_attribute_name_timestamp_idx on ${schemaName}.asset_predicted_datapoint (entity_id, attribute_name, timestamp DESC);
diff --git a/profile/dev-proxy.yml b/profile/dev-proxy.yml
index 12a8a29c3..4139b3643 100644
--- a/profile/dev-proxy.yml
+++ b/profile/dev-proxy.yml
@@ -51,6 +51,7 @@ services:
service: postgresql
volumes:
- ../tmp:/storage
+ - postgresql-data:/var/lib/postgresql/data
# Access directly if needed on localhost
ports:
- "5432:5432"