You can dump the structure with php artisan schema dump then use it for tests.
Set different folder for local/production and test migrations
I have an app which was written in a different language and has an existing database, which I am trying to create a Laravel version of (Laravel 11.x). The local/production database is already setup with tables (as the local database is a copy of the production), however I would like to create migrations for these tables to use in tests. There are certain migrations I would like to be performed in both test and production. So my thought was to have separate folder for migrations for the test and production.
I tried creating a folder called database/migrations_production where I would copy over any migrations which I would want to run on the production database, and I was hoping to use the default database/migrations folder for the test migrations. And I tried to add the following code in the AppServiceProvider (based on a suggestion from ChatGPT/Larry):
/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
$this->configureMigrationPaths();
}
/**
* Configure the migration paths based on the environment.
*
* @return void
*/
protected function configureMigrationPaths()
{
$migrator = $this->app->make('migrator');
// Clear existing migration paths
$migrator->paths([]);
// Determine the appropriate migration path
$migrationPath = database_path('migrations');
if ($this->app->environment('local', 'production')) {
$migrationPath = database_path('migrations_production');
}
// Set the migration path
$migrator->path($migrationPath);
// Debugging output to verify the path
\Log::info('Migration path set to: ' . $migrationPath);
echo 'Migration path set to: ' . $migrationPath . PHP_EOL;
}
However, when I run php artisan migrate:status, even though the debugging output at the end of the function shows the correct paths, the status shows all the migrations in the default migration folder.
Please help with any solutions on how to tackle this situation.
Please or to participate in this conversation.