Browse Source
Merge pull request #10704 from ShvaykaD/feature/log-upgrade-queries
updated log entry for adding customer_title_unq_key if doesn't exist
pull/10727/head
Andrew Shvayka
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
9 additions and
4 deletions
-
application/src/main/java/org/thingsboard/server/service/install/SqlAbstractDatabaseSchemaService.java
-
application/src/main/java/org/thingsboard/server/service/install/SqlEntityDatabaseSchemaService.java
|
|
|
@ -84,13 +84,17 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema |
|
|
|
} |
|
|
|
|
|
|
|
protected void executeQuery(String query) { |
|
|
|
executeQuery(query, null); |
|
|
|
} |
|
|
|
|
|
|
|
protected void executeQuery(String query, String logQuery) { |
|
|
|
logQuery = logQuery != null ? logQuery : query; |
|
|
|
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { |
|
|
|
conn.createStatement().execute(query); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
|
|
|
|
log.info("Successfully executed query: {}", query); |
|
|
|
log.info("Successfully executed query: {}", logQuery); |
|
|
|
Thread.sleep(5000); |
|
|
|
} catch (InterruptedException | SQLException e) { |
|
|
|
log.error("Failed to execute query: {} due to: {}", query, e.getMessage()); |
|
|
|
throw new RuntimeException("Failed to execute query: " + query, e); |
|
|
|
throw new RuntimeException("Failed to execute query: " + logQuery, e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -56,6 +56,7 @@ public class SqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaSer |
|
|
|
@Override |
|
|
|
public void createCustomerTitleUniqueConstraintIfNotExists() { |
|
|
|
executeQuery("DO $$ BEGIN IF NOT EXISTS(SELECT 1 FROM pg_constraint WHERE conname = 'customer_title_unq_key') THEN " + |
|
|
|
"ALTER TABLE customer ADD CONSTRAINT customer_title_unq_key UNIQUE(tenant_id, title); END IF; END; $$;"); |
|
|
|
"ALTER TABLE customer ADD CONSTRAINT customer_title_unq_key UNIQUE(tenant_id, title); END IF; END; $$;", |
|
|
|
"create 'customer_title_unq_key' constraint if it doesn't already exist!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|