Merge branch 'master' of https://github.com/thingsboard/thingsboard into map/3.0
This commit is contained in:
commit
be5e3907d8
@ -14,24 +14,6 @@
|
||||
-- limitations under the License.
|
||||
--
|
||||
|
||||
-- call check_version();
|
||||
|
||||
CREATE OR REPLACE PROCEDURE check_version(INOUT valid_version boolean) LANGUAGE plpgsql AS $BODY$
|
||||
DECLARE
|
||||
current_version integer;
|
||||
BEGIN
|
||||
RAISE NOTICE 'Check the current installed PostgreSQL version...';
|
||||
SELECT current_setting('server_version_num') INTO current_version;
|
||||
IF current_version > 110000 THEN
|
||||
RAISE NOTICE 'PostgreSQL version is valid!';
|
||||
RAISE NOTICE 'Schema update started...';
|
||||
SELECT true INTO valid_version;
|
||||
ELSE
|
||||
RAISE NOTICE 'Postgres version should be at least more than 10!';
|
||||
END IF;
|
||||
END;
|
||||
$BODY$;
|
||||
|
||||
-- call create_partition_ts_kv_table();
|
||||
|
||||
CREATE OR REPLACE PROCEDURE create_partition_ts_kv_table() LANGUAGE plpgsql AS $$
|
||||
|
||||
@ -14,25 +14,6 @@
|
||||
-- limitations under the License.
|
||||
--
|
||||
|
||||
-- call check_version();
|
||||
|
||||
CREATE OR REPLACE PROCEDURE check_version(INOUT valid_version boolean) LANGUAGE plpgsql AS $BODY$
|
||||
|
||||
DECLARE
|
||||
current_version integer;
|
||||
BEGIN
|
||||
RAISE NOTICE 'Check the current installed PostgreSQL version...';
|
||||
SELECT current_setting('server_version_num') INTO current_version;
|
||||
IF current_version > 110000 THEN
|
||||
RAISE NOTICE 'PostgreSQL version is valid!';
|
||||
RAISE NOTICE 'Schema update started...';
|
||||
SELECT true INTO valid_version;
|
||||
ELSE
|
||||
RAISE NOTICE 'Postgres version should be at least more than 10!';
|
||||
END IF;
|
||||
END;
|
||||
$BODY$;
|
||||
|
||||
-- call create_new_ts_kv_table();
|
||||
|
||||
CREATE OR REPLACE PROCEDURE create_new_ts_kv_table() LANGUAGE plpgsql AS $$
|
||||
|
||||
@ -32,11 +32,8 @@ import java.sql.Statement;
|
||||
public abstract class AbstractSqlTsDatabaseUpgradeService {
|
||||
|
||||
protected static final String CALL_REGEX = "call ";
|
||||
protected static final String CHECK_VERSION = "check_version(false)";
|
||||
protected static final String CHECK_VERSION_TO_DELETE = "check_version(INOUT valid_version boolean)";
|
||||
protected static final String DROP_TABLE = "DROP TABLE ";
|
||||
protected static final String DROP_PROCEDURE_IF_EXISTS = "DROP PROCEDURE IF EXISTS ";
|
||||
protected static final String DROP_PROCEDURE_CHECK_VERSION = DROP_PROCEDURE_IF_EXISTS + CHECK_VERSION_TO_DELETE;
|
||||
|
||||
@Value("${spring.datasource.url}")
|
||||
protected String dbUrl;
|
||||
@ -58,13 +55,14 @@ public abstract class AbstractSqlTsDatabaseUpgradeService {
|
||||
}
|
||||
|
||||
protected boolean checkVersion(Connection conn) {
|
||||
log.info("Check the current PostgreSQL version...");
|
||||
boolean versionValid = false;
|
||||
try {
|
||||
Statement statement = conn.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery(CALL_REGEX + CHECK_VERSION);
|
||||
ResultSet resultSet = statement.executeQuery("SELECT current_setting('server_version_num')");
|
||||
resultSet.next();
|
||||
versionValid = resultSet.getBoolean(1);
|
||||
if(resultSet.getLong(1) > 110000) {
|
||||
versionValid = true;
|
||||
}
|
||||
statement.close();
|
||||
} catch (Exception e) {
|
||||
log.info("Failed to check current PostgreSQL version due to: {}", e.getMessage());
|
||||
|
||||
@ -70,16 +70,15 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe
|
||||
switch (fromVersion) {
|
||||
case "2.4.3":
|
||||
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
|
||||
log.info("Updating timeseries schema ...");
|
||||
log.info("Load upgrade functions ...");
|
||||
loadSql(conn);
|
||||
log.info("Check the current PostgreSQL version...");
|
||||
boolean versionValid = checkVersion(conn);
|
||||
if (!versionValid) {
|
||||
log.info("PostgreSQL version should be at least more than 11!");
|
||||
log.info("Please upgrade your PostgreSQL and restart the script!");
|
||||
throw new RuntimeException("PostgreSQL version should be at least more than 11, please upgrade your PostgreSQL and restart the script!");
|
||||
} else {
|
||||
log.info("PostgreSQL version is valid!");
|
||||
log.info("Updating schema ...");
|
||||
log.info("Load upgrade functions ...");
|
||||
loadSql(conn);
|
||||
log.info("Updating timeseries schema ...");
|
||||
executeQuery(conn, CALL_CREATE_PARTITION_TS_KV_TABLE);
|
||||
executeQuery(conn, CALL_CREATE_PARTITIONS);
|
||||
executeQuery(conn, CALL_CREATE_TS_KV_DICTIONARY_TABLE);
|
||||
@ -91,7 +90,6 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe
|
||||
executeQuery(conn, DROP_TABLE_TS_KV_OLD);
|
||||
executeQuery(conn, DROP_TABLE_TS_KV_LATEST_OLD);
|
||||
|
||||
executeQuery(conn, DROP_PROCEDURE_CHECK_VERSION);
|
||||
executeQuery(conn, DROP_PROCEDURE_CREATE_PARTITION_TS_KV_TABLE);
|
||||
executeQuery(conn, DROP_PROCEDURE_CREATE_PARTITIONS);
|
||||
executeQuery(conn, DROP_PROCEDURE_CREATE_TS_KV_DICTIONARY_TABLE);
|
||||
|
||||
@ -73,16 +73,15 @@ public class TimescaleTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgr
|
||||
switch (fromVersion) {
|
||||
case "2.4.3":
|
||||
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
|
||||
log.info("Updating timescale schema ...");
|
||||
log.info("Load upgrade functions ...");
|
||||
loadSql(conn);
|
||||
log.info("Check the current PostgreSQL version...");
|
||||
boolean versionValid = checkVersion(conn);
|
||||
if (!versionValid) {
|
||||
log.info("PostgreSQL version should be at least more than 11!");
|
||||
log.info("Please upgrade your PostgreSQL and restart the script!");
|
||||
throw new RuntimeException("PostgreSQL version should be at least more than 11, please upgrade your PostgreSQL and restart the script!");
|
||||
} else {
|
||||
log.info("PostgreSQL version is valid!");
|
||||
log.info("Updating schema ...");
|
||||
log.info("Load upgrade functions ...");
|
||||
loadSql(conn);
|
||||
log.info("Updating timescale schema ...");
|
||||
executeQuery(conn, CALL_CREATE_TS_KV_LATEST_TABLE);
|
||||
executeQuery(conn, CALL_CREATE_NEW_TENANT_TS_KV_TABLE);
|
||||
|
||||
@ -105,7 +104,7 @@ public class TimescaleTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgr
|
||||
executeQuery(conn, "ALTER TABLE ts_kv ADD COLUMN json_v json;");
|
||||
executeQuery(conn, "ALTER TABLE ts_kv_latest ADD COLUMN json_v json;");
|
||||
|
||||
log.info("schema timeseries updated!");
|
||||
log.info("schema timescale updated!");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user