Showing
7 changed files
with
23 additions
and
9 deletions
@@ -133,13 +133,20 @@ public class ThingsboardInstallService { | @@ -133,13 +133,20 @@ public class ThingsboardInstallService { | ||
133 | databaseEntitiesUpgradeService.upgradeDatabase("2.4.2"); | 133 | databaseEntitiesUpgradeService.upgradeDatabase("2.4.2"); |
134 | 134 | ||
135 | case "2.4.3": | 135 | case "2.4.3": |
136 | - log.info("Upgrading ThingsBoard from version 2.4.3 to 2.5 ..."); | 136 | + log.info("Upgrading ThingsBoard from version 2.4.3 to 2.5.0 ..."); |
137 | 137 | ||
138 | if (databaseTsUpgradeService != null) { | 138 | if (databaseTsUpgradeService != null) { |
139 | databaseTsUpgradeService.upgradeDatabase("2.4.3"); | 139 | databaseTsUpgradeService.upgradeDatabase("2.4.3"); |
140 | } | 140 | } |
141 | databaseEntitiesUpgradeService.upgradeDatabase("2.4.3"); | 141 | databaseEntitiesUpgradeService.upgradeDatabase("2.4.3"); |
142 | 142 | ||
143 | + case "2.5.0": | ||
144 | + log.info("Upgrading ThingsBoard from version 2.5.0 to 2.5.1 ..."); | ||
145 | + if (databaseTsUpgradeService != null) { | ||
146 | + databaseTsUpgradeService.upgradeDatabase("2.5.0"); | ||
147 | + } | ||
148 | + | ||
149 | + | ||
143 | log.info("Updating system data..."); | 150 | log.info("Updating system data..."); |
144 | 151 | ||
145 | systemDataLoaderService.deleteSystemWidgetBundle("charts"); | 152 | systemDataLoaderService.deleteSystemWidgetBundle("charts"); |
@@ -37,8 +37,6 @@ public class PsqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaServic | @@ -37,8 +37,6 @@ public class PsqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaServic | ||
37 | @Override | 37 | @Override |
38 | public void createDatabaseSchema() throws Exception { | 38 | public void createDatabaseSchema() throws Exception { |
39 | super.createDatabaseSchema(); | 39 | super.createDatabaseSchema(); |
40 | - if (partitionType.equals("INDEFINITE")) { | ||
41 | - executeQuery("CREATE TABLE ts_kv_indefinite PARTITION OF ts_kv DEFAULT;"); | ||
42 | - } | 40 | + executeQuery("CREATE TABLE IF NOT EXISTS ts_kv_indefinite PARTITION OF ts_kv DEFAULT;"); |
43 | } | 41 | } |
44 | } | 42 | } |
@@ -99,8 +99,6 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe | @@ -99,8 +99,6 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe | ||
99 | executeQuery(conn, CALL_CREATE_PARTITION_TS_KV_TABLE); | 99 | executeQuery(conn, CALL_CREATE_PARTITION_TS_KV_TABLE); |
100 | if (!partitionType.equals("INDEFINITE")) { | 100 | if (!partitionType.equals("INDEFINITE")) { |
101 | executeQuery(conn, "call create_partitions('" + partitionType + "')"); | 101 | executeQuery(conn, "call create_partitions('" + partitionType + "')"); |
102 | - } else { | ||
103 | - executeQuery(conn, "CREATE TABLE IF NOT EXISTS ts_kv_indefinite PARTITION OF ts_kv DEFAULT;"); | ||
104 | } | 102 | } |
105 | executeQuery(conn, CALL_CREATE_TS_KV_DICTIONARY_TABLE); | 103 | executeQuery(conn, CALL_CREATE_TS_KV_DICTIONARY_TABLE); |
106 | executeQuery(conn, CALL_INSERT_INTO_DICTIONARY); | 104 | executeQuery(conn, CALL_INSERT_INTO_DICTIONARY); |
@@ -194,6 +192,12 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe | @@ -194,6 +192,12 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe | ||
194 | } | 192 | } |
195 | } | 193 | } |
196 | break; | 194 | break; |
195 | + case "2.5.0": | ||
196 | + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { | ||
197 | + executeQuery(conn, "CREATE TABLE IF NOT EXISTS ts_kv_indefinite PARTITION OF ts_kv DEFAULT;"); | ||
198 | + executeQuery(conn, "UPDATE tb_schema_settings SET schema_version = 2005001"); | ||
199 | + } | ||
200 | + break; | ||
197 | default: | 201 | default: |
198 | throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); | 202 | throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); |
199 | } | 203 | } |
@@ -175,6 +175,11 @@ public class TimescaleTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgr | @@ -175,6 +175,11 @@ public class TimescaleTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgr | ||
175 | } | 175 | } |
176 | } | 176 | } |
177 | break; | 177 | break; |
178 | + case "2.5.0": | ||
179 | + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { | ||
180 | + executeQuery(conn, "UPDATE tb_schema_settings SET schema_version = 2005001"); | ||
181 | + } | ||
182 | + break; | ||
178 | default: | 183 | default: |
179 | throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); | 184 | throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); |
180 | } | 185 | } |
@@ -90,7 +90,7 @@ public class JpaPsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDa | @@ -90,7 +90,7 @@ public class JpaPsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDa | ||
90 | } | 90 | } |
91 | 91 | ||
92 | private void savePartitionIfNotExist(long ts) { | 92 | private void savePartitionIfNotExist(long ts) { |
93 | - if (!tsFormat.equals(SqlTsPartitionDate.INDEFINITE)) { | 93 | + if (!tsFormat.equals(SqlTsPartitionDate.INDEFINITE) && ts >= 0) { |
94 | LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneOffset.UTC); | 94 | LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneOffset.UTC); |
95 | LocalDateTime localDateTimeStart = tsFormat.trancateTo(time); | 95 | LocalDateTime localDateTimeStart = tsFormat.trancateTo(time); |
96 | long partitionStartTs = toMills(localDateTimeStart); | 96 | long partitionStartTs = toMills(localDateTimeStart); |
@@ -52,7 +52,7 @@ CREATE TABLE IF NOT EXISTS tb_schema_settings | @@ -52,7 +52,7 @@ CREATE TABLE IF NOT EXISTS tb_schema_settings | ||
52 | CONSTRAINT tb_schema_settings_pkey PRIMARY KEY (schema_version) | 52 | CONSTRAINT tb_schema_settings_pkey PRIMARY KEY (schema_version) |
53 | ); | 53 | ); |
54 | 54 | ||
55 | -INSERT INTO tb_schema_settings (schema_version) VALUES (2005000) ON CONFLICT (schema_version) DO UPDATE SET schema_version = 2005000; | 55 | +INSERT INTO tb_schema_settings (schema_version) VALUES (2005001) ON CONFLICT (schema_version) DO UPDATE SET schema_version = 2005001; |
56 | 56 | ||
57 | CREATE OR REPLACE FUNCTION to_uuid(IN entity_id varchar, OUT uuid_id uuid) AS | 57 | CREATE OR REPLACE FUNCTION to_uuid(IN entity_id varchar, OUT uuid_id uuid) AS |
58 | $$ | 58 | $$ |
@@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS tb_schema_settings | @@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS tb_schema_settings | ||
53 | CONSTRAINT tb_schema_settings_pkey PRIMARY KEY (schema_version) | 53 | CONSTRAINT tb_schema_settings_pkey PRIMARY KEY (schema_version) |
54 | ); | 54 | ); |
55 | 55 | ||
56 | -INSERT INTO tb_schema_settings (schema_version) VALUES (2005000) ON CONFLICT (schema_version) DO UPDATE SET schema_version = 2005000; | 56 | +INSERT INTO tb_schema_settings (schema_version) VALUES (2005001) ON CONFLICT (schema_version) DO UPDATE SET schema_version = 2005001; |
57 | 57 | ||
58 | CREATE OR REPLACE PROCEDURE drop_partitions_by_max_ttl(IN partition_type varchar, IN system_ttl bigint, INOUT deleted bigint) | 58 | CREATE OR REPLACE PROCEDURE drop_partitions_by_max_ttl(IN partition_type varchar, IN system_ttl bigint, INOUT deleted bigint) |
59 | LANGUAGE plpgsql AS | 59 | LANGUAGE plpgsql AS |