committed by
GitHub
44 changed files with 406 additions and 119 deletions
@ -0,0 +1,30 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.install; |
||||
|
|
||||
|
import org.springframework.context.annotation.Profile; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.dao.util.NoSqlDao; |
||||
|
|
||||
|
@Service |
||||
|
@NoSqlDao |
||||
|
@Profile("install") |
||||
|
public class CassandraEntityDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService |
||||
|
implements EntityDatabaseSchemaService { |
||||
|
public CassandraEntityDatabaseSchemaService() { |
||||
|
super("schema-entities.cql"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.install; |
||||
|
|
||||
|
import org.springframework.context.annotation.Profile; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.dao.util.NoSqlTsDao; |
||||
|
|
||||
|
@Service |
||||
|
@NoSqlTsDao |
||||
|
@Profile("install") |
||||
|
public class CassandraTsDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService |
||||
|
implements TsDatabaseSchemaService { |
||||
|
public CassandraTsDatabaseSchemaService() { |
||||
|
super("schema-ts.cql"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.install; |
||||
|
|
||||
|
public interface EntityDatabaseSchemaService extends DatabaseSchemaService { |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.install; |
||||
|
|
||||
|
import org.springframework.context.annotation.Profile; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.dao.util.SqlDao; |
||||
|
|
||||
|
@Service |
||||
|
@SqlDao |
||||
|
@Profile("install") |
||||
|
public class SqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService |
||||
|
implements EntityDatabaseSchemaService { |
||||
|
public SqlEntityDatabaseSchemaService() { |
||||
|
super("schema-entities.sql"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.install; |
||||
|
|
||||
|
import org.springframework.context.annotation.Profile; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.dao.util.SqlTsDao; |
||||
|
|
||||
|
@Service |
||||
|
@SqlTsDao |
||||
|
@Profile("install") |
||||
|
public class SqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaService |
||||
|
implements TsDatabaseSchemaService { |
||||
|
public SqlTsDatabaseSchemaService() { |
||||
|
super("schema-ts.sql"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.install; |
||||
|
|
||||
|
public interface TsDatabaseSchemaService extends DatabaseSchemaService { |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.util; |
||||
|
|
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
||||
|
|
||||
|
@ConditionalOnExpression("'${database.ts.type}'=='cassandra' || '${database.entities.type}'=='cassandra'") |
||||
|
public @interface NoSqlAnyDao { |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.util; |
||||
|
|
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
|
|
||||
|
@ConditionalOnProperty(prefix = "database.ts", value = "type", havingValue = "cassandra") |
||||
|
public @interface NoSqlTsDao { |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.util; |
||||
|
|
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
|
|
||||
|
@ConditionalOnProperty(prefix = "database.ts", value = "type", havingValue = "sql") |
||||
|
public @interface SqlTsDao { |
||||
|
} |
||||
@ -0,0 +1,55 @@ |
|||||
|
-- |
||||
|
-- Copyright © 2016-2018 The Thingsboard Authors |
||||
|
-- |
||||
|
-- Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
-- you may not use this file except in compliance with the License. |
||||
|
-- You may obtain a copy of the License at |
||||
|
-- |
||||
|
-- http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
-- |
||||
|
-- Unless required by applicable law or agreed to in writing, software |
||||
|
-- distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
-- See the License for the specific language governing permissions and |
||||
|
-- limitations under the License. |
||||
|
-- |
||||
|
|
||||
|
CREATE KEYSPACE IF NOT EXISTS thingsboard |
||||
|
WITH replication = { |
||||
|
'class' : 'SimpleStrategy', |
||||
|
'replication_factor' : 1 |
||||
|
}; |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_cf ( |
||||
|
entity_type text, // (DEVICE, CUSTOMER, TENANT) |
||||
|
entity_id timeuuid, |
||||
|
key text, |
||||
|
partition bigint, |
||||
|
ts bigint, |
||||
|
bool_v boolean, |
||||
|
str_v text, |
||||
|
long_v bigint, |
||||
|
dbl_v double, |
||||
|
PRIMARY KEY (( entity_type, entity_id, key, partition ), ts) |
||||
|
); |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_partitions_cf ( |
||||
|
entity_type text, // (DEVICE, CUSTOMER, TENANT) |
||||
|
entity_id timeuuid, |
||||
|
key text, |
||||
|
partition bigint, |
||||
|
PRIMARY KEY (( entity_type, entity_id, key ), partition) |
||||
|
) WITH CLUSTERING ORDER BY ( partition ASC ) |
||||
|
AND compaction = { 'class' : 'LeveledCompactionStrategy' }; |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS thingsboard.ts_kv_latest_cf ( |
||||
|
entity_type text, // (DEVICE, CUSTOMER, TENANT) |
||||
|
entity_id timeuuid, |
||||
|
key text, |
||||
|
ts bigint, |
||||
|
bool_v boolean, |
||||
|
str_v text, |
||||
|
long_v bigint, |
||||
|
dbl_v double, |
||||
|
PRIMARY KEY (( entity_type, entity_id ), key) |
||||
|
) WITH compaction = { 'class' : 'LeveledCompactionStrategy' }; |
||||
@ -0,0 +1,39 @@ |
|||||
|
-- |
||||
|
-- Copyright © 2016-2018 The Thingsboard Authors |
||||
|
-- |
||||
|
-- Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
-- you may not use this file except in compliance with the License. |
||||
|
-- You may obtain a copy of the License at |
||||
|
-- |
||||
|
-- http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
-- |
||||
|
-- Unless required by applicable law or agreed to in writing, software |
||||
|
-- distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
-- See the License for the specific language governing permissions and |
||||
|
-- limitations under the License. |
||||
|
-- |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS ts_kv ( |
||||
|
entity_type varchar(255) NOT NULL, |
||||
|
entity_id varchar(31) NOT NULL, |
||||
|
key varchar(255) NOT NULL, |
||||
|
ts bigint NOT NULL, |
||||
|
bool_v boolean, |
||||
|
str_v varchar(10000000), |
||||
|
long_v bigint, |
||||
|
dbl_v double precision, |
||||
|
CONSTRAINT ts_kv_unq_key UNIQUE (entity_type, entity_id, key, ts) |
||||
|
); |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS ts_kv_latest ( |
||||
|
entity_type varchar(255) NOT NULL, |
||||
|
entity_id varchar(31) NOT NULL, |
||||
|
key varchar(255) NOT NULL, |
||||
|
ts bigint NOT NULL, |
||||
|
bool_v boolean, |
||||
|
str_v varchar(10000000), |
||||
|
long_v bigint, |
||||
|
dbl_v double precision, |
||||
|
CONSTRAINT ts_kv_latest_unq_key UNIQUE (entity_type, entity_id, key) |
||||
|
); |
||||
Loading…
Reference in new issue