Support fine-grained database schema migrations#11668
Support fine-grained database schema migrations#11668Ericson2314 merged 1 commit intoNixOS:masterfrom
Conversation
3865587 to
79b1708
Compare
|
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 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.) |
|
Great that's my main road block to deploy this by default on a larger amount of machines |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
5e27a7c to
517e5da
Compare
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.
517e5da to
27ea437
Compare
bryanhonof
left a comment
There was a problem hiding this comment.
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. |
|
I don't yet fully understand the full lifecycle here. For example:
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 |
|
@Mic92 Agreed. my understanding is this fine-grained approach assumes each named migration is independent of any other. It works for |
Well assuming we don't go crazy with experimental features, we should be able to test all combinations of migrations. |
|
|
||
| std::set<std::string> schemaMigrations; | ||
|
|
||
| { |
There was a problem hiding this comment.
| { | |
| // Load all the names of the migrations we have already done | |
| { |
| schemaMigrations.insert(useQuerySchemaMigrations.getStr(0)); | ||
| } | ||
|
|
||
| auto doUpgrade = [&](const std::string & migrationName, const std::string & stmt) |
There was a problem hiding this comment.
| auto doUpgrade = [&](const std::string & migrationName, const std::string & stmt) | |
| // Do a migration if it is not already done. | |
| auto doUpgrade = [&](const std::string & migrationName, const std::string & stmt) |
| static int getSchema(Path schemaPath) | ||
| { | ||
| int curSchema = 0; | ||
| if (pathExists(schemaPath)) { | ||
| auto s = readFile(schemaPath); | ||
| auto n = string2Int<int>(s); | ||
| if (!n) | ||
| throw Error("'%1%' is corrupt", schemaPath); | ||
| curSchema = *n; | ||
| } | ||
| return curSchema; | ||
| } |
There was a problem hiding this comment.
N.B. this was just inlined.
Ericson2314
left a comment
There was a problem hiding this comment.
Whoops I was thinking this was more advanced than it was (but less advanced than it need to be).
I see right now it's just memoization of schemas, and the logic of what to migrate (including dependencies) is out of scope. That's fine!
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
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 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.