A consolidated, security-hardened Artisan command over the package's backup, restore, and verification services.
php artisan laranail::db-tools.db <action> [options]
| Action | What it does | Backed by |
|---|---|---|
export |
Dump the database to a file | BackupManager driver |
restore |
Restore the database from a dump | BackupManager driver |
import |
Run a .sql file against a connection |
SqlFileRestorer |
clean |
TRUNCATE the named tables | query-builder grammar (never raw SQL) |
| Option | Purpose |
|---|---|
--path= |
SQL/backup file path (import / export / restore). |
--connection= |
Database connection (defaults to the app default). |
--tables=a,b,c |
Tables to truncate (clean). |
--force |
Skip the confirmation prompt. |
--dry-run |
Print what would happen without touching the database. Never prompts. |
php artisan laranail::db-tools.db export --path=storage/backups/db.sql
php artisan laranail::db-tools.db import --path=seed/data.sql --force
php artisan laranail::db-tools.db restore --path=storage/backups/db.sql
php artisan laranail::db-tools.db clean --tables=cache,sessions --force
- Destructive actions (
import,restore,clean) confirm first. In a non-interactive run (pipe/CI) they proceed only with--force, so a script never silently destroys data. --dry-runnever prompts, since it destroys nothing. Before 0.6.0 the confirmation ran first, so a dry run in CI hit the "re-run with--force" skip and exited 0 without printing what it would have done.cleanwill not truncate a protected table. The list lives atlaranail.db-tools.clean.protected_tablesand holdsmigrationsby default; naming one is refused before the prompt. The confirmation is not a guard —--forceremoves it, and--forceis what CI uses.cleandisables foreign key constraints for the run and wraps it in a transaction. Table order stops mattering, including for circular references, which have no valid order at all. SeeCleanDatabaseServicefor the honest limit of that transaction on MySQL.
| Situation | Code |
|---|---|
| Action completed | 0 |
| Dry run | 0 |
| Declined interactively | 0 — a deliberate choice |
Skipped non-interactively (no --force) |
1 |
| Action failed / bad arguments | 1 |
A non-interactive skip reports failure because nobody was asked. Before 0.6.0 it exited 0, so
php artisan laranail::db-tools.db restore --path=dump.sql && ./deploy.sh
deployed against a database that was never restored.
cleantruncates through the connection's query grammar — table names are validated against the schema viaDatabaseTableVerifierfirst, and never interpolated into raw SQL.- Dumps/restores delegate to the per-driver
BackupManager, which passes the database password through an environment variable (MYSQL_PWDfor MySQL/ MariaDB,PGPASSWORDfor PostgreSQL) rather than on the command line, so it never appears in the process listing.
The command uses the laranail :: namespace separator via a local
SupportsNamespacedNames trait, so this package keeps its zero-dependency
invariant (no laranail/console needed).