diff --git a/application/src/main/java/org/thingsboard/server/service/install/SqlAbstractDatabaseSchemaService.java b/application/src/main/java/org/thingsboard/server/service/install/SqlAbstractDatabaseSchemaService.java
index 9e137c3f09..ac6889cc1e 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/SqlAbstractDatabaseSchemaService.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/SqlAbstractDatabaseSchemaService.java
@@ -44,9 +44,11 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema
private InstallScripts installScripts;
private final String schemaSql;
+ private final String schemaIdxSql;
- protected SqlAbstractDatabaseSchemaService(String schemaSql) {
+ protected SqlAbstractDatabaseSchemaService(String schemaSql, String schemaIdxSql) {
this.schemaSql = schemaSql;
+ this.schemaIdxSql = schemaIdxSql;
}
@Override
@@ -60,6 +62,15 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema
}
+ if (schemaIdxSql != null) {
+ log.info("Installing SQL DataBase schema indexes part: " + schemaIdxSql);
+
+ Path schemaIdxFile = Paths.get(installScripts.getDataDir(), SQL_DIR, schemaIdxSql);
+ try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
+ String sql = new String(Files.readAllBytes(schemaIdxFile), Charset.forName("UTF-8"));
+ conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema
+ }
+ }
}
}
diff --git a/application/src/main/java/org/thingsboard/server/service/install/SqlEntityDatabaseSchemaService.java b/application/src/main/java/org/thingsboard/server/service/install/SqlEntityDatabaseSchemaService.java
index 9181cff902..83a780a62c 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/SqlEntityDatabaseSchemaService.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/SqlEntityDatabaseSchemaService.java
@@ -25,6 +25,6 @@ import org.thingsboard.server.dao.util.SqlDao;
public class SqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService
implements EntityDatabaseSchemaService {
public SqlEntityDatabaseSchemaService() {
- super("schema-entities.sql");
+ super("schema-entities.sql", "schema-entities-idx.sql");
}
}
diff --git a/application/src/main/java/org/thingsboard/server/service/install/SqlTsDatabaseSchemaService.java b/application/src/main/java/org/thingsboard/server/service/install/SqlTsDatabaseSchemaService.java
index 1f11ad78e5..42ba9812de 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/SqlTsDatabaseSchemaService.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/SqlTsDatabaseSchemaService.java
@@ -25,6 +25,6 @@ import org.thingsboard.server.dao.util.SqlTsDao;
public class SqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaService
implements TsDatabaseSchemaService {
public SqlTsDatabaseSchemaService() {
- super("schema-ts.sql");
+ super("schema-ts.sql", null);
}
}
\ No newline at end of file
diff --git a/dao/src/main/resources/sql/schema-entities-idx.sql b/dao/src/main/resources/sql/schema-entities-idx.sql
new file mode 100644
index 0000000000..59785ae758
--- /dev/null
+++ b/dao/src/main/resources/sql/schema-entities-idx.sql
@@ -0,0 +1,23 @@
+--
+-- Copyright © 2016-2019 The Thingsboard Authors
+--
+-- 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.
+--
+
+CREATE INDEX IF NOT EXISTS idx_alarm_originator_alarm_type ON alarm(tenant_id, type, originator_type, originator_id);
+
+CREATE INDEX IF NOT EXISTS idx_event_type_entity_id ON event(tenant_id, event_type, entity_type, entity_id);
+
+CREATE INDEX IF NOT EXISTS idx_relation_to_id ON relation(relation_type_group, to_type, to_id);
+
+CREATE INDEX IF NOT EXISTS idx_relation_from_id ON relation(relation_type_group, from_type, from_id);
diff --git a/dao/src/main/resources/sql/schema-entities.sql b/dao/src/main/resources/sql/schema-entities.sql
index bfe8b161eb..2903ca2fb1 100644
--- a/dao/src/main/resources/sql/schema-entities.sql
+++ b/dao/src/main/resources/sql/schema-entities.sql
@@ -37,8 +37,6 @@ CREATE TABLE IF NOT EXISTS alarm (
type varchar(255)
);
-CREATE INDEX IF NOT EXISTS idx_alarm_originator_alarm_type ON alarm(tenant_id, type, originator_type, originator_id);
-
CREATE TABLE IF NOT EXISTS asset (
id varchar(31) NOT NULL CONSTRAINT asset_pkey PRIMARY KEY,
additional_info varchar,
@@ -143,8 +141,6 @@ CREATE TABLE IF NOT EXISTS event (
CONSTRAINT event_unq_key UNIQUE (tenant_id, entity_type, entity_id, event_type, event_uid)
);
-CREATE INDEX IF NOT EXISTS idx_event_type_entity_id ON event(tenant_id, event_type, entity_type, entity_id);
-
CREATE TABLE IF NOT EXISTS relation (
from_id varchar(31),
from_type varchar(255),
@@ -156,10 +152,6 @@ CREATE TABLE IF NOT EXISTS relation (
CONSTRAINT relation_pkey PRIMARY KEY (from_id, from_type, relation_type_group, relation_type, to_id, to_type)
);
-CREATE INDEX IF NOT EXISTS idx_relation_to_id ON relation(relation_type_group, to_type, to_id);
-
-CREATE INDEX IF NOT EXISTS idx_relation_from_id ON relation(relation_type_group, from_type, from_id);
-
CREATE TABLE IF NOT EXISTS tb_user (
id varchar(31) NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY,
additional_info varchar,
@@ -215,8 +207,7 @@ CREATE TABLE IF NOT EXISTS widgets_bundle (
);
CREATE TABLE IF NOT EXISTS rule_chain (
- id varchar(31) NOT NULL CONSTRAINT rule_chCREATE INDEX IF NOT EXISTS idx_event_type_entity_id ON event(tenant_id, event_type, entity_type, entity_id);
-ain_pkey PRIMARY KEY,
+ id varchar(31) NOT NULL CONSTRAINT rule_chain_pkey PRIMARY KEY,
additional_info varchar,
configuration varchar(10000000),
name varchar(255),
diff --git a/dao/src/test/java/org/thingsboard/server/dao/SqlDaoServiceTestSuite.java b/dao/src/test/java/org/thingsboard/server/dao/SqlDaoServiceTestSuite.java
index 26fbc71b36..6dee664716 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/SqlDaoServiceTestSuite.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/SqlDaoServiceTestSuite.java
@@ -30,7 +30,7 @@ public class SqlDaoServiceTestSuite {
@ClassRule
public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
- Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql", "sql/system-test.sql"),
+ Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/schema-entities-idx.sql", "sql/system-data.sql", "sql/system-test.sql"),
"sql/drop-all-tables.sql",
"sql-test.properties"
);
diff --git a/pom.xml b/pom.xml
index 66e5561fe3..d62b1673fb 100755
--- a/pom.xml
+++ b/pom.xml
@@ -75,7 +75,7 @@
1.15.0
1.56
2.0.1
- 2.4.0
+ 2.5.0
2.5.3
1.2.1
9.4.1211