File tree 6 files changed +36
-8
lines changed
6 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,9 @@ dmypy.json
152
152
# Cython debug symbols
153
153
cython_debug /
154
154
155
+ # MacOS
156
+ .DS_Store
157
+
155
158
# PyCharm
156
159
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
160
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
Original file line number Diff line number Diff line change @@ -103,11 +103,11 @@ configuration.yaml
103
103
## Details
104
104
The states are stored in a single table ([ hypertable] ( https://docs.timescale.com/latest/using-timescaledb/hypertables ) , when TimescaleDB is available) with the following layout:
105
105
106
- | Column name: | id | time | entity_id | state | attributes | location [ PostGIS-only] |
107
- | :---| :--- :| :---:| :---:| :---:| :---:| :-----------------------:|
108
- | Type: | bigint | timestamp with timezone | string | string | JSONB | POINT(4326) |
106
+ | Column name: | time | entity_id | state | attributes | location [ PostGIS-only] |
107
+ | :---:| :---:| :---:| :---:| :---:| :-----------------------:|
108
+ | Type: | timestamp with timezone | string | string | JSONB | POINT(4326) |
109
109
| Primary key: | x | x | | | |
110
- | Index: | x | x | x | x | x | |
110
+ | Index: | x | x | x | x | |
111
111
112
112
### Only available with TimescaleDB:
113
113
[ Chunk size] ( https://docs.timescale.com/latest/using-timescaledb/hypertables#best-practices ) of the hypertable is configurable using the ` chunk_time_interval ` config option. It defaults to 2592000000000 microseconds (30 days).
Original file line number Diff line number Diff line change 1
1
{
2
2
"domain" : " ltss" ,
3
- "version" : " 2.0.1 " ,
3
+ "version" : " 2.1.0 " ,
4
4
"name" : " Long Time State Storage (LTSS)" ,
5
5
"documentation" : " https://github.com/freol35241/ltss" ,
6
6
"requirements" : [
Original file line number Diff line number Diff line change @@ -46,6 +46,13 @@ def index_exists(index_name):
46
46
_LOGGER .warning ("Index on entity_id no longer needed, dropping..." )
47
47
drop_entityid_index (engine )
48
48
49
+ # id column?
50
+ if any (col ["name" ] == "id" for col in columns ):
51
+ _LOGGER .warning (
52
+ "Migrating you LTSS table to the latest schema, this might take a couple of minutes!"
53
+ )
54
+ remove_id_column (engine )
55
+
49
56
50
57
def migrate_attributes_text_to_jsonb (engine ):
51
58
with engine .connect () as con :
@@ -75,3 +82,22 @@ def drop_entityid_index(engine):
75
82
autocommit = True
76
83
)
77
84
)
85
+
86
+
87
+ def remove_id_column (engine ):
88
+ with engine .begin () as con :
89
+ con .execute (
90
+ text (
91
+ f"""ALTER TABLE { LTSS .__tablename__ }
92
+ DROP CONSTRAINT { LTSS .__tablename__ } _pkey CASCADE,
93
+ ADD PRIMARY KEY(time,entity_id);"""
94
+ )
95
+ )
96
+ con .execute (
97
+ text (
98
+ f"""ALTER TABLE { LTSS .__tablename__ }
99
+ DROP COLUMN id"""
100
+ )
101
+ )
102
+ con .commit ()
103
+ _LOGGER .info ("Migration completed successfully!" )
Original file line number Diff line number Diff line change @@ -27,9 +27,8 @@ class LTSS(Base): # type: ignore
27
27
"""State change history."""
28
28
29
29
__tablename__ = "ltss"
30
- id = Column (BigInteger , primary_key = True , autoincrement = True )
31
30
time = Column (DateTime (timezone = True ), default = datetime .utcnow , primary_key = True )
32
- entity_id = Column (String (255 ))
31
+ entity_id = Column (String (255 ), primary_key = True )
33
32
state = Column (String (255 ), index = True )
34
33
attributes = Column (JSONB )
35
34
location = None # when not activated, no location column will be added to the table/database
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ def _is_hypertable(con):
128
128
@staticmethod
129
129
def _has_columns (con ):
130
130
return (
131
- 5
131
+ 4
132
132
<= con .execute (
133
133
text (
134
134
f"SELECT COLUMN_NAME\
You can’t perform that action at this time.
0 commit comments