Merge pull request #10704 from ShvaykaD/feature/log-upgrade-queries
updated log entry for adding customer_title_unq_key if doesn't exist
This commit is contained in:
commit
1a70fe36e2
@ -84,13 +84,17 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void executeQuery(String query) {
|
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)) {
|
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
|
||||||
conn.createStatement().execute(query); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
|
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);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException | SQLException e) {
|
} catch (InterruptedException | SQLException e) {
|
||||||
log.error("Failed to execute query: {} due to: {}", query, e.getMessage());
|
throw new RuntimeException("Failed to execute query: " + logQuery, e);
|
||||||
throw new RuntimeException("Failed to execute query: " + query, e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,6 +56,7 @@ public class SqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaSer
|
|||||||
@Override
|
@Override
|
||||||
public void createCustomerTitleUniqueConstraintIfNotExists() {
|
public void createCustomerTitleUniqueConstraintIfNotExists() {
|
||||||
executeQuery("DO $$ BEGIN IF NOT EXISTS(SELECT 1 FROM pg_constraint WHERE conname = 'customer_title_unq_key') THEN " +
|
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!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user