Skip to content

feat(dbserver): support zstd-compressed base_db for faster first-boot restore - #8608

Merged
rfay merged 14 commits into
ddev:mainfrom
weitzman:20260720_weitzman_zstd_base_db
Aug 4, 2026
Merged

rfay merged 14 commits into
ddev:mainfrom
weitzman:20260720_weitzman_zstd_base_db

Conversation

@weitzman

Copy link
Copy Markdown
Contributor

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 that ddev snapshot restore already 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 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]

@weitzman
weitzman requested a review from a team as a code owner July 20, 2026 17:00
@github-actions github-actions Bot added enhancement dependencies Pull requests that update a dependency file labels Jul 20, 2026
@rfay
rfay force-pushed the 20260720_weitzman_zstd_base_db branch from 03b4330 to 57e8898 Compare July 20, 2026 19:12

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

@rfay

rfay commented Jul 20, 2026

Copy link
Copy Markdown
Member

I'm inspired. Adding some stuff. Hope it's OK. You'll like it.

@rfay
rfay requested a review from a team as a code owner July 20, 2026 20:06
@rfay
rfay force-pushed the 20260720_weitzman_zstd_base_db branch from 0654da1 to 57bbea1 Compare July 20, 2026 20:16
@rfay

rfay commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

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

docker-entrypoint.sh now looks up a base_db seed in priority order:

  1. /mnt/snapshots/initializer-<db_type>_<db_version>.* — a project-level seed, created with ddev snapshot --name=initializer. It lives alongside regular snapshots in .ddev/db_snapshots, and is picked up automatically the first time a project's db volume is created (new project, or after ddev delete + ddev start) — no custom image required.
  2. /mysqlbase/custom/base_db.* — a seed baked into a derived dbimage via .ddev/db-build/Dockerfile, for teams publishing a custom database image (this is the use case this PR was built for).
  3. /mysqlbase/base_db.* — the stock DDEV starter database (unchanged behavior).

A .zst seed is preferred over .gz at each tier. create_base_db.sh now emits base_db.zst by default (falling back to gzip only when zstd isn't available, e.g. MariaDB 5.5 on Ubuntu 14.04), so the stock starter database gets the same first-boot speedup this PR already gives snapshot restores.

Tests

  • containers/ddev-dbserver/test/base_db_seed.bats — new container-level test, parameterized by ${DB_TYPE} ${DB_VERSION} like the existing bats suite, so it runs across the full db-version matrix. Covers stock seeding, both override tiers individually, and precedence between them.
  • pkg/ddevapp/ddevapp_test.go (TestDdevAllDatabases) — extended the existing per-version loop to also verify the initializer snapshot path, for every supported MariaDB/MySQL version. (PostgreSQL doesn't use this dbimage, so it's excluded — the initializer mechanism is MariaDB/MySQL-only for now.)

Docs

@weitzman

Copy link
Copy Markdown
Contributor Author

Fantastic improvements. Great to see this officially supported.

@rfay

rfay commented Jul 21, 2026

Copy link
Copy Markdown
Member

Pretty amazing

ddev snapshot --name=initializer
ddev delete -Oy
ddev start

It's all there!

@rfay

rfay commented Jul 21, 2026

Copy link
Copy Markdown
Member

I tested the built database image with

ddev snapshot --cleanup -y
ddev snapshot --name=usethis
cp .ddev/db_snapshots/usethis* .ddev/db-build/base_db.zst
echo " COPY base_db.zst /mysqlbase/custom/base_db.zst" >.ddev/db-build/Dockerfile.custombasedb
ddev delete -Oy
ddev utility rebuild -s db
ddev start

Pretty slick!

@rfay

rfay commented Jul 21, 2026

Copy link
Copy Markdown
Member

I thought maybe we still had a dbimage config item, but I guess we don't, so this process DOES NOT WORK:

docker tag ddev/ddev-dbserver-mariadb-11.8:20260720_weitzman_zstd_base_db randyfay/prebuiltdb:latest
docker push randyfay/prebuiltdb:latest
# No way to tell DDEV to use randyfay/prebuiltdb

@rfay

rfay commented Jul 21, 2026

Copy link
Copy Markdown
Member

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
ddev snapshot --name=base_db
docker buildx build -t ddev/ddev-dbserver-mariadb-11.8:20260720_weitzman_zstd_base_db .
ddev snapshot --cleanup -y
ddev delete -Oy
ddev start
ddev launch

@rfay

rfay commented Jul 21, 2026

Copy link
Copy Markdown
Member

Opened

to bring dbimage back for this use-case

@rfay
rfay requested a review from stasadev July 25, 2026 13:28
@weitzman

Copy link
Copy Markdown
Contributor Author

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 stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit the resulting initializer-* file in .ddev/db_snapshots to 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, I think it's good to commit if the blob is only a few megabytes.

@rfay
rfay force-pushed the 20260720_weitzman_zstd_base_db branch from 013ab1d to a9928c3 Compare July 31, 2026 12:11
@rfay

rfay commented Jul 31, 2026

Copy link
Copy Markdown
Member

This PR now has the option of using dbimage config option to specify an alternate dbimage, so you can test using that as well @weitzman

Comment thread pkg/ddevapp/base_db_seed.go Resolved
rfay added a commit to weitzman/ddev that referenced this pull request Jul 31, 2026
…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.
@rfay

rfay commented Jul 31, 2026

Copy link
Copy Markdown
Member

Pushed 4 commits addressing @stasadev's review comments:

  • 95aeb67e5 fix(dbserver): extend start timeout for base_db seed, use util.FormatBytes
    • ddev start now extends the container-ready wait to at least SnapshotRestoreDefaultWaitTime (600s) when a fresh database volume will be seeded from an initializer snapshot or a derived-image base_db, matching what RestoreSnapshot already does, and the announcement reports the actual timeout in effect.
    • fileSizeSuffix now formats via util.FormatBytes instead of a separate KiB/MiB implementation.
  • c9b16f9be feat(dbserver): report base_db seed size for derived-image seeds too
    • The start-time announcement reported the size of an initializer snapshot but not a seed baked into a derived dbimage. getDerivedDBImageSeed now also reports the in-image file's byte size (via wc -c in the same check container), so both seed paths announce size.
  • f5f351426 fix(dbserver): tidy up base_db seed start-time announcement formatting
    • Long absolute snapshot paths were running on the same line as the sentence. The path/size now go on their own line, and a home-directory path is shortened to ~/... via fileutil.ShortHomeJoin.
  • f8cf6a3a9 fix(dbserver): shorten initializer snapshot path in custom-config check
    • The separate "Custom configuration detected" listing (CheckCustomConfig) reported the initializer snapshot's raw absolute path independently of the start-time announcement. Applied the same ~/... shortening there for consistency.

rfay added a commit to rfay/database-performance that referenced this pull request Aug 1, 2026
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
@rfay

rfay commented Aug 1, 2026

Copy link
Copy Markdown
Member

Tools for testing are in https://github.com/rfay/database-performance

  • building big DB
  • Precreated drupal11 database dumps as snapshots
  • building/pushing a dbimage with contained database

weitzman and others added 2 commits August 3, 2026 00:18
… 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]>
rfay added 4 commits August 3, 2026 00:18
…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.
@rfay
rfay force-pushed the 20260720_weitzman_zstd_base_db branch from f8cf6a3 to e686c07 Compare August 3, 2026 00:25
@rfay

