Repository navigation
feat(database): add --seed-snapshot and --reset-database, rename 'initializer' to 'seed', fixes #8661, fixes #8322 - #8705
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
0fd3d9f to
7ff75d7
Compare
…ed as a YAML comment [skip ci] The do-nothing placeholder workflows added in ddev#8706 are currently failing on every PR that touches `containers/**` (e.g. ddev#8705), because their unquoted `name:`/`run:` strings contain `ddev#8609`, and YAML treats a space followed by `#` as a comment start even mid-string - truncating both values and leaving `run:` with an unterminated quote. - Fixes CI breakage introduced by ddev#8706, related to ddev#8609 `name: Placeholder (see ddev#8609)` parses as `Placeholder (see`, and `run: echo "Placeholder for ddev#8609 ..."` parses as `echo "Placeholder for` - invalid bash (`unexpected EOF while looking for matching "`), failing the "Image build"/"Image push" placeholder job on every containers/-touching PR since ddev#8706 merged. Quotes the `name:` values and switches the `run:` values to block scalars (`run: |`), which aren't subject to inline comment stripping. Verified both files' `ddev#8609` strings now parse intact and the `run` command executes cleanly. Scanned all other workflow files for the same pattern; found nothing else affected. Open (or re-run) a PR touching `containers/**` and confirm the "Image build" placeholder job now passes. Verified via `python3 -c "import yaml; ..."` that both files' `name`/`run` values now parse to their full intended strings, and ran the resulting `run` command through bash directly to confirm it executes without error. No new tests needed for a two-file YAML quoting fix. Fixes an active CI failure on `main` affecting every PR that touches `containers/**`. No other workflow changes. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WqmDPsdWxQjwGu3LFNzGLg
d008d99 to
bd66bf4
Compare
|
Pushed updated container image(s) for this PR:
|
bd66bf4 to
df7fa39
Compare
#8609 ## Short Summary (TL;DR) quickstart.yml, perf-start-time.yml, perf-linux.yml, and the Windows installer test each build or start ddev without waiting for image-push.yml's async push, so they can race a content-tagged image that hasn't landed on Docker Hub yet. Add the same containers/wait-for-images.sh step that test-reusable.yml, test-wsl2-reusable.yml, and the Buildkite test.sh/perf.sh legs already use. ## The Issue - Fixes #8609 #8707 added content-hash image tags built and pushed asynchronously by image-push.yml, and added a wait-for-images.sh step to test-reusable.yml and wsl2-test.sh to avoid racing that push. It missed quickstart.yml, perf-start-time.yml, perf-linux.yml, and the Windows installer pipeline. PR #8705's perf-start-time run failed with `ddev-dbserver-mariadb-11.8:...: not found`, and two quickstart runs on PRs rebased past the same commit failed identically inside `ddev start` for `dummy-project` (output swallowed by `>/dev/null 2>&1`, so it just looked like a bare `Error 1`). ## How This PR Solves The Issue Adds a `Wait for pushed images` step (`containers/wait-for-images.sh`) to quickstart.yml, perf-start-time.yml, and perf-linux.yml, and the equivalent inline call to installer-test.sh, all placed the same way as the existing callers: after public-variables/DOCKER_ORG is available, before anything that pulls or builds a DDEV image. Audited every other GitHub Actions workflow and Buildkite pipeline: the rest either route through test-reusable.yml/test-wsl2-reusable.yml/test.sh/perf.sh (already covered) or never pull a pre-built image tag (cross-compile jobs, the image-build/push jobs themselves, docs/lint jobs). ## Manual Testing Instructions - `actionlint .github/workflows/quickstart.yml .github/workflows/perf-start-time.yml .github/workflows/perf-linux.yml` - no new findings (one pre-existing shellcheck warning in quickstart.yml predates this change). - `bash -n .buildkite/installer-test.sh` - syntax OK. - Re-run the quickstart and perf-start-time workflows on a PR rebased past an image-only commit; both should now block on wait-for-images.sh instead of failing with an image-not-found error. ## Automated Testing Overview No new tests - this only reorders CI steps to reuse the existing, already-tested containers/wait-for-images.sh script. ## Release/Deployment Notes CI-only change. Adds up to ~20 minutes of wait time (only when a relevant image actually changed and hasn't finished pushing yet; fast path is a single registry check per image otherwise).
PR #8705's apache-fpm/docker-rootless/nginx-fpm/no-bind-mounts/podman-rootless/ race-detection checks all failed waiting for ddev-dbserver-mysql-9.7:71f82087a2 and gave up at the 20-minute default. The actual push completed 2 minutes later at 05:22:38, and the approval itself was prompt (~1 minute after the build finished) - the time was consumed by image-build-push.yml's own build fan-out (~17 minutes) plus the push of a large image (~2.5 minutes). A 20-minute budget left effectively no margin for the normal case, let alone a slower approval. Bumped WAIT_FOR_IMAGES_ATTEMPTS' default from 40 to 80 (still 30s apart), and quickstart.yml's job timeout-minutes from 90 to 150 to give the now-longer wait step room without crowding out the quickstart-test suite that follows it (that suite alone can already run 60-90 minutes). Confirmed wait_for_images_test.sh sets WAIT_FOR_IMAGES_ATTEMPTS/_SLEEP explicitly in every case, so the new default doesn't slow down the test suite. make staticrequired is clean. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…B type mismatch, for ddev#8705 After `ddev config --database=<type>` changes the configured database type/version away from what the existing volume actually holds, `ddev start --reset-database` needs to snapshot the volume using its real type before removing it, not the newly configured one. Reading SnapshotAtExistingDBVersion showed this already handled correctly, but no test exercised the exact path. This closes that verification gap; no production code changed.
… outside the project, for ddev#8705 `ddev start --seed-snapshot` already accepted either a bare snapshot name or a path to a snapshot file elsewhere on the host, bind-mounting it into the db container for that start. `ddev snapshot restore` never got the same treatment - it only accepted a bare name resolved inside .ddev/db_snapshots, so passing a path just failed to find the file. Extracted the path-vs-name resolution shared by both commands into resolveSnapshotSource(), and let RestoreSnapshot() request the same /mnt/seed bind mount Start() already sets up for a fresh-volume seed, via a new unexported DdevApp field so it applies without re-triggering seed handling on a restore. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…, for ddev#8705 A shell only expands a leading `~` for a bare argument, not inside a `--flag=value` word, so `--seed-snapshot=~/dataset-mariadb_11.8.zst` reached DDEV with the `~` literal and failed to resolve. resolveSnapshotSource() now expands it via the existing util.ExpandHomedir(), already used the same way for import-db/import-files asset paths, covering both --seed-snapshot and `ddev snapshot restore` since they share that resolver. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…B type mismatch, for ddev#8705 After `ddev config --database=<type>` changes the configured database type/version away from what the existing volume actually holds, `ddev start --reset-database` needs to snapshot the volume using its real type before removing it, not the newly configured one. Reading SnapshotAtExistingDBVersion showed this already handled correctly, but no test exercised the exact path. This closes that verification gap; no production code changed.
… outside the project, for ddev#8705 `ddev start --seed-snapshot` already accepted either a bare snapshot name or a path to a snapshot file elsewhere on the host, bind-mounting it into the db container for that start. `ddev snapshot restore` never got the same treatment - it only accepted a bare name resolved inside .ddev/db_snapshots, so passing a path just failed to find the file. Extracted the path-vs-name resolution shared by both commands into resolveSnapshotSource(), and let RestoreSnapshot() request the same /mnt/seed bind mount Start() already sets up for a fresh-volume seed, via a new unexported DdevApp field so it applies without re-triggering seed handling on a restore. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…, for ddev#8705 A shell only expands a leading `~` for a bare argument, not inside a `--flag=value` word, so `--seed-snapshot=~/dataset-mariadb_11.8.zst` reached DDEV with the `~` literal and failed to resolve. resolveSnapshotSource() now expands it via the existing util.ExpandHomedir(), already used the same way for import-db/import-files asset paths, covering both --seed-snapshot and `ddev snapshot restore` since they share that resolver. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…lde, for ddev#8705 The no-bind-mounts CI job sets globalconfig.DdevGlobalConfig.NoBindMounts to true for the whole package, under which resolveSnapshotSource() intentionally returns an empty mountDir. The test asserted mountDir unconditionally equaled the outside directory, so it failed under that job. TestResolveSeedSnapshot already handles this by pinning the flag for the duration of the test; do the same here. Co-Authored-By: Claude Sonnet 5 <[email protected]>
8541a1a to
3f063dd
Compare
|
This all seems to work ok and is pretty simple in general, although it touches a few places. |
|
I compared this with my pending PR which uses a seed DB. This works well with it and simplifies my pulldb and resetdb wrapper commands. Minor findings below. Feel free to ignore.
|
0a51d75 to
fc42c0c
Compare
…lde, for ddev#8705 The no-bind-mounts CI job sets globalconfig.DdevGlobalConfig.NoBindMounts to true for the whole package, under which resolveSnapshotSource() intentionally returns an empty mountDir. The test asserted mountDir unconditionally equaled the outside directory, so it failed under that job. TestResolveSeedSnapshot already handles this by pinning the flag for the duration of the test; do the same here. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…tializer' to 'seed', fixes ddev#8661, fixes ddev#8322 Renames the reserved seed snapshot from `initializer` to `seed` and adds `ddev start/restart --seed-snapshot` to seed a brand-new database volume from any snapshot, plus `--reset-database` to throw an existing database away and start over — which is what ddev#8322 asks for, PostgreSQL included. - Fixes ddev#8661 - Fixes ddev#8322 The seed mechanism added in ddev#8608 was keyed on one magic filename, `initializer-<type>_<version>.*`, with no way to name a different snapshot and no PostgreSQL support. Separately, there was no way to say "wipe the database and start over" when `ddev start` refuses because the volume was created by a different database server: the error pointed at `ddev utility migrate-database`, which only converts between MariaDB and MySQL. `ddev delete` was no escape hatch either — it started the project to take its pre-delete snapshot and hit the same refusal, so it aborted unless given `-O`. Seeding now goes through the db container's existing `restore_snapshot` command rather than a filename the entrypoint looks up, so one code path serves the reserved name, the explicit flag, and every database type: - `seed` is the reserved snapshot name, picked up automatically on a fresh database volume, and it now works for PostgreSQL too. - `--seed-snapshot=<name-or-path>` names another snapshot for one start. A path outside the project is bind-mounted into the db container, so nothing multi-GB gets copied; the entrypoint learned to accept an absolute path for that, and its `/mnt/snapshots/initializer-*` tier is gone. - Seeding a volume that already has a database is an error naming the way forward, not a silent no-op. `--reset-database` removes the database volume, snapshotting it first unless `-O`. The snapshot is taken with the database version actually in the volume, which is what makes it work after a `database:` change — `Stop()` uses the same helper, so `ddev delete` stops aborting on a mismatched project. `ddev snapshot restore --force` allows a snapshot from a different version of the same database server; a cross-type restore is still refused. `ddev config --database=` now warns rather than failing, since writing config.yaml destroys nothing and `ddev start` still refuses until it's resolved; without that, there was no way to reach `--reset-database` short of hand-editing config.yaml. Also fixes the PostgreSQL restore command, which chmodded its data directory before creating it — unreachable before, since only a populated volume could be restored into, but fatal when seeding a brand-new PostgreSQL 18+ volume. ```bash mkdir ~/tmp/seedtest && cd ~/tmp/seedtest && ddev config --project-type=php ddev start echo "CREATE TABLE marker (id INT);" | ddev mysql db ddev snapshot --name=seed ddev start --reset-database -O -y echo "SHOW TABLES;" | ddev mysql db ddev snapshot --name=other ddev start --reset-database -O --seed-snapshot=other -y mv .ddev/db_snapshots/other-mariadb_11.8.zst ~/tmp/ ddev start --reset-database -O --seed-snapshot=~/tmp/other-mariadb_11.8.zst -y ddev config --database=postgres:17 # warns ddev start # refuses, naming both ways out ddev start --reset-database -y # snapshots as mariadb_11.8, then starts pg17 ``` - `TestResolveSeedSnapshot`, `TestGetSeedSnapshotFile`, `TestSnapshotDBVersionFromFilename`, `TestSnapshotRestoreContainerCommand`: unit coverage of flag resolution, version matching, and the container command, including the PostgreSQL 18+ mkdir. - `TestCmdStartResetDatabase`, `TestCmdStartSeedSnapshotFile`: reset with and without a seed, an out-of-project seed file, and the refused flag combinations. - `TestDdevAllDatabases` now seeds from both the reserved name and an explicit one, for every supported database version. - `base_db_seed.bats` covers `restore_snapshot` seeding an empty datadir from both a `/mnt/snapshots` name and an absolute path. Verified by hand against MariaDB 11.8, PostgreSQL 17, and PostgreSQL 18, including the cross-type reset and `ddev delete` on a mismatched project. `initializer` snapshots are not recognized any more; rename the file to `seed-<type>_<version>.<ext>`. The name only ever existed in main, never in a release, so nothing shipped depends on it — but this has to land before v1.25.4 for that to stay true. Needs a ddev-dbserver image push: the entrypoint accepts an absolute `restore_snapshot` path, which `--seed-snapshot` with an out-of-project file depends on.
aspell doesn't know "restorable", which failed the docs check.
…h no_bind_mounts, for ddev#8661 With no_bind_mounts the db container sees /mnt/snapshots as a Docker volume rather than .ddev/db_snapshots, so a seed snapshot living in the project was never visible to it and the container exited with "does not exist, not attempting restore of snapshot". Only an out-of-project snapshot was copied in. prepareSeedSnapshot() now copies whatever the seed is, and ResolveSeedSnapshot() stops asking for a mount that no_bind_mounts would not provide. The copy moves to after the snapshots volume is created, where the removed `initializer` block used to be, so the volume keeps its compose project label. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…B type mismatch, for ddev#8705 After `ddev config --database=<type>` changes the configured database type/version away from what the existing volume actually holds, `ddev start --reset-database` needs to snapshot the volume using its real type before removing it, not the newly configured one. Reading SnapshotAtExistingDBVersion showed this already handled correctly, but no test exercised the exact path. This closes that verification gap; no production code changed.
… outside the project, for ddev#8705 `ddev start --seed-snapshot` already accepted either a bare snapshot name or a path to a snapshot file elsewhere on the host, bind-mounting it into the db container for that start. `ddev snapshot restore` never got the same treatment - it only accepted a bare name resolved inside .ddev/db_snapshots, so passing a path just failed to find the file. Extracted the path-vs-name resolution shared by both commands into resolveSnapshotSource(), and let RestoreSnapshot() request the same /mnt/seed bind mount Start() already sets up for a fresh-volume seed, via a new unexported DdevApp field so it applies without re-triggering seed handling on a restore. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…, for ddev#8705 A shell only expands a leading `~` for a bare argument, not inside a `--flag=value` word, so `--seed-snapshot=~/dataset-mariadb_11.8.zst` reached DDEV with the `~` literal and failed to resolve. resolveSnapshotSource() now expands it via the existing util.ExpandHomedir(), already used the same way for import-db/import-files asset paths, covering both --seed-snapshot and `ddev snapshot restore` since they share that resolver. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…lde, for ddev#8705 The no-bind-mounts CI job sets globalconfig.DdevGlobalConfig.NoBindMounts to true for the whole package, under which resolveSnapshotSource() intentionally returns an empty mountDir. The test asserted mountDir unconditionally equaled the outside directory, so it failed under that job. TestResolveSeedSnapshot already handles this by pinning the flag for the duration of the test; do the same here. Co-Authored-By: Claude Sonnet 5 <[email protected]>
ddev#8705 Pulling upstream/main (which already carried ddev#8704's uncompressed-snapshot support) left several call sites on this branch out of sync with the new Snapshot()/RestoreSnapshot() signatures, plus two GetInitializerSnapshotFile()/ initializer-* references in base_db_seed_test.go that an earlier rename commit on this branch had missed. Updates every stale call site and finishes that rename; no behavior change. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…dev#8705 snapshotDBVersionFromFilename() hardcoded a `.(gz|zst)` suffix, so an uncompressed .mbstream/.xbstream snapshot passed via --seed-snapshot=<path> was rejected with "unable to determine database type/version" even though GetSeedSnapshotFile() and RestoreSnapshot() already accept all four extensions through the shared snapshotExtensionPattern. Reuses that pattern here too, so --seed-snapshot is no longer more restrictive than the reserved `seed` name or `ddev snapshot restore`. Co-Authored-By: Claude Sonnet 5 <[email protected]>
fc42c0c to
18ebf7c
Compare
|
Pushed updated container image(s) for this PR:
|
…broken bats test, for ddev#8705 Two more botched-merge leftovers from rebasing e9ff8e2 onto upstream/main, found while chasing the CI failure in base_db_seed.bats (`unexpected end of file` at line 177): - base_db_seed.bats had a dangling, bodyless `@test "uncompressed initializer seed overrides..." {` line immediately followed by another `@test` line, a syntax error bats' parser correctly rejected. It also had a duplicated header comment block and an exact duplicate of the "restore_snapshot seeds an empty datadir from /mnt/snapshots" test. Replaced the dangling declaration with a real test exercising restore_snapshot against an uncompressed (.mbstream/.xbstream) snapshot, which is new coverage: nothing exercised that path before. - docker-entrypoint.sh's base_db seed lookup still checked /mnt/snapshots/initializer-<version>.{mbstream,xbstream} even though the surrounding comment and error message already said (correctly) that a project-level seed is handed over via restore_snapshot instead, and even though the .zst/.gz sibling lines for the same removed tier were already gone. Removed the two leftover lines so the code matches its own comment. Also updates two stale `initializer` references in database-management.md and a test comment to the current `seed` naming, and regenerates BaseDBTag in versionconstants.go for the changed image content (local dbserver image rebuilt and the new base_db_seed.bats suite re-run against it: all 5 tests pass, including the new uncompressed-restore case). Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Pushed updated container image(s) for this PR:
|
stasadev
left a comment
There was a problem hiding this comment.
Looks good to me.
I didn't know I needed the --reset-database flag, but I think it's going to be my new favorite!
I left a couple of minor suggestions for the docs.
Co-authored-by: Stanislav Zhuk <[email protected]>
…napshot restore` ## The Issue Related to ddev#8623 ("Allow worktrees to share DB snapshots" by @tyler36): a snapshot taken in one git worktree of a project isn't visible to `ddev snapshot restore` in another worktree of the same repository, so reusing a database across worktrees means manually copying snapshot files around. ddev#8623 predates the path-based snapshot restore/seed support that's landed on `main` since it was opened (ddev#8704, ddev#8705), and its `RestoreSnapshot(name, sourceRoot)` signature no longer matches `RestoreSnapshot(name, force)` on `main` - it needs a rewrite on top of current code either way. This is that rewrite, built directly on the newer mechanism instead of duplicating it. ## How This PR Solves The Issue `ddev snapshot restore` and `ddev snapshot restore --latest` already support restoring from an arbitrary host path via `resolveSnapshotSource`. This adds automatic discovery on top of that, rather than a parallel restore mechanism: - `DdevApp.ListSnapshotRestoreTargets()` lists the current project's own snapshots plus any snapshots found in the same project checked out in other worktrees of the same git repository (via `git worktree list`), newest first. A worktree match requires the same repository and the same relative project path - determined entirely from git and the filesystem, never from the `.ddev/config.yaml` project name (worktree projects don't usually share a name). A separate clone that happens to sit at the same relative path is not offered. - `DdevApp.GetLatestSnapshotRestoreTarget()` extends `--latest` the same way. - The interactive picker in `ddev snapshot restore` shows a worktree snapshot's name and source directory (`snapshot-name (worktree-dir)`); selecting one restores by its absolute path, reusing the existing path-based restore/bind-mount plumbing rather than a copy step. I considered going further with a repository-agnostic shared snapshot pool keyed by project name (so any two checkouts with the same name could share snapshots, not just worktrees of one repo). I left that out: project names collide too easily across unrelated projects, and a git worktree relationship is a precise, verifiable identity check that a name is not. The fully general case - "restore a snapshot from anywhere on disk" - is already covered by the existing path argument. ## Manual Testing Instructions 1. Create a git repo and a worktree of it, each with a DDEV project at the same relative path (project names deliberately differ, since that's the normal case for worktrees): ```bash git init repo && cd repo && git commit --allow-empty -m init ddev config --project-type=php --project-name=repo-a ddev start ddev snapshot --name=shared-snapshot cd .. && git -C repo worktree add ../repo-b HEAD cd repo-b ddev config --project-type=php --project-name=repo-b ddev start ``` 2. `ddev snapshot restore` in `repo-b` - the picker should list `shared-snapshot (repo)` alongside any of `repo-b`'s own snapshots. `ddev snapshot restore --latest` should restore it directly. 3. A separate `git clone` of `repo` at the same relative depth should *not* have its snapshots offered from `repo-b`. ## Automated Testing Overview Covered in the following commit, along with a fix for a real bug found while writing it. ## Release/Deployment Notes No config or behavior changes for projects outside a git worktree. Within a worktree, `ddev snapshot restore` and `--latest` now also see snapshots from sibling worktrees of the same project; this is additive and doesn't change what a bare snapshot name resolves to. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Thanks @rfay for working on this! ❤️ |
…napshot restore` ## The Issue Related to ddev#8623 ("Allow worktrees to share DB snapshots" by @tyler36): a snapshot taken in one git worktree of a project isn't visible to `ddev snapshot restore` in another worktree of the same repository, so reusing a database across worktrees means manually copying snapshot files around. ddev#8623 predates the path-based snapshot restore/seed support that's landed on `main` since it was opened (ddev#8704, ddev#8705), and its `RestoreSnapshot(name, sourceRoot)` signature no longer matches `RestoreSnapshot(name, force)` on `main` - it needs a rewrite on top of current code either way. This is that rewrite, built directly on the newer mechanism instead of duplicating it. ## How This PR Solves The Issue `ddev snapshot restore` and `ddev snapshot restore --latest` already support restoring from an arbitrary host path via `resolveSnapshotSource`. This adds automatic discovery on top of that, rather than a parallel restore mechanism: - `DdevApp.ListSnapshotRestoreTargets()` lists the current project's own snapshots plus any snapshots found in the same project checked out in other worktrees of the same git repository (via `git worktree list`), newest first. A worktree match requires the same repository and the same relative project path - determined entirely from git and the filesystem, never from the `.ddev/config.yaml` project name (worktree projects don't usually share a name). A separate clone that happens to sit at the same relative path is not offered. - `DdevApp.GetLatestSnapshotRestoreTarget()` extends `--latest` the same way. - The interactive picker in `ddev snapshot restore` shows a worktree snapshot's name and source directory (`snapshot-name (worktree-dir)`); selecting one restores by its absolute path, reusing the existing path-based restore/bind-mount plumbing rather than a copy step. I considered going further with a repository-agnostic shared snapshot pool keyed by project name (so any two checkouts with the same name could share snapshots, not just worktrees of one repo). I left that out: project names collide too easily across unrelated projects, and a git worktree relationship is a precise, verifiable identity check that a name is not. The fully general case - "restore a snapshot from anywhere on disk" - is already covered by the existing path argument. ## Manual Testing Instructions 1. Create a git repo and a worktree of it, each with a DDEV project at the same relative path (project names deliberately differ, since that's the normal case for worktrees): ```bash git init repo && cd repo && git commit --allow-empty -m init ddev config --project-type=php --project-name=repo-a ddev start ddev snapshot --name=shared-snapshot cd .. && git -C repo worktree add ../repo-b HEAD cd repo-b ddev config --project-type=php --project-name=repo-b ddev start ``` 2. `ddev snapshot restore` in `repo-b` - the picker should list `shared-snapshot (repo)` alongside any of `repo-b`'s own snapshots. `ddev snapshot restore --latest` should restore it directly. 3. A separate `git clone` of `repo` at the same relative depth should *not* have its snapshots offered from `repo-b`. ## Automated Testing Overview Covered in the following commit, along with a fix for a real bug found while writing it. ## Release/Deployment Notes No config or behavior changes for projects outside a git worktree. Within a worktree, `ddev snapshot restore` and `--latest` now also see snapshots from sibling worktrees of the same project; this is additive and doesn't change what a bare snapshot name resolves to. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…napshot restore` ## The Issue Related to ddev#8623 ("Allow worktrees to share DB snapshots" by @tyler36): a snapshot taken in one git worktree of a project isn't visible to `ddev snapshot restore` in another worktree of the same repository, so reusing a database across worktrees means manually copying snapshot files around. ddev#8623 predates the path-based snapshot restore/seed support that's landed on `main` since it was opened (ddev#8704, ddev#8705), and its `RestoreSnapshot(name, sourceRoot)` signature no longer matches `RestoreSnapshot(name, force)` on `main` - it needs a rewrite on top of current code either way. This is that rewrite, built directly on the newer mechanism instead of duplicating it. ## How This PR Solves The Issue `ddev snapshot restore` and `ddev snapshot restore --latest` already support restoring from an arbitrary host path via `resolveSnapshotSource`. This adds automatic discovery on top of that, rather than a parallel restore mechanism: - `DdevApp.ListSnapshotRestoreTargets()` lists the current project's own snapshots plus any snapshots found in the same project checked out in other worktrees of the same git repository (via `git worktree list`), newest first. A worktree match requires the same repository and the same relative project path - determined entirely from git and the filesystem, never from the `.ddev/config.yaml` project name (worktree projects don't usually share a name). A separate clone that happens to sit at the same relative path is not offered. - `DdevApp.GetLatestSnapshotRestoreTarget()` extends `--latest` the same way. - The interactive picker in `ddev snapshot restore` shows a worktree snapshot's name and source directory (`snapshot-name (worktree-dir)`); selecting one restores by its absolute path, reusing the existing path-based restore/bind-mount plumbing rather than a copy step. I considered going further with a repository-agnostic shared snapshot pool keyed by project name (so any two checkouts with the same name could share snapshots, not just worktrees of one repo). I left that out: project names collide too easily across unrelated projects, and a git worktree relationship is a precise, verifiable identity check that a name is not. The fully general case - "restore a snapshot from anywhere on disk" - is already covered by the existing path argument. ## Manual Testing Instructions 1. Create a git repo and a worktree of it, each with a DDEV project at the same relative path (project names deliberately differ, since that's the normal case for worktrees): ```bash git init repo && cd repo && git commit --allow-empty -m init ddev config --project-type=php --project-name=repo-a ddev start ddev snapshot --name=shared-snapshot cd .. && git -C repo worktree add ../repo-b HEAD cd repo-b ddev config --project-type=php --project-name=repo-b ddev start ``` 2. `ddev snapshot restore` in `repo-b` - the picker should list `shared-snapshot (repo)` alongside any of `repo-b`'s own snapshots. `ddev snapshot restore --latest` should restore it directly. 3. A separate `git clone` of `repo` at the same relative depth should *not* have its snapshots offered from `repo-b`. ## Automated Testing Overview Covered in the following commit, along with a fix for a real bug found while writing it. ## Release/Deployment Notes No config or behavior changes for projects outside a git worktree. Within a worktree, `ddev snapshot restore` and `--latest` now also see snapshots from sibling worktrees of the same project; this is additive and doesn't change what a bare snapshot name resolves to. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Short Summary (TL;DR)
seedreplacesinitializeras the reserved snapshot name that fills a brand-new database volume, and it now works for PostgreSQL too.ddev start/restart --seed-snapshot=<name-or-path>fills a brand-new database volume from any snapshot, including one outside the project.ddev start/restart --reset-databasethrows the existing database away and starts over. It snapshots first unless you add-O.ddev snapshot restore --forcerestores a snapshot made by a different version of the same database server.The Issue
The seed mechanism in #8608 was keyed on one filename,
initializer-<type>_<version>.*. You had to learn that name from the docs, you could not point at a different snapshot, and PostgreSQL was not supported.Separately, there was no way to say "wipe the database and start over" when
ddev startrefused because the volume was made by a different database server. The error pointed atddev utility migrate-database, which only converts between MariaDB and MySQL.ddev deletewas no way out either: it started the project to take its pre-delete snapshot, hit the same refusal, and gave up unless you passed-O. That is why the workaround in #8322 starts with putting theconfig.yamlchange back.How This PR Solves The Issue
Seeding now uses the db container's existing
restore_snapshotcommand instead of a filename the entrypoint looks for. On an empty data directory that command does exactly what the old seed lookup did, so one path covers the reserved name, the flag, and every database type. The/mnt/snapshots/initializer-*tier is gone from the entrypoint; the twobase_dbtiers baked into images are unchanged.seedis picked up automatically on a fresh database volume, asinitializerwas, and PostgreSQL gets it now as well.--seed-snapshottakes a snapshot name from.ddev/db_snapshotsor a path to a file elsewhere. A file outside the project is bind-mounted into the db container rather than copied, so a multi-GB snapshot is not duplicated. The entrypoint learned to accept an absolute path for this.--reset-databaseremoves the database volume so the next start makes a new one. The snapshot it takes first is made with the database version that is actually in the volume, not the configured one, which is what makes it work after adatabase:change.Stop()uses the same helper, soddev deletestops giving up on a mismatched project.Two smaller changes were needed to make the above usable:
ddev config --database=now warns instead of failing. Writingconfig.yamldestroys nothing andddev startstill refuses until you resolve it, but whileddev configrefused there was no way to reach--reset-databaseshort of hand-editingconfig.yaml.Manual Testing Instructions
Automated Testing Overview
TestResolveSeedSnapshot,TestGetSeedSnapshotFile,TestSnapshotDBVersionFromFilenameandTestSnapshotRestoreContainerCommandcover flag resolution, version matching and the container command, including the PostgreSQL 18+mkdir.TestCmdStartResetDatabaseandTestCmdStartSeedSnapshotFilecover reset with and without a seed, a seed file outside the project, and the flag combinations that are refused.TestDdevAllDatabasesnow seeds from both the reserved name and an explicit one, for every supported database version.base_db_seed.batscoversrestore_snapshotseeding an empty data directory from both a/mnt/snapshotsname and an absolute path.Checked by hand against MariaDB 11.8, PostgreSQL 17 and PostgreSQL 18, including the cross-type reset and
ddev deleteon a mismatched project.Release/Deployment Notes
initializersnapshots are no longer recognized. Rename the file toseed-<type>_<version>.<ext>. That name only ever existed in main and was never in a release, so nothing shipped depends on it, but this needs to land before v1.25.4 for that to stay true.This needs a
ddev-dbserverimage push.--seed-snapshotwith a file outside the project relies on the entrypoint accepting an absoluterestore_snapshotpath.