### DBDiff Configuration File Example Source: https://dbdiff.github.io/DBDiff Example `dbdiff.yml` configuration file. Sets up connection parameters for two servers, specifies the driver, and defines diffing options like type and include. ```yaml # ── Diff command (./dbdiff server1.db:server2.db) ───────────────────────── server1: user: user password: password port: 3306 # MySQL: 3306 | PostgreSQL: 5432 host: localhost server2: user: user password: password port: 3306 host: host2 driver: mysql # mysql | pgsql | sqlite type: all include: all nocomments: true # ── Filtering ───────────────────────────────────────────────────────────── # Include list — only these tables are diffed (supports globs: *, ?). # When set, only matching tables are included. Omit to diff all tables. # tables: # - users # - orders # - wp_* # Exclude list — skip these tables entirely (supports globs). tablesToIgnore: - table1 - table2 # Exclude from data diff only — schema is still diffed (supports globs). # tablesDataToIgnore: # - audit_log # - event_stream ``` -------------------------------- ### DBDiff Output Example Source: https://dbdiff.github.io/DBDiff This is an example of the expected output when running DBDiff. It indicates the progress of schema diff calculation, migration file generation, and completion. ```bash ℹ Now calculating schema diff for table `foo` ℹ Now generating UP migration ℹ Writing migration file to /path/to/dbdiff/migration.sql ✔ Completed ``` -------------------------------- ### Make Binary Executable and Run Source: https://dbdiff.github.io/DBDiff After downloading a pre-built binary, make it executable and optionally move it to your system's PATH. Then, you can run it with the --version flag to verify the installation. ```bash chmod +x dbdiff-linux-x64 sudo mv dbdiff-linux-x64 /usr/local/bin/dbdiff dbdiff --version ``` -------------------------------- ### Install DBDiff via npm Source: https://dbdiff.github.io/DBDiff Install the DBDiff CLI globally using npm. This command ensures the latest version is available on your system. Verify the installation by checking the version. ```bash npm install -g @dbdiff/cli dbdiff --version ``` -------------------------------- ### Make PHAR Executable and Run Source: https://dbdiff.github.io/DBDiff Download the PHAR file and make it executable. Move it to your system's PATH for easy access. Verify the installation by checking the version. ```bash chmod +x dbdiff.phar sudo mv dbdiff.phar /usr/local/bin/dbdiff dbdiff --version ``` -------------------------------- ### Clone DBDiff Repository and Install Dependencies Source: https://dbdiff.github.io/DBDiff Clone the DBDiff repository from GitHub and install its dependencies using Composer. This is for source installs and requires PHP and Composer. ```bash git clone https://github.com/DBDiff/DBDiff.git cd DBDiff composer install --optimize-autoloader ``` -------------------------------- ### Run DBDiff from Source Install Source: https://dbdiff.github.io/DBDiff After installing DBDiff from source (e.g., via git clone and composer install), you can run it directly using a relative path. This command compares two databases. ```bash ./dbdiff server1.db1:server1.db2 ``` -------------------------------- ### Install DBDiff via npm from GitHub Packages Source: https://dbdiff.github.io/DBDiff If npmjs.org is unavailable, you can install the DBDiff CLI globally from GitHub Packages using this command. Ensure you have the correct registry URL. ```bash npm install -g @dbdiff/cli --registry=https://npm.pkg.github.com ``` -------------------------------- ### Diff Neon Branches Source: https://dbdiff.github.io/DBDiff Compare two Neon branches directly by providing their respective --server-url parameters. This example also specifies the output format and adds a description for the migration. ```bash ./dbdiff \ --server1-url postgres://user:pass@main-branch.hostname.neon.tech/mydb \ --server2-url postgres://user:pass@feature-branch.hostname.neon.tech/mydb \ --format=flyway --description=my_feature ``` -------------------------------- ### Build Full DBDiff Docker Image Locally Source: https://dbdiff.github.io/DBDiff Build the full Docker image locally. This method uses Composer to install from source and does not require a pre-compiled PHAR file. ```bash # Full image (Composer install from source — no PHAR needed) docker build -f docker/Dockerfile -t dbdiff:full . ``` -------------------------------- ### Cross-Version Testing with DBDiff Source: https://dbdiff.github.io/DBDiff Starts DBDiff locally for a single combination of PHP and MySQL versions, or for all combinations in parallel. Refer to DOCKER.md for additional flags. ```bash # Single combination ./start.sh 8.3 8.0 ``` ```bash # All 16 combinations in parallel ./start.sh all all --parallel ``` -------------------------------- ### Build Local PHAR Archive Source: https://dbdiff.github.io/DBDiff Installs dependencies and compiles the PHAR archive locally using Box. The output PHAR is located in `dist/dbdiff.phar`. ```bash composer install vendor/bin/box compile ``` -------------------------------- ### Install DBDiff Globally via Composer Source: https://dbdiff.github.io/DBDiff Install DBDiff globally for your user account using Composer. This makes the DBDiff command available system-wide. ```bash composer global require "dbdiff/dbdiff:@dev" ``` -------------------------------- ### Supabase Diff with Local Stack Auto-fill Source: https://dbdiff.github.io/DBDiff Performs a diff between a remote Supabase database and the local Supabase stack. The local connection details are automatically filled in when `supabase start` is running. ```bash # Only supply the remote (production) URL — local stack fills in automatically ./dbdiff diff --server2-url='postgres://user:pass@db.yyyy.supabase.co:5432/postgres' ``` -------------------------------- ### Add DBDiff as a Composer Project Dependency Source: https://dbdiff.github.io/DBDiff Install DBDiff as a development dependency for your project using Composer. This command adds the specified version to your composer.json file. ```bash composer require "dbdiff/dbdiff:@dev" ``` -------------------------------- ### Scaffold New Migration (Supabase Format) Source: https://dbdiff.github.io/DBDiff Creates a new migration file in the Supabase format (`.sql`, UP only). Use when migrating existing Supabase projects or when rollback is not needed. ```bash # Scaffold a Supabase-format migration (plain .sql, no DOWN file) ./dbdiff migration:new create_users_table --format=supabase ``` -------------------------------- ### Build Slim DBDiff Docker Image Locally Source: https://dbdiff.github.io/DBDiff Build the slim Docker image locally. This requires the PHAR file to be compiled first using `vendor/bin/box compile`. Replace 'docker' with 'podman' if you are using Podman. ```bash # Slim image (requires dist/dbdiff.phar — run `vendor/bin/box compile` first) # Replace 'docker' with 'podman' if using Podman docker build -f docker/Dockerfile.slim -t dbdiff:slim . docker run --rm dbdiff:slim --version ``` -------------------------------- ### Connect to Supabase Source: https://dbdiff.github.io/DBDiff Use the --supabase flag for a shorthand connection to Supabase, which automatically sets the driver to pgsql and enables SSL. ```bash ./dbdiff --supabase --server1=user:pass@db.xxx.supabase.co:5432 server1.mydb:server1.mydb ``` -------------------------------- ### Scaffold New Migration (Native Format) Source: https://dbdiff.github.io/DBDiff Creates a new migration file in the default DBDiff native format (`.up.sql` and `.down.sql`). Use for new projects requiring rollback support. ```bash # Scaffold a new migration (DBDiff native format) ./dbdiff migration:new create_users_table ``` -------------------------------- ### Release DBDiff with Scripts Source: https://dbdiff.github.io/DBDiff Executes release scripts for building the PHAR, tagging the release, and pushing to origin. Also includes commands for building binaries locally and uploading assets to GitHub Releases. ```bash # Build PHAR + tag scripts/release.sh v2.1.0 git push origin v2.1.0 ``` ```bash # Build Linux binaries locally (requires Podman or Docker) SKIP_PHAR=1 scripts/release-binaries.sh 2.1.0 ``` ```bash # Upload assets to an existing GitHub Release gh release upload v2.1.0 --clobber \ dist/dbdiff.phar \ packages/@dbdiff/cli-linux-x64/dbdiff \ packages/@dbdiff/cli-linux-x64-musl/dbdiff \ packages/@dbdiff/cli-linux-arm64/dbdiff \ packages/@dbdiff/cli-linux-arm64-musl/dbdiff ``` ```bash # Update the Homebrew tap formula scripts/update-homebrew-formula.sh 2.1.0 ../homebrew-dbdiff ``` -------------------------------- ### Command: diff Source: https://dbdiff.github.io/DBDiff Generates a migration file by comparing two database sources or tables. ```APIDOC ## diff ### Description Compares two database sources or tables and generates a migration file. Flags override settings defined in the .dbdiff configuration file. ### Parameters #### Query Parameters - **--server1** (string) - Optional - Source connection string (user:pass@host:port). - **--server2** (string) - Optional - Target connection string (user:pass@host:port). - **--server1-url** (string) - Optional - Full DSN URL for source. - **--server2-url** (string) - Optional - Full DSN URL for target. - **--driver** (string) - Optional - Database driver (mysql, pgsql, sqlite). Defaults to mysql. - **--format** (string) - Optional - Output format (native, flyway, liquibase-xml, liquibase-yaml, laravel). Defaults to native. - **--type** (string) - Optional - What to diff (schema, data, all). Defaults to schema. - **--include** (string) - Optional - Directions to include (up, down, both/all). Defaults to up. - **--tables** (string) - Optional - Comma-separated list of tables to include. - **--ignore-tables** (string) - Optional - Comma-separated list of tables to exclude. ``` -------------------------------- ### Pull and Run DBDiff Podman Image Source: https://dbdiff.github.io/DBDiff Pull the pre-built DBDiff image for Podman. The commands are identical to Docker. Run it to check the version or perform a database diff, specifying the driver and server details. ```bash podman pull ghcr.io/dbdiff/dbdiff podman run --rm ghcr.io/dbdiff/dbdiff --version podman run --rm ghcr.io/dbdiff/dbdiff --driver=mysql \ --server1=user:pass@host:3306 server1.mydb:server1.mydb ``` -------------------------------- ### Scaffold New Migration (Supabase Auto-Detection) Source: https://dbdiff.github.io/DBDiff Creates a new migration file within a Supabase project directory. The format and migration directory (`supabase/migrations/`) are automatically detected. ```bash # Inside a Supabase project, format and directory are auto-detected: cd my-supabase-project # contains supabase/config.toml ./dbdiff migration:new create_users_table # → supabase/migrations/{ts}_create_users_table.sql ``` -------------------------------- ### Basic DBDiff Configuration Source: https://dbdiff.github.io/DBDiff Defines database connection details and migration settings. Ensure your database credentials and migration directory are correctly specified. ```yaml database: driver: mysql host: localhost port: 3306 name: mydb user: root password: secret migrations: dir: ./migrations history_table: _dbdiff_migrations ``` -------------------------------- ### Basic MySQL Database Diff Source: https://dbdiff.github.io/DBDiff Compares two MySQL databases using default settings. Ensure servers are accessible. ```bash ./dbdiff server1.db1:server2.db2 ``` -------------------------------- ### Diff SQLite Databases Source: https://dbdiff.github.io/DBDiff Use the --driver=sqlite option to compare SQLite databases. The database file path is provided as the database name. ```bash ./dbdiff --driver=sqlite server1./path/to/source.db:server1./path/to/target.db ``` -------------------------------- ### MySQL Diff with Flyway Format and Output Path Source: https://dbdiff.github.io/DBDiff Compares MySQL databases using Flyway format, including all objects, and specifies an output directory for SQL diffs. Useful for integrating with Flyway workflows. ```bash ./dbdiff --format=flyway --description=add_users --include=all \ server1.db1:server2.db2 --output=./sql/ ``` -------------------------------- ### Apply All Pending Migrations Source: https://dbdiff.github.io/DBDiff Applies all migrations that have not yet been applied to the target database. Requires a database URL. ```bash # Apply all pending migrations ./dbdiff migration:up --db-url='postgres://user:pass@localhost:5432/mydb' ``` -------------------------------- ### Supabase Database Diff Source: https://dbdiff.github.io/DBDiff Compares two Supabase databases, automatically detecting Supabase-specific configurations. Requires Supabase credentials. ```bash ./dbdiff --supabase --server1=postgres:pass@db.xxxx.supabase.co:5432 \ server1.staging:server1.production ``` -------------------------------- ### Migration Runner Commands Source: https://dbdiff.github.io/DBDiff Commands for managing and applying database migrations. ```APIDOC ## Migration Runner ### Description Built-in commands to manage database migrations, including scaffolding, applying, rolling back, and validating migration states. ### Commands - **migration:new ** - Scaffold a new migration file. - **migration:up** - Apply all pending migrations. - **migration:down** - Roll back applied migration(s). - **migration:status** - Show applied vs pending migrations. - **migration:validate** - Verify on-disk checksums match the history table. - **migration:repair** - Remove failed entries. - **migration:baseline** - Mark current DB state as the migration baseline. ``` -------------------------------- ### PostgreSQL Database Diff Source: https://dbdiff.github.io/DBDiff Compares two PostgreSQL databases using explicit driver and server connection details. Ensure correct user, password, host, and port are provided. ```bash ./dbdiff --driver=pgsql --server1=user:pass@localhost:5432 server1.staging:server1.production ``` -------------------------------- ### Command: url:encode Source: https://dbdiff.github.io/DBDiff Percent-encodes a raw password for safe embedding in connection strings. ```APIDOC ## url:encode ### Description Percent-encodes a raw password to ensure it is safe for use in DSN URLs, handling special characters like @, #, ?, /, +, and %. ``` -------------------------------- ### SQLite Database Diff Source: https://dbdiff.github.io/DBDiff Compares two SQLite database files using the SQLite driver. Provide paths to the database files. ```bash ./dbdiff --driver=sqlite server1./var/db/v1.db:server1./var/db/v2.db ``` -------------------------------- ### DBDiff Output Formats Source: https://dbdiff.github.io/DBDiff Demonstrates various output formats supported by DBDiff for integration with different migration tools. Choose the format that best suits your workflow. ```text `native` (default) | Plain SQL | Any | `migration.sql` | Up, down, or both `flyway` | Flyway | Java | `V{ts}__{desc}.sql` | Down adds `U{ts}__{desc}.sql` (Flyway Teams) `liquibase-xml` | Liquibase | Java | `changelog.xml` | Both directions in one file `liquibase-yaml` | Liquibase | Java | `changelog.yaml` | Both directions in one file `laravel` | Laravel Migrations | PHP | `YYYY_MM_DD_HHMMSS_{desc}.php` | `up()`/`down()` methods _(template)_ | Simple DB Migrate | Python | custom | Use `--template=templates/simple-db-migrate.tmpl` ``` -------------------------------- ### Pull and Run DBDiff Docker Image Source: https://dbdiff.github.io/DBDiff Pull the pre-built DBDiff Docker image from GHCR. You can then run it to check the version or perform a database diff, specifying the driver and server details. ```bash docker pull ghcr.io/dbdiff/dbdiff docker run --rm ghcr.io/dbdiff/dbdiff --version docker run --rm ghcr.io/dbdiff/dbdiff --driver=mysql \ --server1=user:pass@host:3306 server1.mydb:server1.mydb ``` -------------------------------- ### Generate Diff with Rollback Source: https://dbdiff.github.io/DBDiff Include both UP and DOWN migrations in the generated output. ```bash dbdiff diff --include=all ... ``` -------------------------------- ### Database Diff using DSN URLs Source: https://dbdiff.github.io/DBDiff Compares two databases using full DSN URLs for connection strings. This method is flexible for various database types and connection parameters. ```bash ./dbdiff diff \ --server1-url='postgres://user:pass@db.xxxx.supabase.co:5432/postgres' \ --server2-url='postgres://user:pass@db.yyyy.supabase.co:5432/postgres' ``` -------------------------------- ### Validate Migration Checksums Source: https://dbdiff.github.io/DBDiff Verifies the integrity of migration files by checking their checksums against the database. Helps detect accidental modifications. ```bash # Validate checksums ./dbdiff migration:validate --db-url='postgres://user:pass@localhost:5432/mydb' ``` -------------------------------- ### DSN URLs with Password Encoding Source: https://dbdiff.github.io/DBDiff Compares databases using DSN URLs when passwords contain special characters. Use `dbdiff url:encode` to safely encode the password before including it in the URL. ```bash PASS=$(dbdiff url:encode 'my$ecret#pass@word%123') ./dbdiff diff \ --server1-url="postgres://user:${PASS}@db.xxxx.supabase.co:5432/postgres" \ --server2-url='postgres://user:pass@db.yyyy.supabase.co:5432/postgres' ``` -------------------------------- ### Diff Dolt Branches Source: https://dbdiff.github.io/DBDiff Compare two branches of a Dolt database by specifying the database name with the branch name appended after a colon. ```bash ./dbdiff server1.main:server1.feature_add_users ``` -------------------------------- ### Encode Password for DSN Source: https://dbdiff.github.io/DBDiff Percent-encode a password for safe use in connection strings. ```bash dbdiff url:encode '' ``` ```bash PASS=$(dbdiff url:encode 'my$ecret#pass@word%123') dbdiff diff \ --server1-url="postgres://user:${PASS}@db.xxxx.supabase.co:5432/postgres" \ --server2-url="postgres://user:pass@db.yyyy.supabase.co:5432/postgres" ``` ```bash echo 'my$ecret#pass' | dbdiff url:encode ``` ```bash PASS=$(scripts/encode-password.sh 'my$ecret#pass@word%123') ``` -------------------------------- ### Check Migration Status Source: https://dbdiff.github.io/DBDiff Displays the status of all migrations, indicating which have been applied. Includes a 'Supa?' column when run inside a Supabase project. ```bash # Check status (adds a Supa? column inside Supabase projects) ./dbdiff migration:status --db-url='postgres://user:pass@localhost:5432/mydb' ``` -------------------------------- ### Table Inclusion and Exclusion Source: https://dbdiff.github.io/DBDiff Specify which tables to include in the diff and which to exclude entirely. Supports glob patterns for flexible matching. ```yaml # Only diff tables matching these patterns tables: - users - orders - wp_* # Skip these tables entirely tablesToIgnore: - cache_* - _dbdiff_migrations ``` -------------------------------- ### MySQL Data Diff Only Source: https://dbdiff.github.io/DBDiff Performs a data-only comparison for a specific table in MySQL, ignoring comments. Use for focused data validation. ```bash ./dbdiff server1.dev.table1:server2.prod.table1 --nocomments --type=data ``` -------------------------------- ### Roll Back Last Migration Source: https://dbdiff.github.io/DBDiff Reverts the most recently applied migration. Use with caution as it modifies the database schema. ```bash # Roll back the last migration ./dbdiff migration:down --db-url='postgres://user:pass@localhost:5432/mydb' ``` -------------------------------- ### Per-Table Row Filtering Source: https://dbdiff.github.io/DBDiff Skip rows from data comparison based on a regular expression pattern applied to a specific column. This allows fine-grained control over data diffing. ```yaml # Skip rows matching column-value regex rowsToIgnore: wp_options: - { column: option_name, pattern: "_transient_.*" } sessions: - { column: status, pattern: "expired|archived" } ``` -------------------------------- ### Data-Only Table Exclusion Source: https://dbdiff.github.io/DBDiff Exclude tables from data comparison while still including them for schema comparison. Useful for large tables where only schema changes are relevant. ```yaml # Skip data diff for these (schema is still compared) tablesDataToIgnore: - audit_log ``` -------------------------------- ### Per-Table Column Exclusion Source: https://dbdiff.github.io/DBDiff Exclude specific columns from schema and data comparison on a per-table basis. Supports glob patterns for table names. ```yaml # Exclude columns per table (keys support globs) fieldsToIgnore: users: - updated_at - last_login wp_*: - ID ``` -------------------------------- ### Per-Table Scope Override Source: https://dbdiff.github.io/DBDiff Override the default comparison scope (schema + data) for specific tables. Can be set to 'schema' or 'data' only. ```yaml # Override scope per table: schema | data | all tableScope: audit_log: schema config: data ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.