Fix upgrade scripts.
This commit is contained in:
parent
84460a0094
commit
562bbbe849
@ -14,6 +14,14 @@
|
||||
-- limitations under the License.
|
||||
--
|
||||
|
||||
CREATE OR REPLACE FUNCTION to_uuid(IN entity_id varchar, OUT uuid_id uuid) AS
|
||||
$$
|
||||
BEGIN
|
||||
uuid_id := substring(entity_id, 8, 8) || '-' || substring(entity_id, 4, 4) || '-1' || substring(entity_id, 1, 3) ||
|
||||
'-' || substring(entity_id, 16, 4) || '-' || substring(entity_id, 20, 12);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION extract_ts(uuid UUID) RETURNS BIGINT AS
|
||||
$$
|
||||
DECLARE
|
||||
@ -826,3 +834,23 @@ BEGIN
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ts_kv_latest
|
||||
(
|
||||
entity_id uuid NOT NULL,
|
||||
key int NOT NULL,
|
||||
ts bigint NOT NULL,
|
||||
bool_v boolean,
|
||||
str_v varchar(10000000),
|
||||
long_v bigint,
|
||||
dbl_v double precision,
|
||||
json_v json,
|
||||
CONSTRAINT ts_kv_latest_pkey PRIMARY KEY (entity_id, key)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ts_kv_dictionary
|
||||
(
|
||||
key varchar(255) NOT NULL,
|
||||
key_id serial UNIQUE,
|
||||
CONSTRAINT ts_key_id_pkey PRIMARY KEY (key)
|
||||
);
|
||||
|
||||
@ -156,12 +156,11 @@ public class ThingsboardInstallService {
|
||||
}
|
||||
case "2.5.1":
|
||||
log.info("Upgrading ThingsBoard from version 2.5.1 to 3.0.0 ...");
|
||||
log.info("Updating system data...");
|
||||
systemDataLoaderService.updateSystemWidgets();
|
||||
break;
|
||||
case "3.0.1":
|
||||
log.info("Upgrading ThingsBoard from version 3.0.1 to 3.1.0 ...");
|
||||
databaseEntitiesUpgradeService.upgradeDatabase("3.0.1");
|
||||
log.info("Updating system data...");
|
||||
systemDataLoaderService.updateSystemWidgets();
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unable to upgrade ThingsBoard, unsupported fromVersion: " + upgradeFromVersion);
|
||||
|
||||
@ -254,13 +254,9 @@ public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService
|
||||
|
||||
conn.createStatement().execute("call drop_all_idx()");
|
||||
|
||||
log.info("Updating alarm relations...");
|
||||
log.info("Optimizing alarm relations...");
|
||||
conn.createStatement().execute("DELETE from relation WHERE relation_type_group = 'ALARM' AND relation_type <> 'ALARM_ANY';");
|
||||
|
||||
conn.createStatement().execute("UPDATE relation SET relation_type = 'ANY' WHERE relation_type_group = 'ALARM' AND relation_type = 'ALARM_ANY';");
|
||||
log.info("Alarm relations updated.");
|
||||
|
||||
conn.createStatement().execute("VACUUM FULL relation");
|
||||
log.info("Alarm relations optimized.");
|
||||
|
||||
for (String table : tables) {
|
||||
log.info("Updating table {}.", table);
|
||||
@ -286,6 +282,10 @@ public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService
|
||||
conn.createStatement().execute("DROP PROCEDURE create_all_idx");
|
||||
conn.createStatement().execute("DROP FUNCTION column_type_to_uuid");
|
||||
|
||||
log.info("Updating alarm relations...");
|
||||
conn.createStatement().execute("UPDATE relation SET relation_type = 'ANY' WHERE relation_type_group = 'ALARM' AND relation_type = 'ALARM_ANY';");
|
||||
log.info("Alarm relations updated.");
|
||||
|
||||
conn.createStatement().execute("UPDATE tb_schema_settings SET schema_version = 3001000;");
|
||||
|
||||
conn.createStatement().execute("VACUUM FULL");
|
||||
|
||||
@ -277,6 +277,26 @@ CREATE TABLE IF NOT EXISTS entity_view (
|
||||
additional_info varchar
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ts_kv_latest
|
||||
(
|
||||
entity_id uuid NOT NULL,
|
||||
key int NOT NULL,
|
||||
ts bigint NOT NULL,
|
||||
bool_v boolean,
|
||||
str_v varchar(10000000),
|
||||
long_v bigint,
|
||||
dbl_v double precision,
|
||||
json_v json,
|
||||
CONSTRAINT ts_kv_latest_pkey PRIMARY KEY (entity_id, key)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ts_kv_dictionary
|
||||
(
|
||||
key varchar(255) NOT NULL,
|
||||
key_id serial UNIQUE,
|
||||
CONSTRAINT ts_key_id_pkey PRIMARY KEY (key)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE PROCEDURE cleanup_events_by_ttl(IN ttl bigint, IN debug_ttl bigint, INOUT deleted bigint)
|
||||
LANGUAGE plpgsql AS
|
||||
$$
|
||||
@ -301,3 +321,11 @@ BEGIN
|
||||
deleted := ttl_deleted_count + debug_ttl_deleted_count;
|
||||
END
|
||||
$$;
|
||||
|
||||
CREATE OR REPLACE FUNCTION to_uuid(IN entity_id varchar, OUT uuid_id uuid) AS
|
||||
$$
|
||||
BEGIN
|
||||
uuid_id := substring(entity_id, 8, 8) || '-' || substring(entity_id, 4, 4) || '-1' || substring(entity_id, 1, 3) ||
|
||||
'-' || substring(entity_id, 16, 4) || '-' || substring(entity_id, 20, 12);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user