### Install Migrate DB Package Source: https://context7.com/thedragoncode/migrate-db/llms.txt Instructions for installing the Migrate DB package as a development dependency using Composer. ```bash composer require dragon-code/migrate-db --dev ``` ```json { "require-dev": { "dragon-code/migrate-db": "^3.0" } } ``` -------------------------------- ### Install Migrate DB using Composer Source: https://github.com/thedragoncode/migrate-db/blob/main/README.md Installs the Migrate DB package using Composer. This is the recommended method for adding the package to your Laravel project and ensures you have the latest stable version. ```bash composer require dragon-code/migrate-db --dev ``` -------------------------------- ### Basic Database Migration Source: https://context7.com/thedragoncode/migrate-db/llms.txt Performs a full database migration, copying all tables and data from a source to a target connection. It handles foreign keys and uses chunked queries for efficiency. Interactive prompts guide the user through options like truncating and dropping tables. ```bash php artisan db:migrate --schema-from=mysql_old --schema-to=mysql_new ``` -------------------------------- ### Configure Migrate DB in composer.json Source: https://github.com/thedragoncode/migrate-db/blob/main/README.md Manually add the Migrate DB package to your project's development dependencies by updating the composer.json file. After modification, run 'composer update' to install the package. ```json { "require-dev": { "dragon-code/migrate-db": "^3.0" } } ``` -------------------------------- ### Perform Cross-Database Migrations (Bash) Source: https://context7.com/thedragoncode/migrate-db/llms.txt Execute database migrations between different systems such as MySQL, PostgreSQL, and SQL Server using Artisan commands. This functionality automatically handles data type conversions and constraint differences. ```bash # MySQL to PostgreSQL migration php artisan db:migrate --schema-from=mysql --schema-to=pgsql # PostgreSQL to MySQL migration php artisan db:migrate --schema-from=pgsql --schema-to=mysql # MySQL to SQL Server migration php artisan db:migrate --schema-from=mysql --schema-to=sqlsrv # Example connection setup for cross-database migration in config/database.php: # 'connections' => [ # 'mysql' => [ # 'driver' => 'mysql', # 'host' => '127.0.0.1', # 'database' => 'source_db', # 'username' => 'mysql_user', # 'password' => 'mysql_pass', # ], # 'pgsql' => [ # 'driver' => 'pgsql', # 'host' => '127.0.0.1', # 'database' => 'target_db', # 'username' => 'postgres_user', # 'password' => 'postgres_pass', # ], # ] ``` -------------------------------- ### Programmatic Database Builder Access (PHP) Source: https://context7.com/thedragoncode/migrate-db/llms.txt Utilize the BuilderManager facade to programmatically interact with database builders for custom migration tasks. This allows for fine-grained control over database operations, including fetching tables, managing constraints, and executing custom data transfer logic. ```php get(); // Get all tables from the connection (excludes 'migrations' table) $tables = $builder->getAllTables(); // Returns: ['users', 'orders', 'products', ...] // Get the primary key column for a specific table $primaryKey = $builder->getPrimaryKey('users'); // Returns: 'id' // Drop all tables in the database $builder->dropAllTables(); // Disable foreign key constraints (useful before bulk operations) $builder->disableForeign(); // Enable foreign key constraints $builder->enableForeign(); // Access the underlying Laravel schema builder $schemaBuilder = $builder->schema(); $columns = $schemaBuilder->getColumnListing('users'); // Returns: ['id', 'name', 'email', 'password', 'created_at', 'updated_at'] // Example: Custom migration with progress tracking $sourceBuilder = BuilderManager::of('mysql_old')->get(); $targetBuilder = BuilderManager::of('mysql_new')->get(); $targetBuilder->disableForeign(); foreach ($sourceBuilder->getAllTables() as $table) { $primaryKey = $sourceBuilder->getPrimaryKey($table); DB::connection('mysql_old') ->table($table) ->orderBy($primaryKey) ->chunk(1000, function ($records) use ($table) { DB::connection('mysql_new') ->table($table) ->insert($records->toArray()); }); echo "Migrated table: {$table}\n"; } $targetBuilder->enableForeign(); ``` -------------------------------- ### Run Database Migration with Migrate DB Source: https://github.com/thedragoncode/migrate-db/blob/main/README.md Executes the database migration process using the Migrate DB Artisan command. This command transfers data between two specified database connections. ```bash php artisan db:migrate --schema-from=foo --schema-to=bar ``` -------------------------------- ### Database Driver Constants Reference (PHP) Source: https://context7.com/thedragoncode/migrate-db/llms.txt Provides constants for supported database drivers, enabling programmatic checks and conditional logic for different database types. This ensures compatibility and allows for flexible handling of various database systems within your application. ```php uuid('id')->primary(); $table->string('title'); $table->text('content'); $table->timestamps(); }); } }; ``` -------------------------------- ### Exclude Tables from Migration with Migrate DB Source: https://github.com/thedragoncode/migrate-db/blob/main/README.md Performs a database migration while excluding specific tables from the process. This is useful when you want to transfer most of the data but keep certain tables untouched. ```bash php artisan db:migrate --schema-from=foo --schema-to=bar --exclude=table1 --exclude=table2 ``` -------------------------------- ### PHP: Create Tables with ULID Primary Key Source: https://context7.com/thedragoncode/migrate-db/llms.txt This PHP code snippet shows how to define a table with a ULID primary key using Laravel's migration system (available from Laravel 9.30+). It sets up an 'events' table with an 'id' column of type ULID. ```php // Example migration with ULID primary key (Laravel 9.30+) return new class extends Migration { public function up() { Schema::create('events', function (Blueprint $table) { $table->ulid('id')->primary(); $table->string('name'); $table->timestamp('occurred_at'); $table->timestamps(); }); } }; ``` -------------------------------- ### Exclude Tables from Migration Source: https://context7.com/thedragoncode/migrate-db/llms.txt Migrates all tables except those specified using the --exclude option. This is useful for skipping large or temporary tables like logs or cache tables. ```bash php artisan db:migrate --schema-from=mysql_old --schema-to=mysql_new --exclude=logs --exclude=sessions ``` ```bash php artisan db:migrate --schema-from=mysql_old --schema-to=mysql_new \ --exclude=cache \ --exclude=jobs \ --exclude=failed_jobs \ --exclude=password_resets ``` ```bash php artisan db:migrate --schema-from=production --schema-to=staging \ --exclude=audit_logs \ --exclude=activity_log \ --exclude=telescope_entries ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.