Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db schema changed on upgrade without noticeable warning, world of pain to downgrade #995

Open
obadz opened this issue Jul 23, 2016 · 5 comments
Assignees
Labels

Comments

@obadz
Copy link

obadz commented Jul 23, 2016

While working with @shlevy on #994, I accidentally upgraded my db schema from version 7 to 9.

I looked at the changes which added a couple columns and deleted a table. I tried to revert via sql statements but got tangled in the triggers.

In the end, I was able to get back to a stable state via:

$ nix-store --dump-db > db.txt
$ mv -v /nix/var/nix/db /nix/var/nix/db.old
$ nix-store --load-db < db.txt

(I suspect someone going through the same issues without doing the failed SQL wizardry might have to dump the db using nix-store from the newer version, and reload it using nix-store from the older version)

I would suggest:

  1. That there be an appropriate warning and user acknowledgment when the db is irreversibly upgraded
  2. That the above procedure be documented somewhere
@basvandijk
Copy link
Member

I also just ran into this problem. I was able to resolve it by removing /nix/var/nix/db and running nixops deploy again which recreates the nix db.

@dtzWill
Copy link
Member

dtzWill commented Feb 12, 2017

Just ran into this problem today, and just wanted to thank you for this and share a bit of what was needed to resolve my schema version problems.
In my particular case, I had nixUnstable in my profile and somehow managed to upgrade the system schema to '10' which is too new for my 16.09 system.

Here's what I ended up doing, written up after the fact but in hopes it helps someone in the future:

  • Stop nix-daemon
    $ sudo systemctl stop nix-daemon
    $ sudo systemctl stop nix-daemon.socket

  • Use 'new' Nix from my profile to dump the current DB:
    $ NIX_REMOTE= sudo -E nix-store --dump-db > db.txt
    (EDIT: it might not be necessary to clear NIX_REMOTE; @LnL7 points out the nix-daemon isn't used when invoked by root)

  • Move current db to the side:
    $ sudo su
    # mv /nix/var/nix/db /nix/var/nix/db.old

  • Import the saved DB using the "old" Nix
    # nix-store --load-db < db.txt

  • Remove the new Nix from my profile so it won't cause problems again
    # nix-env -p /nix/var/nix/profiles/per-user/will/profile -e nix

  • Start the nix-daemon again, all should be well:
    # systemctl start nix-daemon.socket

@LnL7
Copy link
Member

LnL7 commented Feb 12, 2017

The NIX_REMOTE environment variable is only set when the db is not writable for the user. https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/nix-daemon.nix#L406-L408

@stale
Copy link

stale bot commented Feb 15, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 15, 2021
@stale
Copy link

stale bot commented May 2, 2022

I closed this issue due to inactivity. → More info

@stale stale bot closed this as completed May 2, 2022
@thufschmitt thufschmitt reopened this Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants