Updates script to write all preferences to store#11668
Updates script to write all preferences to store#11668mekarpeles merged 2 commits intointernetarchive:masterfrom
store#11668Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
This PR adds a --legacy flag to the preference migration script that allows writing all remaining preferences from the thing table to the store table, rather than just a subset based on specific criteria.
- Introduces new
_fetch_legacy_preference_keys()function to query all preferences inthingtable not yet instore - Adds
--legacycommand-line flag to switch between the two migration modes - Updates documentation to reflect the new functionality
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| scripts/migrations/write_prefs_to_store.py | Adds new _fetch_legacy_preference_keys() function and --legacy argument to enable migration of all preferences |
| scripts/migrations/README.md | Updates description to document the --legacy flag functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| keys = [] | ||
| try: | ||
| legacy_preference_entries = oldb.query(legacy_key_query) | ||
| keys = [entry.get('key', '') for entry in list(legacy_preference_entries)] | ||
| except DatabaseError as e: | ||
| print(f"An error occurred while fetching preference keys: {e}") |
There was a problem hiding this comment.
The new function lacks transaction handling that exists in the original _fetch_preference_keys() function. The original function creates a transaction with t = oldb.transaction() and performs a rollback in both the error case and the success case. This transaction pattern should be replicated here for consistency and to ensure proper database resource management.
| keys = [] | |
| try: | |
| legacy_preference_entries = oldb.query(legacy_key_query) | |
| keys = [entry.get('key', '') for entry in list(legacy_preference_entries)] | |
| except DatabaseError as e: | |
| print(f"An error occurred while fetching preference keys: {e}") | |
| keys = [] | |
| t = None | |
| try: | |
| t = oldb.transaction() | |
| legacy_preference_entries = oldb.query(legacy_key_query) | |
| keys = [entry.get('key', '') for entry in list(legacy_preference_entries)] | |
| except DatabaseError as e: | |
| if t is not None: | |
| t.rollback() | |
| print(f"An error occurred while fetching preference keys: {e}") | |
| else: | |
| if t is not None: | |
| t.rollback() |
There was a problem hiding this comment.
The transaction in the other function was added to support the use of a temporary table. Rolling back that transaction cleans up the temporary table.
Also, I'm not exactly sure what benefit could be had by rolling back the single SELECT query that is executed in this function......
…nce-migration-script Updates script to write all preferences to `store`
…nce-migration-script Updates script to write all preferences to `store`
Advances #11009
Adds
--legacyflag to the preference migration script. When--legacyis true, all remaining preferences in thethingtable will be written to thestore.Technical
Testing
Screenshot
Stakeholders