Showing
7 changed files
with
23 additions
and
9 deletions
... | ... | @@ -133,13 +133,20 @@ public class ThingsboardInstallService { |
133 | 133 | databaseEntitiesUpgradeService.upgradeDatabase("2.4.2"); |
134 | 134 | |
135 | 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 | 138 | if (databaseTsUpgradeService != null) { |
139 | 139 | databaseTsUpgradeService.upgradeDatabase("2.4.3"); |
140 | 140 | } |
141 | 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 | 150 | log.info("Updating system data..."); |
144 | 151 | |
145 | 152 | systemDataLoaderService.deleteSystemWidgetBundle("charts"); | ... | ... |
... | ... | @@ -37,8 +37,6 @@ public class PsqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaServic |
37 | 37 | @Override |
38 | 38 | public void createDatabaseSchema() throws Exception { |
39 | 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 | } |
\ No newline at end of file | ... | ... |
... | ... | @@ -99,8 +99,6 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe |
99 | 99 | executeQuery(conn, CALL_CREATE_PARTITION_TS_KV_TABLE); |
100 | 100 | if (!partitionType.equals("INDEFINITE")) { |
101 | 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 | 103 | executeQuery(conn, CALL_CREATE_TS_KV_DICTIONARY_TABLE); |
106 | 104 | executeQuery(conn, CALL_INSERT_INTO_DICTIONARY); |
... | ... | @@ -194,6 +192,12 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe |
194 | 192 | } |
195 | 193 | } |
196 | 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 | 201 | default: |
198 | 202 | throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); |
199 | 203 | } | ... | ... |
... | ... | @@ -175,6 +175,11 @@ public class TimescaleTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgr |
175 | 175 | } |
176 | 176 | } |
177 | 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 | 183 | default: |
179 | 184 | throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); |
180 | 185 | } | ... | ... |
... | ... | @@ -90,7 +90,7 @@ public class JpaPsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDa |
90 | 90 | } |
91 | 91 | |
92 | 92 | private void savePartitionIfNotExist(long ts) { |
93 | - if (!tsFormat.equals(SqlTsPartitionDate.INDEFINITE)) { | |
93 | + if (!tsFormat.equals(SqlTsPartitionDate.INDEFINITE) && ts >= 0) { | |
94 | 94 | LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneOffset.UTC); |
95 | 95 | LocalDateTime localDateTimeStart = tsFormat.trancateTo(time); |
96 | 96 | long partitionStartTs = toMills(localDateTimeStart); | ... | ... |
... | ... | @@ -52,7 +52,7 @@ CREATE TABLE IF NOT EXISTS tb_schema_settings |
52 | 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 | 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 | 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 | 58 | CREATE OR REPLACE PROCEDURE drop_partitions_by_max_ttl(IN partition_type varchar, IN system_ttl bigint, INOUT deleted bigint) |
59 | 59 | LANGUAGE plpgsql AS | ... | ... |