nix icon indicating copy to clipboard operation
nix copied to clipboard

Support fine-grained database schema migrations

Open edolstra opened this issue 1 year ago • 3 comments

Motivation

Backward-compatible schema changes (e.g. those that add tables or nullable columns) now no longer need a change to the global schema file (/nix/var/nix/db/schema). Thus, old Nix versions can continue to access the database.

This is especially useful for schema changes required by experimental features. In particular, it replaces the ad-hoc handling of the schema changes for CA derivations (i.e. the file /nix/var/nix/db/ca-schema).

Schema versions 8 and 10 could have been handled by this mechanism in a backward-compatible way as well.

Context

Priorities and Process

Add :+1: to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

edolstra avatar Oct 10 '24 15:10 edolstra

Does this also help with the deadlock that are seeing when enabling ca derivations? Currently it requires a reboot of the machine because existing running nix processes will not allow the schema migration from happening as they hold the global lock file.

Mic92 avatar Oct 15 '24 20:10 Mic92

@Mic92 It should help with the deadlock since it doesn't hold the global lock anymore while doing SQLite schema migrations. (Maybe it should, but AFAIK SQLite doesn't need it.)

edolstra avatar Oct 16 '24 15:10 edolstra

Great that's my main road block to deploy this by default on a larger amount of machines

Mic92 avatar Oct 16 '24 17:10 Mic92

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-10-16-nix-team-meeting-minutes-187/54835/1

nixos-discourse avatar Oct 24 '24 09:10 nixos-discourse

To me, this looks good. Haven't tested it out though, also not sure how one might test this.

On a system without ca-derivations, enable ca-derivations and see if they work.

Mic92 avatar Nov 06 '24 05:11 Mic92

I don't yet fully understand the full lifecycle here.

For example:

  1. What does one do if they need to make a "breaking" change to the CA schema while its experimental? It is non-breaking from the non-experimental status quo, but breaking from the last CA change.

  2. What does one do if CA derivations is merged (not experimental) and then we make some sort of cross-cutting breaking change?

I think what this change is doing is grafting on a powerset of feature names in top of the last breaking migration, but I don't think that is sufficient to make this sustainable.

Ericson2314 avatar Nov 18 '24 01:11 Ericson2314

I don't yet fully understand the full lifecycle here.

For example:

1. What does one do if they need to make a "breaking" change to the CA schema while its experimental? It is non-breaking from the non-experimental status quo, but breaking from the last CA change.

2. What does one do if CA derivations is merged (not experimental) and then we make some sort of cross-cutting breaking change?

I think what this change is doing is grafting on a powerset of feature names in top of the last breaking migration, but I don't think that is sufficient to make this sustainable.

We should not break the schema, experimental or not. We would append a migration after 20220326-ca-derivations if we need to update it. And when we remove the experimental feature status we will remove the if statement and apply this migration unconditionally. If we drop the feature, we would just ignore those extra columns that some nix installations might have in their database. Of course we need to make sure that we don't have different experimental features that introduce conflicting schemas, but we need to make sure this doesn't happen in any case.

Mic92 avatar Nov 19 '24 15:11 Mic92

@Mic92 Agreed. my understanding is this fine-grained approach assumes each named migration is independent of any other. It works for 2^n schemas freely generated by n non-conflicted migrations, but breaks down for when the partial order is not such a free semi-lattice (power set).

Ericson2314 avatar Nov 19 '24 19:11 Ericson2314

@Mic92 Agreed. my understanding is this fine-grained approach assumes each named migration is independent of any other. It works for 2^n schemas freely generated by n non-conflicted migrations, but breaks down for when the partial order is not such a free semi-lattice (power set).

Well assuming we don't go crazy with experimental features, we should be able to test all combinations of migrations.

Mic92 avatar Nov 20 '24 18:11 Mic92

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-11-20-nix-team-meeting-minutes-196/56688/1

nixos-discourse avatar Nov 27 '24 20:11 nixos-discourse