rfay commented Aug 3, 2026

Copy link
Copy Markdown
Member

Tools for testing this: rfay/database-performance
has scripts and generated large-dataset dumps/snapshots for exercising both
seeding paths this PR touches
(test-initializer-snapshot.sh,
test-baked-image-seed.sh,
build-and-push-seeded-image.sh).
The "Xlarge" 2M-node/500K-user dataset used below is already available
locally for further testing.

ddev start performance: initializer snapshot vs. baked-in dbimage seed

Real-world comparison of the two ways to seed a brand-new database volume
supported by this PR, using the "Xlarge" 2M-node / 500K-user Drupal dataset
from rfay/database-performance:

  1. A project-level initializer snapshot (.ddev/db_snapshots/initializer-mariadb_11.8.zst)
  2. A base_db seed baked into the dbimage itself (dbimage: randyfay/dbserver-2m)

Environment

  • Host: Apple M4, 10 cores, 32GB RAM, macOS 27
  • Docker runtime: OrbStack 29.4.0 (10 CPUs, ~15.7GB allotted)
  • ddev: v1.25.3-64-ge686c0743 (this branch, built locally)
  • Project: ~/workspace/d11 (Drupal 11, mariadb:11.8, dbimage_extra_packages: [sudo])
  • Dataset: 2,807,140,669 bytes (2.6GB) .zst, same underlying data both ways
  • Both the stock randyfay/dbserver-2m image and its project-derived -built
    image were already present in the local Docker image cache before timing
    started, so these numbers exclude image-pull time. A cold pull of the
    3.36GB randyfay/dbserver-2m image over the network would add to the
    dbimage approach's first-ever run, with no equivalent cost for the
    initializer approach (which downloads a smaller 2.6GB file once, outside
    ddev start).

Method

For each approach: remove the other seed source, ddev delete -Oy (forces a
truly empty database volume, skips a snapshot of the outgoing data), then
time ddev start, twice. This mirrors what
test-initializer-snapshot.sh
and
test-baked-image-seed.sh
in that repo do.

Results

Total ddev start wall-clock (time real)

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 total ddev start time 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-back phase — 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 to zstdmt than 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 by ddev delete's belt-and-suspenders image cleanup — errors ignored via _ =)
  • ddevapp.go:3470 (same pattern for webBuilt, though app.WebImage is 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 rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good! It will offer so many great opportunities.

@rfay
rfay merged commit 1cca794 into ddev:main Aug 4, 2026
50 of 52 checks passed
@weitzman
weitzman deleted the 20260720_weitzman_zstd_base_db branch August 8, 2026 16:13
rfay added a commit to rfay/ddev that referenced this pull request Aug 14, 2026
…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.
rfay added a commit to rfay/ddev that referenced this pull request Aug 14, 2026
…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.
rfay added a commit to rfay/ddev that referenced this pull request Aug 16, 2026
…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.
rfay added a commit to rfay/ddev that referenced this pull request Aug 18, 2026
…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.
rfay added a commit to rfay/ddev that referenced this pull request Aug 18, 2026
…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.
rfay added a commit to rfay/ddev that referenced this pull request Aug 19, 2026
…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.
rfay added a commit to rfay/ddev that referenced this pull request Aug 21, 2026
…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.
rfay added a commit to rfay/ddev that referenced this pull request Aug 21, 2026
…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.
rfay added a commit to rfay/ddev that referenced this pull request Aug 22, 2026
…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.
rfay added a commit to rfay/ddev that referenced this pull request Aug 22, 2026
…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.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in the v1.25.4 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants