Separate SQL indexes file.
This commit is contained in:
		
							parent
							
								
									15b6b4ef2a
								
							
						
					
					
						commit
						f140f6d475
					
				@ -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
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								dao/src/main/resources/sql/schema-entities-idx.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								dao/src/main/resources/sql/schema-entities-idx.sql
									
									
									
									
									
										Normal file
									
								
							@ -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);
 | 
			
		||||
@ -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),
 | 
			
		||||
 | 
			
		||||
@ -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"
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							@ -75,7 +75,7 @@
 | 
			
		||||
        <jts.version>1.15.0</jts.version>
 | 
			
		||||
        <bouncycastle.version>1.56</bouncycastle.version>
 | 
			
		||||
        <winsw.version>2.0.1</winsw.version>
 | 
			
		||||
        <hsqldb.version>2.4.0</hsqldb.version>
 | 
			
		||||
        <hsqldb.version>2.5.0</hsqldb.version>
 | 
			
		||||
        <dbunit.version>2.5.3</dbunit.version>
 | 
			
		||||
        <spring-test-dbunit.version>1.2.1</spring-test-dbunit.version>
 | 
			
		||||
        <postgresql.driver.version>9.4.1211</postgresql.driver.version>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user