Optimizations to the Nexus schema tests#8271
Conversation
| // Used as a regression test against | ||
| // https://github.com/oxidecomputer/omicron/issues/5561 |
There was a problem hiding this comment.
Full admission, I'm dropping this regression test. It's sorta clinging onto the side of this data migration test, but is actually not validating data migration.
It was originally added in #5565, and moved in #7471 , but it's painful to maintain, because it relies on "finding an enum that has been created, dropped, and re-created with the same name", and then applying all updates to the most recent schema so we can issue diesel commands against it.
This cache has been gone for over a year - I think we can re-visit this if/when we ever add back an OID cache.
|
Noting that the |
Good call, updated the description |
schema/crdb/README.adoc
Outdated
| `NEW_VERSION` and still appears at the top of the list (logically after the | ||
| new version that came in from "main"). | ||
| * Update the version in `dbinit.sql` to match the new `NEW_VERSION`. | ||
| * Re-run `cargo xtask schema generate-previous`. |
There was a problem hiding this comment.
Curious what is supposed to happen (like in CI) if you fail to do this
|
Should we consider just removing old schema versions altogether? I'm imagining something where:
Concretely, say that today:
In this world:
Basically:
I think it's also pretty easy to do mechanically, though probably annoying to automate. |
Sounds totally reasonable to me. I might tweak some of the names and things, but if we're fine dropping old support beyond the past release, this seems like it would clean up a lot, and let us release a lot of the data migration tests too. I'll give this a swing. I think I can modify the existing xtask to handle a lot of the functionality of "check out the base dbinit we want". |
|
Okay, went ahead and implemented this, using |
|
Okay! This PR should be updated. Of note:
All that said, this should be ready for review! |
| // Parse the base schema version from the header | ||
| for line in content.lines() { | ||
| if line.starts_with("-- Schema version:") { | ||
| let version_str = line | ||
| .strip_prefix("-- Schema version:") | ||
| .ok_or_else(|| { | ||
| anyhow::anyhow!("Invalid schema version line format") | ||
| })? | ||
| .trim(); | ||
| return semver::Version::parse(version_str).with_context(|| { | ||
| format!("Failed to parse base schema version: {}", version_str) | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
Nit: this duplicates parse_base_schema_version in dev-tools/schema/src/main.rs. I wonder if there's a reasonable way to have these share code? Possibly not.
There was a problem hiding this comment.
Pulled it into nexus/db-model, since that's a common dependency, and it's a cheap function to compile
There was a problem hiding this comment.
Nice, ok. Wasn't sure offhand if there were any sensible deps in common.
| fn find_workspace_root() -> Result<Utf8PathBuf> { | ||
| let current_dir = | ||
| std::env::current_dir().context("Failed to get current directory")?; | ||
| let current_dir = Utf8PathBuf::try_from(current_dir) | ||
| .context("Current directory path is not valid UTF-8")?; | ||
|
|
||
| current_dir | ||
| .ancestors() | ||
| .find(|p| p.join("Cargo.toml").exists() && p.join(".git").exists()) | ||
| .map(|p| p.to_path_buf()) | ||
| .ok_or_else(|| anyhow::anyhow!("Could not find workspace root")) | ||
| } |
There was a problem hiding this comment.
I think you can use cargo locate-project --workspace here.
dev-tools/schema/src/main.rs
Outdated
| println!( | ||
| " - Update EARLIEST_SUPPORTED_VERSION in schema_versions.rs if needed" | ||
| ); |
There was a problem hiding this comment.
I wonder if we should actually bail here if EARLIEST_SUPPORTED_VERSION != base_version?
| #[allow(dead_code)] | ||
| log: &'a Logger, |
There was a problem hiding this comment.
Did you intend to keep this around? I think it's unused.
schema/crdb/README.adoc
Outdated
| ==== Updating the baseline after a release | ||
|
|
||
| After each Omicron release, update the baseline to match the previous release. | ||
| The "baseline" will become the new "earlist supported CockroachDB schema version", |
|
|
||
| let file_content = String::from_utf8(show_output.stdout)?; | ||
|
|
||
| // Parse the SCHEMA_VERSION from the file |
There was a problem hiding this comment.
This feels a bit fragile, although I can't really imagine a better way to do it. I wonder, if it fails for whatever reason, should we bail rather than returning Ok(None)?
There was a problem hiding this comment.
I can just make get_schema_version_from_commit return a Result<Version>, and have this case be an error.
Updated in 777a605
This PR optimizes several of the Nexus schema tests:
cargo xtask schema generate-basecommand to help pull down this baseline.cargo xtask schema old-migrationsto assist with cleaning up old migrations that are before the "baseline", and are no longer supported.Fixes #10005