Skip to content

Commands

The binary has four commands. Every one reads the database named by TRUSS_DSN, or by --dsn when it is given.

CommandWhat it does
truss showPrint the structure as a table in the terminal
truss exportWrite the structure in one of seven formats
truss doctorReview the structure for problems
truss diffCompare 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

DatabaseConnection string
MySQLmysql://user:pass@host:3306/database
MariaDBmariadb://user:pass@host:3306/database
PostgreSQLpgsql://user:pass@host:5432/database
SQLitesqlite:/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.

MessageWhat it meansWhat to check
The database refused the user name or passwordThe server answered and rejected the loginThe user name and password in the connection string
The database does not exist on its serverThe server answered and has no database by that nameThe database name in the connection string
There is no SQLite file for the databaseThe SQLite path has no file behind itThe path in the connection string
Truss could not reach the databaseNo server answeredThe 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:

CodeMeaning
0Clean: the command ran and found nothing to fail on
1doctor found something at the --fail-on level, or export --check found drift
2Anything 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.

Terminal window
truss show

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

Terminal window
truss export --format=dbml
truss export --format=mermaid --output=docs/schema.mmd
truss export --format=llm --focus=orders --depth=2
truss export --format=html --output=schema.html
Option
--formatdbml (the default), json, csv, markdown, mermaid, llm or html
--tablesOnly these tables, comma-separated
--excludeSkip these tables, comma-separated, applied after --tables
--focusReduce to this table and its foreign-key neighbourhood
--depthHow many hops --focus reaches (default 1)
--compactDrop defaults and non-unique indexes to shrink the output
--no-annotationsStrip annotations from the export
--mermaidhtml only: inline (self-contained, the default) or cdn (a small file that needs a network to render)
--outputWrite to this file instead of stdout. Required for html
--checkCompare 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.

Terminal window
truss export --format=dbml --output=schema.dbml --check

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

Terminal window
truss doctor
truss doctor --preset=strict --fail-on=warning
truss doctor --table=orders --format=json
Option
--tableReview only this table
--onlyOnly these categories, comma-separated: integrity, index, type
--skipSkip these categories, comma-separated
--presetrecommended (the default), strict or none
--formatconsole (the default) or json
--fail-onThe 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.

Terminal window
TRUSS_DSN="$STAGING_DSN" TRUSS_AGAINST_DSN="$PRODUCTION_DSN" truss diff

The 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 diff

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