Skip to main content

Database

The running site's database lives inside the database container - the .data/db.sql file on the host is only a dump used for imports and exports. Removing the container (for example, with ahoy reset) discards the live database, and the next build re-creates it from the dump.

Fetching and exporting run on the host (they move dump files around), while refreshing runs inside the containers (it imports into the running database) - the tabs below reflect that difference.

Fetching database

To fetch the database with the latest data from the production environment, fetch the latest database dump into the .data directory.

# Fetch latest database dump (uses cache if fetched today)
ahoy fetch-db
# Force a fresh fetch regardless of cache
ahoy fetch-db --fresh
note

The database dump is stored in the .data directory instead of being directly imported into the local environment to allow for caching and reusing the database dump without needing to fetch it every time you need to refresh the local environment.

You can manually fetch the database dump from the production environment, name it db.sql, and place it in the .data directory.

Refreshing database

There are 2 distinct ways to load the dump from .data into the running database container - pick the one matching what you need.

Import and run updates

ahoy provision imports the dump and applies all the provisioning steps: database updates, configuration import, cache rebuilds and deploy hooks. Use it any time you need the local environment reset to a fully updated state.

ahoy provision

Import only

ahoy import-db imports the raw dump without running any updates, configuration imports or scripts. Use it to quickly reset the database contents to the state captured in the dump.

ahoy import-db

Exporting database

Export timestamped database dumps from the local environment.

# Export current database to .data directory
ahoy export-db

You can use these dumps to restore the local environment to a specific state: rename the dump file to .data/db.sql and run the import command.

Cache tables are exported with their structure but without their data, because Drupal rebuilds them on demand and their contents would only inflate the dump. Set VORTEX_EXPORT_DB_FILE_STRUCTURE_TABLES to a comma-separated list of table names, each of which may use the * wildcard, to choose which tables are exported this way. Set it to an empty value to export the data of every table.

➡️ See Drupal > Provision