Repository navigation
feat(dbserver): support zstd-compressed base_db for faster first-boot restore - #8608
Conversation
03b4330 to
57e8898
Compare
rfay
left a comment
There was a problem hiding this comment.
I pushed the needed db image and added it to versionconstants.go, but
- We should just be building and using zst to begin with
- It has to have a test
- If we're going to do this it makes sense to offer a way to get the zst from external instead of built-in
|
Download the artifacts for this pull request:
See Testing a PR. |
|
I'm inspired. Adding some stuff. Hope it's OK. You'll like it. |
0654da1 to
57bbea1
Compare
|
Sorry, I got carried away. It needed images pushed. Then it needed tests. Then it was such a good idea that it needed a simpler approach and an initializer. Anyway, see docs below for current state. If you don't like it we can roll back. Added two more pieces to this PR: Two override tiers for the base_db seed, ahead of the stock starter database
A Tests
Docs
|
|
Fantastic improvements. Great to see this officially supported. |
|
Pretty amazing It's all there! |
|
I tested the built database image with Pretty slick! |
|
I thought maybe we still had a |
|
This works, but it's fragile and a local build, but it validates this PR: #Dockerfile to build embedded database snapshot
FROM ddev/ddev-dbserver-mariadb-11.8:20260720_weitzman_zstd_base_db
COPY .ddev/db_snapshots/base_db-mariadb_11.8.zst /mysqlbase/custom/base_db.zst |
|
Opened to bring dbimage back for this use-case |
|
This PR unlocks some nice functionality for agents that frequently spin up worktrees. Those worktrees will automatically get a fresh DB to work with. |
stasadev
left a comment
There was a problem hiding this comment.
Overall, this looks like a great improvement, but I don't think there's enough user feedback to help people understand what's happening on ddev start.
| ddev snapshot --name=initializer | ||
| ``` | ||
|
|
||
| Unlike other snapshots, `initializer` isn't meant to be restored with `ddev snapshot restore` — it's only consulted for an uninitialized database. Commit the resulting `initializer-*` file in `.ddev/db_snapshots` to your repository if you want teammates and CI to get the same starting dataset on their first `ddev start`. |
There was a problem hiding this comment.
Commit the resulting
initializer-*file in.ddev/db_snapshotsto your repository
I would not recommend this, committing blobs is a bad idea. I'd rather make some pre-start hook to copy the file from a specific location if it doesn't exist.
There was a problem hiding this comment.
Although, I think it's good to commit if the blob is only a few megabytes.
013ab1d to
a9928c3
Compare
|
This PR now has the option of using |
…Bytes Addresses PR ddev#8608 review feedback from @stasadev. - When a fresh database volume will be seeded from an `initializer` snapshot or a derived-image base_db, `ddev start` now extends the container-ready wait to at least `SnapshotRestoreDefaultWaitTime` (600s), same as `RestoreSnapshot` already does, and reports the actual timeout in effect instead of the unmodified default. - `fileSizeSuffix` now formats via `util.FormatBytes` instead of a separate KiB/MiB implementation, keeping byte formatting consistent across the codebase.
|
Pushed 4 commits addressing @stasadev's review comments:
|
Alongside the project-level `initializer` snapshot, ddev/ddev#8608 also supports baking a base_db seed directly into the dbimage: either via a project .ddev/db-build/Dockerfile (built automatically by `ddev start`) or a standalone image set via `dbimage:` config. Tested both against Medium and Xlarge tiers with fresh-volume ddev starts, verified row counts, and compared timings against the initializer-snapshot baseline (all three land in the same 76-90s ballpark for the Xlarge/2.6GB seed -- the real difference between them is seed distribution/lifecycle, not restore speed). - scripts/test-baked-image-seed.sh: fresh-volume ddev start timing/ verification for either baked-image technique, mirroring test-initializer-snapshot.sh's approach (trust ddev's own announceBaseDBSeed output, not reconstructed container logs) - dockerfiles/db-with-seed/Dockerfile: standalone image example for the `dbimage:` technique - notes/devel-generate-scale-findings.md: full writeup with precedence order, both techniques' results tables, and the cross-technique comparison
|
Tools for testing are in https://github.com/rfay/database-performance
|
… restore ## The Issue The dbserver first-boot restore path is hardcoded to gzip: it always runs `gunzip -c /mysqlbase/base_db.gz | xbstream -x`. The snapshot restore path in the same entrypoint already auto-detects `.zst` vs `.gz`. gzip decompression is single-threaded and dominates first-boot restore time, which matters most for derived images that bake a large production dataset into `/mysqlbase/base_db.gz` (and for ephemeral/CI containers that restore on every startup). Benchmarked against a real 21GB datadir (2.99GB gzipped) on an 18-core Docker VM: | Phase | gzip | zstd | |---------------------------|--------|-------| | decompress + xbstream -x | 105.2s | 30.5s | | xtrabackup --prepare | 4.5s | 4.5s | | xtrabackup --copy-back | 16.2s | 16.2s | | total restore | ~126s | ~51s | Decompression is ~84% of restore time. End-to-end, container start to mysqld ready dropped from 117s to 40s. The zstd archive is also 25-32% smaller (2.24GB at level 3, 2.03GB at level 9) than the 2.99GB gzip archive. ## How This PR Solves The Issue The base-database first-boot path now prefers `/mysqlbase/base_db.zst` when present, decompressing with `zstdmt` (parallel; falls back to `zstd`), using the same tool invocation as the existing snapshot restore path. It falls back to `base_db.gz` exactly as before. `create_base_db.sh` intentionally still emits gzip: if stock images shipped `base_db.zst`, a derived image that COPYs a custom `base_db.gz` over the stock image would be silently shadowed by the preferred stock `.zst`. Accepting zstd only on the consume side keeps every existing derived image working while letting projects opt in by baking `base_db.zst` instead (e.g. `xtrabackup --backup --stream=xbstream ... | zstdmt -3`). zstd is already installed in the images; the snapshot path uses it. Nothing in ddev Go code, docs, or container tests references the `base_db.gz` filename, so no other changes are needed. ## Manual Testing Instructions 1. Build a dbserver image, or use any existing v1.25 image. 2. Transcode its starter db: `docker run --rm --entrypoint bash <image> -c 'gunzip -c /mysqlbase/base_db.gz' | zstdmt -3 -o base_db.zst` 3. Start with the new entrypoint, a fresh datadir volume, and the zst archive mounted: `docker run -d --user=501:20 -v $PWD/base_db.zst:/mysqlbase/base_db.zst:ro -v /var/lib/mysql <image>` 4. Verify logs show `zstdmt -dc --quiet /mysqlbase/base_db.zst` and `Database initialized`, and that mysql answers queries. 5. Repeat without the zst mount to confirm the gzip fallback path. ## Automated Testing Overview Existing dbserver container tests exercise the gzip fallback path on every image build (stock images contain only `base_db.gz`). Manually verified both paths against a production-sized derived image: zstd restore (506 tables intact, mysqld healthy) and gzip fallback (identical result). ## Release/Deployment Notes Additive and backward compatible. Stock images are unchanged in behavior. Derived images gain the option to ship `base_db.zst` for ~3x faster first boot and smaller images; `.zst` takes precedence when both files exist. Co-Authored-By: Claude Fable 5 <[email protected]>
…Bytes Addresses PR ddev#8608 review feedback from @stasadev. - When a fresh database volume will be seeded from an `initializer` snapshot or a derived-image base_db, `ddev start` now extends the container-ready wait to at least `SnapshotRestoreDefaultWaitTime` (600s), same as `RestoreSnapshot` already does, and reports the actual timeout in effect instead of the unmodified default. - `fileSizeSuffix` now formats via `util.FormatBytes` instead of a separate KiB/MiB implementation, keeping byte formatting consistent across the codebase.
The start-time announcement already reported the size of an `initializer` snapshot seed, but not a seed baked into a derived dbimage. Have `getDerivedDBImageSeed` also report the in-image file's byte size (via `wc -c` in the same check container) so both seed paths announce size.
Long absolute snapshot paths ran on the same line as the surrounding sentence, e.g.: Initializing new database volume from the 'initializer' snapshot /home/user/project/.ddev/db_snapshots/initializer-mariadb_11.8.zst (137.9MB)... Put the path/size on its own line, and shorten a home-directory path to `~/...` via fileutil.ShortHomeJoin, matching how other ddev output already shortens paths.
The "Custom configuration detected" listing (from CheckCustomConfig, shown by e.g. `ddev start`/`ddev utility check-custom-config`) reports the `initializer` snapshot with its raw absolute host path. Shorten it with fileutil.ShortHomeJoin, matching the ~/... shortening already applied to the same path in the start-time base_db seed announcement.
f8cf6a3 to
e686c07
Compare
|
Tools for testing this: rfay/database-performance
|
| Run | dbimage (randyfay/dbserver-2m) |
initializer snapshot |
|---|---|---|
| 1 | 123.8s | 110.0s |
| 2 | 113.8s | 105.6s |
| avg | 118.8s | 107.8s |
ddev's own "containers ready" time (subset of the above; excludes image build + Mutagen flush)
| Run | dbimage | initializer |
|---|---|---|
| 1 | 101.0s | 89.0s |
| 2 | 97.0s | 84.5s |
| avg | 99.0s | 86.75s |
db container timeline detail (from docker logs --timestamps ddev-d11-db)
| Phase | dbimage run 1 | dbimage run 2 | initializer run 1 |
|---|---|---|---|
decompress (zstdmt -dc) + xbstream extract |
48.9s | 39.7s | 31.5s |
mariabackup --copy-back |
63.6s | 63.2s | 65.6s |
container start → mariadbd: ready for connections |
~113.4s | ~103.8s | ~99.4s |
Observations
- The initializer snapshot was consistently ~10-15s faster end-to-end than the
dbimage-baked seed, on both totalddev starttime and ddev's internal
"containers ready" measurement, across both runs. - The gap is concentrated entirely in the decompression phase (reading
/mnt/snapshots/initializer-*.zst, a host bind mount, vs.
/mysqlbase/custom/base_db.zst, a file baked into an image layer). The
mariabackup --copy-backphase — identical work regardless of seed source
— took the same ~63-66s in every run, as expected. - This is a small sample (2 runs each) on one machine; treat the ~10s gap as
directional, not precise. It's plausible the difference is specific to how
OrbStack's virtual disk handles image-layer reads vs. bind mounts, and may
not reproduce on Linux or Docker Desktop. - Neither approach's raw restore time changed materially from what's already
documented in the PR description for the 18-core Linux Docker VM (~105-114s
decompress+copy-back here vs. ~51s there) — this hardware/runtime has less
parallelism available tozstdmtthan the box the original PR benchmark
used, plus decompression is competing with copy-back for the M4's 10 cores.
Bug found while running this: derived-image seed detection breaks for untagged dbimage:
While timing the dbimage case, ddev start never printed the
"Initializing new database volume from ... baked into dbimage ..." banner
that the initializer case prints reliably. Both restores actually happened
correctly (confirmed via docker logs), so this only affects the
announcement/timeout-extension path added in 9de4d13, not the seed itself.
Root cause: getDerivedDBImageSeed() in pkg/ddevapp/base_db_seed.go:108
builds the check-container's image reference as
app.GetDBImage()+"-"+app.Name+"-built" — plain string concatenation. When
dbimage: is configured without an explicit tag (e.g.
dbimage: randyfay/dbserver-2m, which is exactly how this PR's own testing
setup and dockerfiles/db-with-seed in rfay/database-performance both use
it), this produces an untagged reference like randyfay/dbserver-2m-d11-built
with no colon at all. dockerutil.RunSimpleContainer → the helper at
pkg/dockerutil/containers.go:649 rejects that outright:
Unable to check dbimage for a baked-in base_db seed: image name must specify tag: randyfay/dbserver-2m-d11-built, output=
(only visible with DDEV_DEBUG=true; the failure is otherwise swallowed by
util.Debug() and getDerivedDBImageSeed() just returns ("", -1), so
BaseDBSeedDescription() silently returns "" and the whole announcement
block is skipped.)
The working precedent for this exact pattern is
ddevapp.go:1858's app.WebImage+"-"+app.Name+"-built" for the log-stderr
check — but that one only works because app.WebImage always carries an
explicit tag from versionconstants (e.g. ddev/ddev-webserver:v1.25.3), so
the appended suffix lands in the tag portion (v1.25.3-d11-built) rather than
collapsing into an untagged repo string. app.DBImage has no such guarantee
when a user sets dbimage: to a bare repo name.
Practical impact: for any project whose dbimage: omits an explicit tag —
which is the common case, and is how this PR's own README/PR description
examples show it — the user gets no advance warning of a large baked-in seed
restore, and (more importantly) default_container_timeout never gets
bumped to SnapshotRestoreDefaultWaitTime (600s) the way the initializer path
does. A big enough baked-in seed could time out ddev start without ever
extending the wait, where the equivalent initializer-snapshot seed would not.
Two other call sites use the same unsafe concatenation and may have the same
latent issue for untagged dbimage: values (both currently swallow errors,
so likely also silent):
ddevapp.go:3468(dbBuilt := app.GetDBImage() + "-" + app.Name + "-built", used byddev delete's belt-and-suspenders image cleanup — errors ignored via_ =)ddevapp.go:3470(same pattern forwebBuilt, thoughapp.WebImageis safe per above)
Happy to send a fix (normalize the image reference — default to :latest
before appending the -built suffix to the tag, matching whatever the real
compose-build tagging logic does at ddevapp.go:335/473) if wanted.
…base_db seed
getDerivedDBImageSeed() built its check-container's image reference as
`app.GetDBImage()+"-"+app.Name+"-built"`. When `dbimage:` is configured
without an explicit tag (e.g. `dbimage: randyfay/dbserver-2m`, a common
style, and how this feature's own testing setup used it), that produces an
untagged reference like `randyfay/dbserver-2m-d11-built`, which
dockerutil.RunSimpleContainer rejects outright ("image name must specify
tag"). The failure was only visible with DDEV_DEBUG=true; otherwise
getDerivedDBImageSeed() silently returned no seed found.
Net effect: for any project with an untagged `dbimage:`, `ddev start` never
announced a baked-in base_db seed and never extended
default_container_timeout to SnapshotRestoreDefaultWaitTime the way the
`initializer` snapshot path does -- a large enough seed could time out
without warning.
Docker itself defaults a tag-less repo to ":latest" when tagging a build
(which is exactly how the "-built" image got its real tag in the first
place), so derivedBuiltImageRef() now does the same before handing the
reference to RunSimpleContainer.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
rfay
left a comment
There was a problem hiding this comment.
I think this is good! It will offer so many great opportunities.
…tializer' to 'seed', fixes ddev#8661, fixes ddev#8322 ## Short Summary (TL;DR) 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. ## The Issue - 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`. ## How This PR Solves The Issue 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. ## Manual Testing Instructions ```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 # Reserved name: the marker table comes back on a brand-new volume ddev start --reset-database -O -y echo "SHOW TABLES;" | ddev mysql db # Explicit name, and a snapshot from outside the project 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#8322: switch database type with data in the volume 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 ``` ## Automated Testing Overview - `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. ## Release/Deployment Notes `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.
…tializer' to 'seed', fixes ddev#8661, fixes ddev#8322 ## Short Summary (TL;DR) 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. ## The Issue - 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`. ## How This PR Solves The Issue 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. ## Manual Testing Instructions ```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 # Reserved name: the marker table comes back on a brand-new volume ddev start --reset-database -O -y echo "SHOW TABLES;" | ddev mysql db # Explicit name, and a snapshot from outside the project 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#8322: switch database type with data in the volume 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 ``` ## Automated Testing Overview - `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. ## Release/Deployment Notes `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.
…tializer' to 'seed', fixes ddev#8661, fixes ddev#8322 ## Short Summary (TL;DR) 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. ## The Issue - 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`. ## How This PR Solves The Issue 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. ## Manual Testing Instructions ```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 # Reserved name: the marker table comes back on a brand-new volume ddev start --reset-database -O -y echo "SHOW TABLES;" | ddev mysql db # Explicit name, and a snapshot from outside the project 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#8322: switch database type with data in the volume 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 ``` ## Automated Testing Overview - `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. ## Release/Deployment Notes `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.
…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.
…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.
…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.
…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.
…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.
…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.
…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.
|
🎉 This PR is included in the v1.25.4 release. |
I have a new iteration on the DDEV-MTK approach which has far superior DX. I can't show it yet - will do so soon. Meanwhile, this PR speeds up one piece of the puzzle.
The gist of my new approach is that I use Github Actions to build a DB image thats based on the DDEV DB Image (I'm aware that you don't provide guarantees regarding future changes of this). The new image has our Prod DB data baked in via a
mysqlbase/base_db.gz. The DB image restores that data into datadir upon startup. This PR speeds up that startup using an optimization thatddev snapshot restorealready uses in this same file.Sorry for the wall of text below. I hope some of it is helpful. The diff is small, thankfully.
The Issue
The dbserver first-boot restore path is hardcoded to gzip: it always runs
gunzip -c /mysqlbase/base_db.gz | xbstream -x. The snapshot restore path inthe same entrypoint already auto-detects
.zstvs.gz. gzip decompressionis single-threaded and dominates first-boot restore time, which matters most
for derived images that bake a large production dataset into
/mysqlbase/base_db.gz(and for ephemeral/CI containers that restore onevery startup).
Benchmarked against a real 21GB datadir (2.99GB gzipped) on an 18-core
Docker VM:
Decompression is ~84% of restore time. End-to-end, container start to mysqld
ready dropped from 117s to 40s. The zstd archive is also 25-32% smaller
(2.24GB at level 3, 2.03GB at level 9) than the 2.99GB gzip archive.
How This PR Solves The Issue
The base-database first-boot path now prefers
/mysqlbase/base_db.zstwhenpresent, decompressing with
zstdmt(parallel; falls back tozstd), usingthe same tool invocation as the existing snapshot restore path. It falls
back to
base_db.gzexactly as before.create_base_db.shintentionally still emits gzip: if stock images shippedbase_db.zst, a derived image that COPYs a custombase_db.gzover thestock image would be silently shadowed by the preferred stock
.zst.Accepting zstd only on the consume side keeps every existing derived image
working while letting projects opt in by baking
base_db.zstinstead(e.g.
xtrabackup --backup --stream=xbstream ... | zstdmt -3).zstd is already installed in the images; the snapshot path uses it. Nothing
in ddev Go code, docs, or container tests references the
base_db.gzfilename, so no other changes are needed.
Manual Testing Instructions
docker run --rm --entrypoint bash <image> -c 'gunzip -c /mysqlbase/base_db.gz' | zstdmt -3 -o base_db.zstarchive mounted:
docker run -d --user=501:20 -v $PWD/base_db.zst:/mysqlbase/base_db.zst:ro -v /var/lib/mysql <image>zstdmt -dc --quiet /mysqlbase/base_db.zstandDatabase initialized, and that mysql answers queries.Automated Testing Overview
Existing dbserver container tests exercise the gzip fallback path on every
image build (stock images contain only
base_db.gz). Manually verified bothpaths against a production-sized derived image: zstd restore (506 tables
intact, mysqld healthy) and gzip fallback (identical result).
Release/Deployment Notes
Additive and backward compatible. Stock images are unchanged in behavior.
Derived images gain the option to ship
base_db.zstfor ~3x faster firstboot and smaller images;
.zsttakes precedence when both files exist.Co-Authored-By: Claude Fable 5 [email protected]