ltss icon indicating copy to clipboard operation
ltss copied to clipboard

migrate existing recorder Database into ltss

Open manonfgoo opened this issue 1 year ago • 4 comments

Hello, it there any simple way to migrate existing recorder Database Data into the ltss table ?

Kind regards

manonfgoo avatar Apr 24 '23 21:04 manonfgoo

Hi @manonfgoo and thanks for the questions.

There exists no ready-made script for migration to the ltss table as far as I know. The way to do that will also depend on what backend you are currently running the recorder with, i.e. sqlite, postgresql, mysql, or mariadb.

freol35241 avatar Apr 26 '23 18:04 freol35241

I am using portgresql

From: freol35241 @.> Reply to: freol35241/ltss @.> Date: Wednesday, 26. April 2023 at 20:59 To: freol35241/ltss @.> Cc: manonfgoo @.>, Mention @.***> Subject: Re: [freol35241/ltss] migrate existing recorder Database into ltss (Issue #78)

Hi @manonfgoohttps://github.com/manonfgoo and thanks for the questions.

There exists no ready-made script for migration to the ltss table as far as I know. The way to do that will also depend on what backend you are currently running the recorder with, i.e. sqlite, postgresql, mysql, or mariadb.

— Reply to this email directly, view it on GitHubhttps://github.com/freol35241/ltss/issues/78#issuecomment-1523902926, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABTP25F4FDWZC32YHSCAKELXDFWBPANCNFSM6AAAAAAXKD2D7U. You are receiving this because you were mentioned.Message ID: @.***>

manonfgoo avatar Apr 26 '23 19:04 manonfgoo

I will leave this issue open and happily accept contributions for scripts that perform these kind of migrations.

freol35241 avatar May 17 '23 17:05 freol35241

For postgres, you can do the following:

insert into ltss
select to_timestamp(last_updated_ts) time, states_meta.entity_id, state, shared_attrs::json attributes
from states, states_meta, state_attributes
where states.metadata_id = states_meta.metadata_id and states.attributes_id = state_attributes.attributes_id
    and states_meta.entity_id like 'sensor.%'
on conflict do nothing;

Note that you can optionally limit the entity_id to sensor.% to match your include/exclude list.

Bouke avatar May 27 '24 17:05 Bouke