Commit graph

195 commits

Author SHA1 Message Date
Jan Bouwhuis
60e3a1fc5f
Fix ruff import validation (#126917) 2024-09-27 15:17:54 +02:00
Erik Montnemery
66ab90b518
Add EntityIDPostMigration data migrator class (#125307) 2024-09-27 14:58:34 +02:00
Erik Montnemery
ba5f1ac2a9
Bump version of recorder context ID data migrators (#125293) 2024-09-24 13:45:37 +02:00
Alberto Montes
b2401bf2e3
Update string formatting to use f-string on components (#125987)
* Update string formatting to use f-string on components

* Update code given review feedback

* Use f-string

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-09-19 11:38:25 +02:00
Erik Montnemery
09989e6184
Fix UnboundLocalError in recorder (#125419) 2024-09-06 17:14:25 +02:00
Erik Montnemery
86ae70780c
Refactor recorder retryable_database_job decorator (#125306) 2024-09-05 13:09:27 +02:00
Erik Montnemery
a8f2204f4f
Teach recorder data migrator base class to update MigrationChanges (#125214)
* Teach recorder data migrator base class to update MigrationChanges

* Bump migration version

* Improve test coverage

* Update migration.py

* Revert migrator version bump

* Remove unneeded change
2024-09-05 08:56:18 +02:00
Erik Montnemery
8fd691be69
Teach recorder data migrator base class to remove index (#125168)
* Teach recorder data migrator base class to remove index

* Fix tests
2024-09-04 09:52:41 +02:00
Erik Montnemery
7fc0e36b2f
Move recorder EntityIDPostMigrationTask to migration (#125136)
* Move recorder EntityIDPostMigrationTask to migration

* Update test
2024-09-04 08:38:46 +02:00
Erik Montnemery
cc3d059783
Refactor recorder EventIDPostMigration data migrator (#125126) 2024-09-03 22:37:50 +02:00
Erik Montnemery
7c223db1d5
Remove recorder PostSchemaMigrationTask (#125076)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-09-03 07:51:27 +02:00
Erik Montnemery
7bb93d4f3e
Deduplicate warning messages in recorder DB migration (#124845) 2024-08-29 19:05:27 -07:00
Erik Montnemery
b9aaba0432
Prevent duplicating constraints during schema migration (#124616) 2024-08-26 08:35:54 -10:00
Erik Montnemery
a7bca9bcea
Use BIGINT SQL type for ID columns (#123973)
Redo recorder ID migration from INT to BIGINT
2024-08-17 11:01:14 +02:00
Erik Montnemery
64a68b17f4
Simplify recorder.migration._drop_foreign_key_constraints (#123968) 2024-08-15 11:58:52 -05:00
Erik Montnemery
f72d9a2c02
Raise on database error in recorder.migration._modify_columns (#123642)
* Raise on database error in recorder.migration._modify_columns

* Improve test coverage
2024-08-15 14:46:23 +02:00
Erik Montnemery
72e235ad9f
Improve some comments in recorder migration code (#123969) 2024-08-15 10:56:56 +02:00
Erik Montnemery
667414a457
Raise on database error in recorder.migration._drop_foreign_key_constraints (#123645)
* Raise on database error in recorder.migration._drop_foreign_key_constraints

* Fix test

* Fix test

* Revert "Fix test"

This reverts commit 940b8cb506e912826d43d09d7697c10888bdf685.

* Update test

* Improve test coverage

* Disable test for SQLite
2024-08-15 08:25:18 +02:00
Erik Montnemery
e6ed3c8c5c
Raise on database error in recorder.migration function (#123644)
* Raise on database error in recorder.migration._update_states_table_with_foreign_key_options

* Improve test coverage

* Fix test

* Fix test
2024-08-14 22:37:23 +02:00
Erik Montnemery
9c4677a3c6
Add comment clarifying recorder migration to schema version 16 (#123902) 2024-08-14 14:22:06 -05:00
Erik Montnemery
e050d187c4
Clarify SQLite can't drop foreign key constraints (#123898) 2024-08-14 07:04:53 -05:00
Erik Montnemery
80f5683cd6
Raise on database error in recorder.migration._add_constraint (#123646)
* Raise on database error in recorder.migration._add_constraint

* Fix test
2024-08-14 13:59:06 +02:00
Erik Montnemery
b7bbc938d3
Drop violating rows before adding foreign constraints in DB schema 44 migration (#123454)
* Drop violating rows before adding foreign constraints

* Don't delete rows with null-references

* Only delete rows when integrityerror is caught

* Move restore of dropped foreign key constraints to a separate migration step

* Use aliases for tables

* Update homeassistant/components/recorder/migration.py

* Update test

* Don't use alias for table we're deleting from, improve test

* Fix MySQL

* Update instead of deleting in case of self references

* Improve log messages

* Batch updates

* Add workaround for unsupported LIMIT in PostgreSQL

* Simplify

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-08-14 09:31:37 +02:00
J. Nick Koston
00c1a3fd4e
Ensure legacy event foreign key is removed from the states table when a previous rebuild failed (#123388)
* Ensure legacy event foreign key is removed from the states table

If the system ran out of disk space removing the FK, it would
fail. #121938 fixed that to try again, however that PR was made
ineffective by #122069 since it will never reach the check.

To solve this, the migration version is incremented to 2, and
the migration is no longer marked as done unless the rebuild
/fk removal is successful.

* fix logic for mysql

* fix test

* asserts

* coverage

* coverage

* narrow test

* fixes

* split tests

* should have skipped

* fixture must be used
2024-08-09 06:19:12 +02:00
Erik Montnemery
ea75c8864f
Remove support for live schema migration of old recorder databases (#122399)
* Remove support for live schema migration of old recorder databases

* Update test
2024-07-29 15:52:18 +02:00
Erik Montnemery
5467685bd8
Adjust warning message when recorder is doing offline migration (#122509)
* Adjust warning message when recorder is doing offline migration

* Address review comments
2024-07-29 11:38:36 +02:00
Erik Montnemery
0c7ab2062f
Avoid creating nested sessions in recorder migration (#122580) 2024-07-25 15:44:48 +02:00
Erik Montnemery
96de0a4c94
Correct off-by-one bug in recorder non live schema migration (#122428)
* Correct off-by-one bug in recorder non live schema migration

* Remove change from the future
2024-07-23 00:30:31 +02:00
Erik Montnemery
20fc5233a1
Add recorder data migrator class to clean up states table (#122069) 2024-07-22 13:04:01 -05:00
Erik Montnemery
b14e8d1609
Remove SchemaValidationStatus.valid (#122394) 2024-07-22 17:33:13 +02:00
Erik Montnemery
e8b88557ee
Refactor recorder schema migration (#122372)
* Refactor recorder schema migration

* Simplify

* Remove unused imports

* Refactor _migrate_schema according to review comments

* Add comment
2024-07-22 16:53:54 +02:00
Erik Montnemery
6921e053e4
Move recorder data migration implementation to migrators (#122045) 2024-07-17 10:59:58 +02:00
Erik Montnemery
9970b7eece
Refactor recorder data migration (#121009)
* Refactor recorder data migration

* Fix stale docstrings

* Don't store a session object in BaseRunTimeMigration instances

* Simplify logic in EntityIDMigration.migration_done

* Fix tests
2024-07-16 21:50:19 +02:00
Erik Montnemery
a22e12dac9
Refactor function recorder.migration._apply_update (#122023)
* Refactor function recorder.migration._apply_update

* Remove _SchemaVersionMigrators dict
2024-07-16 20:28:03 +02:00
Erik Montnemery
d8440e809a
Avoid mutating database schema definitions during schema migration (#122012)
* Avoid mutating database schema definitions during schema migration

* Adjust test when using mysql

* Address review comment
2024-07-16 20:27:49 +02:00
Erik Montnemery
dbe68ca057
Minor adjustment of recorder migration (#122020) 2024-07-16 14:20:23 +02:00
J. Nick Koston
ebd50d327b
Log add/remove index complete at the same level as when it starts (#121852) 2024-07-12 15:54:38 +02:00
Erik Montnemery
6eeb70151d
Use BIGINT SQL type for ID columns (#121025) 2024-07-05 10:42:39 -05:00
Erik Montnemery
5b39989869
Fix typo in post_schema_migration (#121017) 2024-07-02 15:52:54 +02:00
J. Nick Koston
c5804d362c
Remove legacy foreign key constraint from sqlite states table (#120779) 2024-06-29 07:50:53 -05:00
Sid
2cc916db6d
Replace pylint broad-except with Ruff BLE001 (#116250) 2024-05-07 14:00:27 +02:00
Sid
3799d20d43
Enable Ruff B905 (#114197) 2024-04-14 00:14:26 -05:00
Sid
6587ee20db
Enable Ruff TRY300 (#114437)
* Enable Ruff TRY300

* Update validation.py

* Address review comments
2024-03-30 10:37:59 +01:00
Sid
a5b609f081
Enable ruff TRY401 (#114395)
* Enable ruff TRY401

* fix tests
2024-03-29 07:20:36 +01:00
Erik Montnemery
a3059fe504
Record state.last_reported (#114201)
* Record state.last_reported

* Include last_reported in parts of the history API

* Use a bulk update

* fix refactoring error

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-27 12:48:06 +01:00
Joost Lekkerkerker
6bb4e7d62c
Bump ruff to 0.3.4 (#112690)
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
J. Nick Koston
68e170284f
Speed up recorder startup by making schema query read only (#113987) 2024-03-22 18:29:46 +01:00
J. Nick Koston
06f356a038
Avoid expensive db queries at startup to check if data is migrated (#113773) 2024-03-19 15:27:40 -10:00
Joost Lekkerkerker
05172d8e4d
Improve loops and lists (#113269)
* Enable PERF

* Enable PERF rule

* Enable PERF rule

* Don't enable flag yet
2024-03-14 10:22:20 +01:00
Joost Lekkerkerker
77917506bb
Improve lists in integrations [R-S] (#113233)
* Improve lists in integrations [R-S]

* Fix

* Fix
2024-03-13 21:55:00 +01:00