I'm building an enviroment that needs two databases on one PGSQL database server for Laravel, the production one is named laravel, and the testing/dev one would be named laravel_test, is there any way to create the new database using database migrations in Laravel? I've been trying things like
$dbName = config("database.connections.pgsql-test.database");
// Create the second database
DB::statement("CREATE DATABASE $dbName");
but end up getting an error that states this:
SQLSTATE[25001]: Active sql transaction: 7 ERROR: CREATE DATABASE cannot run inside a transaction block (Connection: pgsql, SQL: CREATE DATABASE laravel_test)
I'm inexperienced when it comes to database specific operations like this, is there a way I could migrate a new Database using this primary (pgsql) DB connection: (config/database.php)
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'search_path' => 'public',
'sslmode' => 'prefer',
],
so that I could use this connection (pgsql-test):
'pgsql-test' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge') . "_test",
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'search_path' => 'public',
'sslmode' => 'prefer',
],
without manually creating a database?