Move log and history files to $XDG_STATE_HOME#1571
Open
jrraymond wants to merge 1 commit intodbcli:mainfrom
Open
Move log and history files to $XDG_STATE_HOME#1571jrraymond wants to merge 1 commit intodbcli:mainfrom
jrraymond wants to merge 1 commit intodbcli:mainfrom
Conversation
Log and history are state files (persist across restarts, not user-configuration), so they belong in \$XDG_STATE_HOME (~/.local/state/pgcli/) rather than \$XDG_CONFIG_HOME (~/.config/pgcli/). On first launch after upgrade, existing files at the old location are silently migrated to the new location. Errors during migration are logged rather than raised. Fixes dbcli#1497 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1497.
Summary
Per the XDG Base Directory Specification,
$XDG_STATE_HOME(default~/.local/state) is the correct location for state data that persists across restarts but is not user-configuration. Log and history fit this definition; config and casing remain in$XDG_CONFIG_HOME.state_location()toconfig.py, mirroringconfig_location()but using$XDG_STATE_HOME(defaults to~/.local/state/pgcli/). On Windows, returns the same path asconfig_location()since there is no XDG equivalent.migrate_file(old, new)helper that silently moves a file from the old location to the new one on first launch after upgrade. Errors are logged rather than raised.initialize_logging()andrun_cli()now usestate_location()for the default log and history paths, and callmigrate_file()to handle the one-time upgrade migration.pgclirc.state_location()and all migration cases (old only, both exist, old missing, error logged on failure).Testing
Checklist
changelog.rst.AUTHORSfile (or it's already there).pip install pre-commit && pre-commit install).🤖 Generated with Claude Code