Showing
7 changed files
with
40 additions
and
15 deletions
@@ -44,9 +44,11 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema | @@ -44,9 +44,11 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema | ||
44 | private InstallScripts installScripts; | 44 | private InstallScripts installScripts; |
45 | 45 | ||
46 | private final String schemaSql; | 46 | private final String schemaSql; |
47 | + private final String schemaIdxSql; | ||
47 | 48 | ||
48 | - protected SqlAbstractDatabaseSchemaService(String schemaSql) { | 49 | + protected SqlAbstractDatabaseSchemaService(String schemaSql, String schemaIdxSql) { |
49 | this.schemaSql = schemaSql; | 50 | this.schemaSql = schemaSql; |
51 | + this.schemaIdxSql = schemaIdxSql; | ||
50 | } | 52 | } |
51 | 53 | ||
52 | @Override | 54 | @Override |
@@ -60,6 +62,15 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema | @@ -60,6 +62,15 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema | ||
60 | conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema | 62 | conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema |
61 | } | 63 | } |
62 | 64 | ||
65 | + if (schemaIdxSql != null) { | ||
66 | + log.info("Installing SQL DataBase schema indexes part: " + schemaIdxSql); | ||
67 | + | ||
68 | + Path schemaIdxFile = Paths.get(installScripts.getDataDir(), SQL_DIR, schemaIdxSql); | ||
69 | + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { | ||
70 | + String sql = new String(Files.readAllBytes(schemaIdxFile), Charset.forName("UTF-8")); | ||
71 | + conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema | ||
72 | + } | ||
73 | + } | ||
63 | } | 74 | } |
64 | 75 | ||
65 | } | 76 | } |
application/src/main/java/org/thingsboard/server/service/install/SqlEntityDatabaseSchemaService.java
@@ -25,6 +25,6 @@ import org.thingsboard.server.dao.util.SqlDao; | @@ -25,6 +25,6 @@ import org.thingsboard.server.dao.util.SqlDao; | ||
25 | public class SqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService | 25 | public class SqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService |
26 | implements EntityDatabaseSchemaService { | 26 | implements EntityDatabaseSchemaService { |
27 | public SqlEntityDatabaseSchemaService() { | 27 | public SqlEntityDatabaseSchemaService() { |
28 | - super("schema-entities.sql"); | 28 | + super("schema-entities.sql", "schema-entities-idx.sql"); |
29 | } | 29 | } |
30 | } | 30 | } |
@@ -25,6 +25,6 @@ import org.thingsboard.server.dao.util.SqlTsDao; | @@ -25,6 +25,6 @@ import org.thingsboard.server.dao.util.SqlTsDao; | ||
25 | public class SqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaService | 25 | public class SqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaService |
26 | implements TsDatabaseSchemaService { | 26 | implements TsDatabaseSchemaService { |
27 | public SqlTsDatabaseSchemaService() { | 27 | public SqlTsDatabaseSchemaService() { |
28 | - super("schema-ts.sql"); | 28 | + super("schema-ts.sql", null); |
29 | } | 29 | } |
30 | } | 30 | } |
1 | +-- | ||
2 | +-- Copyright © 2016-2019 The Thingsboard Authors | ||
3 | +-- | ||
4 | +-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | +-- you may not use this file except in compliance with the License. | ||
6 | +-- You may obtain a copy of the License at | ||
7 | +-- | ||
8 | +-- http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | +-- | ||
10 | +-- Unless required by applicable law or agreed to in writing, software | ||
11 | +-- distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | +-- See the License for the specific language governing permissions and | ||
14 | +-- limitations under the License. | ||
15 | +-- | ||
16 | + | ||
17 | +CREATE INDEX IF NOT EXISTS idx_alarm_originator_alarm_type ON alarm(tenant_id, type, originator_type, originator_id); | ||
18 | + | ||
19 | +CREATE INDEX IF NOT EXISTS idx_event_type_entity_id ON event(tenant_id, event_type, entity_type, entity_id); | ||
20 | + | ||
21 | +CREATE INDEX IF NOT EXISTS idx_relation_to_id ON relation(relation_type_group, to_type, to_id); | ||
22 | + | ||
23 | +CREATE INDEX IF NOT EXISTS idx_relation_from_id ON relation(relation_type_group, from_type, from_id); |
@@ -37,8 +37,6 @@ CREATE TABLE IF NOT EXISTS alarm ( | @@ -37,8 +37,6 @@ CREATE TABLE IF NOT EXISTS alarm ( | ||
37 | type varchar(255) | 37 | type varchar(255) |
38 | ); | 38 | ); |
39 | 39 | ||
40 | -CREATE INDEX IF NOT EXISTS idx_alarm_originator_alarm_type ON alarm(tenant_id, type, originator_type, originator_id); | ||
41 | - | ||
42 | CREATE TABLE IF NOT EXISTS asset ( | 40 | CREATE TABLE IF NOT EXISTS asset ( |
43 | id varchar(31) NOT NULL CONSTRAINT asset_pkey PRIMARY KEY, | 41 | id varchar(31) NOT NULL CONSTRAINT asset_pkey PRIMARY KEY, |
44 | additional_info varchar, | 42 | additional_info varchar, |
@@ -143,8 +141,6 @@ CREATE TABLE IF NOT EXISTS event ( | @@ -143,8 +141,6 @@ CREATE TABLE IF NOT EXISTS event ( | ||
143 | CONSTRAINT event_unq_key UNIQUE (tenant_id, entity_type, entity_id, event_type, event_uid) | 141 | CONSTRAINT event_unq_key UNIQUE (tenant_id, entity_type, entity_id, event_type, event_uid) |
144 | ); | 142 | ); |
145 | 143 | ||
146 | -CREATE INDEX IF NOT EXISTS idx_event_type_entity_id ON event(tenant_id, event_type, entity_type, entity_id); | ||
147 | - | ||
148 | CREATE TABLE IF NOT EXISTS relation ( | 144 | CREATE TABLE IF NOT EXISTS relation ( |
149 | from_id varchar(31), | 145 | from_id varchar(31), |
150 | from_type varchar(255), | 146 | from_type varchar(255), |
@@ -156,10 +152,6 @@ CREATE TABLE IF NOT EXISTS relation ( | @@ -156,10 +152,6 @@ CREATE TABLE IF NOT EXISTS relation ( | ||
156 | CONSTRAINT relation_pkey PRIMARY KEY (from_id, from_type, relation_type_group, relation_type, to_id, to_type) | 152 | CONSTRAINT relation_pkey PRIMARY KEY (from_id, from_type, relation_type_group, relation_type, to_id, to_type) |
157 | ); | 153 | ); |
158 | 154 | ||
159 | -CREATE INDEX IF NOT EXISTS idx_relation_to_id ON relation(relation_type_group, to_type, to_id); | ||
160 | - | ||
161 | -CREATE INDEX IF NOT EXISTS idx_relation_from_id ON relation(relation_type_group, from_type, from_id); | ||
162 | - | ||
163 | CREATE TABLE IF NOT EXISTS tb_user ( | 155 | CREATE TABLE IF NOT EXISTS tb_user ( |
164 | id varchar(31) NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY, | 156 | id varchar(31) NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY, |
165 | additional_info varchar, | 157 | additional_info varchar, |
@@ -215,8 +207,7 @@ CREATE TABLE IF NOT EXISTS widgets_bundle ( | @@ -215,8 +207,7 @@ CREATE TABLE IF NOT EXISTS widgets_bundle ( | ||
215 | ); | 207 | ); |
216 | 208 | ||
217 | CREATE TABLE IF NOT EXISTS rule_chain ( | 209 | CREATE TABLE IF NOT EXISTS rule_chain ( |
218 | - 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); | ||
219 | -ain_pkey PRIMARY KEY, | 210 | + id varchar(31) NOT NULL CONSTRAINT rule_chain_pkey PRIMARY KEY, |
220 | additional_info varchar, | 211 | additional_info varchar, |
221 | configuration varchar(10000000), | 212 | configuration varchar(10000000), |
222 | name varchar(255), | 213 | name varchar(255), |
@@ -30,7 +30,7 @@ public class SqlDaoServiceTestSuite { | @@ -30,7 +30,7 @@ public class SqlDaoServiceTestSuite { | ||
30 | 30 | ||
31 | @ClassRule | 31 | @ClassRule |
32 | public static CustomSqlUnit sqlUnit = new CustomSqlUnit( | 32 | public static CustomSqlUnit sqlUnit = new CustomSqlUnit( |
33 | - Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/system-data.sql", "sql/system-test.sql"), | 33 | + Arrays.asList("sql/schema-ts.sql", "sql/schema-entities.sql", "sql/schema-entities-idx.sql", "sql/system-data.sql", "sql/system-test.sql"), |
34 | "sql/drop-all-tables.sql", | 34 | "sql/drop-all-tables.sql", |
35 | "sql-test.properties" | 35 | "sql-test.properties" |
36 | ); | 36 | ); |
@@ -75,7 +75,7 @@ | @@ -75,7 +75,7 @@ | ||
75 | <jts.version>1.15.0</jts.version> | 75 | <jts.version>1.15.0</jts.version> |
76 | <bouncycastle.version>1.56</bouncycastle.version> | 76 | <bouncycastle.version>1.56</bouncycastle.version> |
77 | <winsw.version>2.0.1</winsw.version> | 77 | <winsw.version>2.0.1</winsw.version> |
78 | - <hsqldb.version>2.4.0</hsqldb.version> | 78 | + <hsqldb.version>2.5.0</hsqldb.version> |
79 | <dbunit.version>2.5.3</dbunit.version> | 79 | <dbunit.version>2.5.3</dbunit.version> |
80 | <spring-test-dbunit.version>1.2.1</spring-test-dbunit.version> | 80 | <spring-test-dbunit.version>1.2.1</spring-test-dbunit.version> |
81 | <postgresql.driver.version>9.4.1211</postgresql.driver.version> | 81 | <postgresql.driver.version>9.4.1211</postgresql.driver.version> |