Commands
The binary has four commands. Every one reads the database named by TRUSS_DSN, or by --dsn when it is given.
| Command | What it does |
|---|---|
truss show | Print the structure as a table in the terminal |
truss export | Write the structure in one of seven formats |
truss doctor | Review the structure for problems |
truss diff | Compare two live databases |
The text exports and the doctor’s report are byte-identical to the artisan commands run against the same database, because both call one implementation. What you learn on the artisan commands page applies here.
Connection strings
| Database | Connection string |
|---|---|
| MySQL | mysql://user:pass@host:3306/database |
| MariaDB | mariadb://user:pass@host:3306/database |
| PostgreSQL | pgsql://user:pass@host:5432/database |
| SQLite | sqlite:/path/to/database.sqlite, or just the path |
The port is optional and defaults to the driver’s usual one. postgres:// and postgresql:// are accepted as well as pgsql://. A bare path is read as a SQLite file when it contains a / or ends in .sqlite, .sqlite3 or .db. A password with special characters needs them URL-encoded, the same as in any other connection string.
Query parameters are passed to the connection, so ?sslmode=require or ?charset=latin1 works as it would in a Laravel database.php.
No error message ever contains the connection string. A connection failure names the driver, host, port and database, and never the user or password, so it is safe to leave in a CI log.
When the connection fails
A connection that cannot be opened exits 2, whatever the reason. The message says which kind of failure it was. Before v1.15.5, every failure read as a network problem.
| Message | What it means | What to check |
|---|---|---|
The database refused the user name or password | The server answered and rejected the login | The user name and password in the connection string |
The database does not exist on its server | The server answered and has no database by that name | The database name in the connection string |
There is no SQLite file for the database | The SQLite path has no file behind it | The path in the connection string |
Truss could not reach the database | No server answered | The host, the port, and whether this machine needs a VPN or an allow-listed address |
A wrong password, for example:
The database refused the user name or password: mysql at 127.0.0.1:3306/shop.The server answered, so this is not a network problem. Check the credentials in the connection string.The refused and does-not-exist messages work on MySQL, MariaDB and PostgreSQL. On PostgreSQL, the refused message also covers an unknown user on a server that does not ask for a password. When both the password and the database name are wrong, the server rejects the login first, so the message is about the credentials. A PHP that lacks the PDO extension for your database also reads as “could not reach” (php -m shows which extensions you have).
If the connection opens but the structure cannot be read, the command prints Could not load the schema: and the reason, and exits 2. The reason is the driver’s own error, with any password from the connection strings replaced by [redacted]. It can still name the user, as in MySQL’s SELECT command denied to user 'shop'@'10.0.0.4'.
Exit codes
The same as the artisan commands, which is what makes the binary safe to put in CI:
| Code | Meaning |
|---|---|
0 | Clean: the command ran and found nothing to fail on |
1 | doctor found something at the --fail-on level, or export --check found drift |
2 | Anything else: a bad connection string, an unreachable host, a refused user name or password, a database name the server does not have, a SQLite file that is not there, a schema that cannot be read, an unknown command or option, a PHP older than 8.2 |
A 2 never means your schema has a problem. An unreachable host can never be mistaken for a schema with findings, so a CI step that fails on 1 and on 2 tells you which it was.
truss show
The structure as a terminal table: one row per table, with its column count and foreign-key count.
truss showIf the structure cannot be read after connecting, it prints Could not load the schema: and exits 2, the same as doctor and export. Before v1.15.5 it printed a raw exception and exited 1.
truss export
Writes the structure to stdout, or to a file with --output. The formats are the package’s: see the Schema export guide for what each one is for.
truss export --format=dbmltruss export --format=mermaid --output=docs/schema.mmdtruss export --format=llm --focus=orders --depth=2truss export --format=html --output=schema.html| Option | |
|---|---|
--format | dbml (the default), json, csv, markdown, mermaid, llm or html |
--tables | Only these tables, comma-separated |
--exclude | Skip these tables, comma-separated, applied after --tables |
--focus | Reduce to this table and its foreign-key neighbourhood |
--depth | How many hops --focus reaches (default 1) |
--compact | Drop defaults and non-unique indexes to shrink the output |
--no-annotations | Strip annotations from the export |
--mermaid | html only: inline (self-contained, the default) or cdn (a small file that needs a network to render) |
--output | Write to this file instead of stdout. Required for html |
--check | Compare against --output and exit 1 if it would change. Writes nothing |
--check is the drift check for CI: commit an export, and the build fails when the database no longer matches it.
truss export --format=dbml --output=schema.dbml --checktruss doctor
Reviews the structure for problems: integrity, indexing and column types. It is the same rule set as Schema doctor, with the same findings in the same order. truss check is an alias.
truss doctortruss doctor --preset=strict --fail-on=warningtruss doctor --table=orders --format=json| Option | |
|---|---|
--table | Review only this table |
--only | Only these categories, comma-separated: integrity, index, type |
--skip | Skip these categories, comma-separated |
--preset | recommended (the default), strict or none |
--format | console (the default) or json |
--fail-on | The lowest severity that exits 1: error (the default), warning, info or never |
truss diff
Compares two live databases, for example staging against production, right now. This is the one thing the binary does that the package cannot.
Inside a Laravel application, truss:diff answers “what changed since the last migration”, which is a question about time. Given two connection strings, truss diff answers “what differs between these two databases”, which is a question about place. No migration and no baseline are involved: both sides are read live.
TRUSS_DSN="$STAGING_DSN" TRUSS_AGAINST_DSN="$PRODUCTION_DSN" truss diffThe second database is read from TRUSS_AGAINST_DSN, for the same reason the first is read from TRUSS_DSN: a connection string passed as an argument lands in shell history and is visible in ps. --against is there for when you need it, and when both are given it wins, just as --dsn wins over TRUSS_DSN.
Direction matters. TRUSS_DSN is the current state and TRUSS_AGAINST_DSN is what it is compared to, so a table only staging has reads as added, and a table only production has reads as removed.
The report names both sides with the driver, host and database, and neither set of credentials.
In CI
A GitHub Actions job that prints what differs between staging and production on every push, with both connection strings held as repository secrets:
name: Schema drift
on: [push]
jobs: diff: runs-on: ubuntu-latest steps: - uses: shivammathur/setup-php@v2 with: php-version: '8.4' extensions: pdo_pgsql
- name: Download truss run: | curl -L -o truss https://github.com/albertoarena/laravel-truss/releases/latest/download/truss.phar chmod +x truss
- name: Staging against production env: TRUSS_DSN: ${{ secrets.STAGING_DSN }} TRUSS_AGAINST_DSN: ${{ secrets.PRODUCTION_DSN }} run: ./truss diffThe runner needs network access to both databases, which for most production databases means a self-hosted runner or an allow-listed address. If either connection cannot be opened, the step exits 2 and fails, naming which database it was.
Who can run it
Whoever holds the connection string. The binary has no dashboard, no route and nothing to log in to, so there is nothing for an authorization gate to protect. The credentials are the protection: a user who can run truss against a database could already connect to it with any other client.
What it reads is the same as the package: structure, and never row data.
Not in the binary
open and rebuild exist only as artisan commands. truss:open opens the dashboard, and the binary has no dashboard to open. truss:rebuild refreshes the cached snapshot, and the binary keeps no cache between runs: every command reads the database live.