Skip to content

CLI: back up cli.db on upgrade and add a command to undo an upgrade #1623

Closed

Description

@sentry-junior

Follow-up from #1612, suggested by @BYK in review.

Problem

Older CLIs only migrate cli.db forward. When a user moves from a newer CLI back to an older one (for example nightly → stable with sentry cli upgrade stable), the older CLI finds a database it can't read (#1611). #1612 handles this by having the newer CLI reset the database before the older one runs: it clears cache tables and stored accounts and sets the schema version back to 16. That works, but the user has to log in again, and every migration after v16 has to be safe to re-run.

Proposal

Restore a saved copy instead of reverting the database in code:

  • Before sentry cli upgrade installs a different version, copy cli.db to a backup and record the version being replaced.
  • Add a command, such as sentry cli upgrade undo or sentry cli revert, that reinstalls the recorded version and restores the backed-up database.

The user goes back to the exact database the older CLI last used, login included, and newer CLIs don't need to know older schemas.

Open questions

  • Stale data: logins or token refreshes made on the newer version are lost when the backup is restored. Should we warn, or merge accounts back in?
  • Retention: keep only the most recent backup, or one per version?
  • Other install methods: what about downgrades that don't go through cli upgrade, like npm or brew pinning? Those still need the newer-schema handling from fix(cli): Keep the local database usable across CLI downgrades #1612.
  • Secrets: backups contain refresh tokens, so they need the same file permissions as cli.db.

via BYK.

--

View Junior Session [Sentry]

Activity

  1. linear-code commented on Oct 23, 2026

    @linear-code
  2. BYK commented on Oct 23, 2026

    @BYK
    Member

    Stale data: logins or token refreshes made on the newer version are lost when the backup is restored. Should we warn, or merge accounts back in?

    Merge when possible, warn at least.

    Retention: keep only the most recent backup, or one per version?

    One per version

    Other install methods: what about downgrades that don't go through cli upgrade, like npm or brew pinning? Those still need the newer-schema handling from #1612.

    Yes. Warn if we can but it's up to the users at that point. We can try pre/post install scripts etc but they are normally blocked now for security (rightly so)

    Secrets: backups contain refresh tokens, so they need the same file permissions as cli.db.

    Sounds good? Don't see a question here?

  3. added a commit that references this issue on Oct 27, 2026
    520eeb6
  4. added a commit that references this issue on Oct 27, 2026
    d2a66ee
  5. added a commit that references this issue on Oct 27, 2026
    0315e47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions