Switch to SQLAlchemy for the Recorder component. Gives the ability t…#2377
Conversation
| return [] | ||
|
|
||
|
|
||
| def row_to_state(row): |
There was a problem hiding this comment.
Should these be moved to be (a static) methods on the models?
There was a problem hiding this comment.
Probably should do so. I wasn't ever very happy with these, but they mimic the old structure. Now's the time to clean up though.
There was a problem hiding this comment.
In the end, I decided to refactor this to rely on model methods to convert to native form and an execution helper.
|
This is awesome! I've only had a few minor comments. |
| if not db_url: | ||
| db_url = DEFAULT_URL.format( | ||
| hass_config_path=hass.config.path(DEFAULT_DB_FILE)) | ||
|
|
There was a problem hiding this comment.
This comment is not perse related to this place in the code but GitHub otherwise has no threaded conversations.
One problem we have with current conversion script is that the script directory is not shipped to pypi. I think it would make sense if we create a new package homeassistant.scripts that contains scripts we want to bundle with HA or just put it in the recorder package for now.
I wonder if we would want to do the migration automatically. Should we add here something like this:
import sys
from subprocess import check_output
from homeassistant.components.recorder import convert_db_to_sqlalchemy
old_path = hass.config.path('home-assistant.db')
if os.path.isfile(old_path):
check_output([sys.executable, convert_db_to_sqlalchemy.__file__, hass.config.config_dir, db_url])
os.remove(old_path)There was a problem hiding this comment.
Running the migration automatically could take a very long time, may run us out of disk space, or may wear out SD cards. We could migrate the current day's data automatically, though?
With regards to moving the script into homeassistant.scripts, that's easy and lets us adapt the conversion script for automation if needed.
There was a problem hiding this comment.
I moved the script as suggested.
| homeassistant/components/upnp.py | ||
| homeassistant/components/zeroconf.py | ||
|
|
||
| homeassistant/scripts/*.py |
There was a problem hiding this comment.
Can you move this to be under the line __main__
|
How do we supply username and password for mysql? I tried this and didn't get any errors but the db is still empty: recorder:
db_url: mysql://192.168.1.50/homeassistant?user=root&password=pw |
|
Search for sql alchemy connection string.. We should make sure we have On Thu, Jul 14, 2016, 07:58 Nolan Gilley notifications@github.com wrote:
|
|
Try this: |
|
@rhooper you think we should auto install support package based on database If protocol == MySQL, install mysqlclient etc On Thu, Jul 14, 2016, 09:10 rhooper notifications@github.com wrote:
|
|
If that's easy to implement, yes. Otherwise we'll have a lot of confused users. |
|
This commit contains a couple of |
|
I don't have time for this but these snippets should help: >>> from urllib.parse import urlparse
>>> urlparse('postgresql://scott:tiger@SERVER_IP/DB_NAME')
ParseResult(scheme='postgresql', netloc='scott:tiger@SERVER_IP', path='/DB_NAME', params='', query='', fragment='')import homeassistant.util.package as pkg_util
pkg_util.install_package('mysqlclient', target=hass.config.path('deps')) |
Description: Adds SQLAlchemy support.
Major change: This now uses homeassistant2.db as the default DB because of shift in data types for timestamps.
Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code does not interact with devices:
toxrun successfully. Your PR cannot be merged unless tests pass