Commit e190bb63f055358f5f98181160707a7759cb9085
1 parent
9ce07959
Expand string values column of latest values SQL table.
Showing
5 changed files
with
54 additions
and
2 deletions
1 | +-- | |
2 | +-- Copyright © 2016-2017 The Thingsboard Authors | |
3 | +-- | |
4 | +-- Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | +-- you may not use this file except in compliance with the License. | |
6 | +-- You may obtain a copy of the License at | |
7 | +-- | |
8 | +-- http://www.apache.org/licenses/LICENSE-2.0 | |
9 | +-- | |
10 | +-- Unless required by applicable law or agreed to in writing, software | |
11 | +-- distributed under the License is distributed on an "AS IS" BASIS, | |
12 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | +-- See the License for the specific language governing permissions and | |
14 | +-- limitations under the License. | |
15 | +-- | |
16 | + | |
17 | +ALTER TABLE ts_kv_latest ALTER COLUMN str_v varchar(10000000); | ... | ... |
... | ... | @@ -71,7 +71,7 @@ public class ThingsboardInstallService { |
71 | 71 | case "1.2.3": //NOSONAR, Need to execute gradual upgrade starting from upgradeFromVersion |
72 | 72 | log.info("Upgrading ThingsBoard from version 1.2.3 to 1.3.0 ..."); |
73 | 73 | |
74 | - databaseUpgradeService.upgradeDatabase(upgradeFromVersion); | |
74 | + databaseUpgradeService.upgradeDatabase("1.2.3"); | |
75 | 75 | |
76 | 76 | log.info("Updating system data..."); |
77 | 77 | |
... | ... | @@ -86,6 +86,8 @@ public class ThingsboardInstallService { |
86 | 86 | case "1.3.0": |
87 | 87 | log.info("Upgrading ThingsBoard from version 1.3.0 to 1.3.1 ..."); |
88 | 88 | |
89 | + databaseUpgradeService.upgradeDatabase("1.3.0"); | |
90 | + | |
89 | 91 | log.info("Updating system data..."); |
90 | 92 | |
91 | 93 | systemDataLoaderService.deleteSystemWidgetBundle("charts"); | ... | ... |
... | ... | @@ -155,6 +155,8 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService { |
155 | 155 | log.info("Relations restored."); |
156 | 156 | |
157 | 157 | break; |
158 | + case "1.3.0": | |
159 | + break; | |
158 | 160 | default: |
159 | 161 | throw new RuntimeException("Unable to upgrade Cassandra database, unsupported fromVersion: " + fromVersion); |
160 | 162 | } | ... | ... |
... | ... | @@ -17,19 +17,50 @@ |
17 | 17 | package org.thingsboard.server.service.install; |
18 | 18 | |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | +import org.springframework.beans.factory.annotation.Value; | |
20 | 21 | import org.springframework.context.annotation.Profile; |
21 | 22 | import org.springframework.stereotype.Service; |
22 | 23 | import org.thingsboard.server.dao.util.SqlDao; |
23 | 24 | |
25 | +import java.nio.charset.Charset; | |
26 | +import java.nio.file.Files; | |
27 | +import java.nio.file.Path; | |
28 | +import java.nio.file.Paths; | |
29 | +import java.sql.Connection; | |
30 | +import java.sql.DriverManager; | |
31 | + | |
24 | 32 | @Service |
25 | 33 | @Profile("install") |
26 | 34 | @Slf4j |
27 | 35 | @SqlDao |
28 | 36 | public class SqlDatabaseUpgradeService implements DatabaseUpgradeService { |
29 | 37 | |
38 | + private static final String SCHEMA_UPDATE_SQL = "schema_update.sql"; | |
39 | + | |
40 | + @Value("${install.data_dir}") | |
41 | + private String dataDir; | |
42 | + | |
43 | + @Value("${spring.datasource.url}") | |
44 | + private String dbUrl; | |
45 | + | |
46 | + @Value("${spring.datasource.username}") | |
47 | + private String dbUserName; | |
48 | + | |
49 | + @Value("${spring.datasource.password}") | |
50 | + private String dbPassword; | |
51 | + | |
30 | 52 | @Override |
31 | 53 | public void upgradeDatabase(String fromVersion) throws Exception { |
32 | 54 | switch (fromVersion) { |
55 | + case "1.3.0": | |
56 | + log.info("Updating schema ..."); | |
57 | + Path schemaUpdateFile = Paths.get(this.dataDir, "upgrade", "1.3.1", SCHEMA_UPDATE_SQL); | |
58 | + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { | |
59 | + String sql = new String(Files.readAllBytes(schemaUpdateFile), Charset.forName("UTF-8")); | |
60 | + conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script | |
61 | + } | |
62 | + log.info("Schema updated."); | |
63 | + break; | |
33 | 64 | default: |
34 | 65 | throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); |
35 | 66 | } | ... | ... |
... | ... | @@ -209,7 +209,7 @@ CREATE TABLE IF NOT EXISTS ts_kv_latest ( |
209 | 209 | key varchar(255) NOT NULL, |
210 | 210 | ts bigint NOT NULL, |
211 | 211 | bool_v boolean, |
212 | - str_v varchar, | |
212 | + str_v varchar(10000000), | |
213 | 213 | long_v bigint, |
214 | 214 | dbl_v double precision, |
215 | 215 | CONSTRAINT ts_kv_latest_unq_key UNIQUE (entity_type, entity_id, key) | ... | ... |