Reputation: 1077
I'm using PostgreSQL with Laravel. I have created a new Schema
in my postgresql Database and setup pgsql
driver in my laravel project. But when I migrate all migration by-default load in public
Schema. I want to load all migration in self-defined Schema
. How Can I do this.
Here, my .env
and app/config/database
file configuration.
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:qqv8sHot0EBDj4fZXedwaxY4Xb+O4ynEzLgyKTLtW88=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=dbtuto
DB_USERNAME=postgres
DB_PASSWORD=root
app/config/database file configuration.
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', ''),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'dbtutoschema',
'sslmode' => 'prefer',
],
Note:dbtutoschema
is my self-defined schema I want to load all migration under this Schema.
Upvotes: 2
Views: 1146
Reputation: 3341
Set the search_path in a general statement.
// Retrieve the current search path in a select query
$sp_res = DB::select('SHOW search_path');
$current_search_path = $sp_res[0]->search_path;
// Set a new search path
$search_path = 'my_schema';
DB::statement("SET search_path TO $search_path");
Upvotes: 1