mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Fix migration 5
This commit is contained in:
parent
90ef81d8d5
commit
9ad1d290af
@ -412,19 +412,27 @@ class Recorder(threading.Thread):
|
|||||||
|
|
||||||
if migration_id < 5:
|
if migration_id < 5:
|
||||||
# Add domain so that thermostat graphs look right
|
# Add domain so that thermostat graphs look right
|
||||||
self.query("""
|
try:
|
||||||
ALTER TABLE states
|
cur.execute("""
|
||||||
ADD COLUMN domain text
|
ALTER TABLE states
|
||||||
""")
|
ADD COLUMN domain text
|
||||||
|
""")
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
# We had a bug in this migration for a while on dev
|
||||||
|
# Without this, dev-users will have to throw away their db
|
||||||
|
pass
|
||||||
|
|
||||||
|
# TravisCI has Python compiled against an old version of SQLite3
|
||||||
|
# which misses the instr method.
|
||||||
|
self.conn.create_function(
|
||||||
|
"instr", 2,
|
||||||
|
lambda string, substring: string.find(substring) + 1)
|
||||||
|
|
||||||
# populate domain with defaults
|
# populate domain with defaults
|
||||||
rows = self.query("select distinct entity_id from states")
|
cur.execute("""
|
||||||
for row in rows:
|
UPDATE states
|
||||||
entity_id = row[0]
|
set domain=substr(entity_id, 0, instr(entity_id, '.'))
|
||||||
domain = entity_id.split(".")[0]
|
""")
|
||||||
self.query(
|
|
||||||
"UPDATE states set domain=? where entity_id=?",
|
|
||||||
domain, entity_id)
|
|
||||||
|
|
||||||
# add indexes we are going to use a lot on selects
|
# add indexes we are going to use a lot on selects
|
||||||
self.query("""
|
self.query("""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user