İçeriğe geç →

Using PostgreSQL MultiSchema in Laravel

Nowadays in our team needed to work with a multischema database system but there is no article about that problem.

Imagine we have 2 schemas that have lots of table in PostgreSQL in order to interact between Eloquent ORM and schemas, you need to change Laravel migrations, models and some configs

PostgreSQL Creation Schema

CREATE SCHEMA john
CREATE SCHEMA doe

First of all Start with Configs

configs/database.php

'migrations' => 'john.migrations',

Change migrations table schema path

configs/queue.php

'failed' => [
'table' => 'john.failed_jobs',
],

Change failed_jobs table schema path

Migrations

Every table needs one schema and the default schema is public in postgresql in order to change table schema in migrations lets look at the below example.

Schema::create('doe.users', function (Blueprint $table) {

Eloquent Model

Link with schema and table in the model

class User extends Model
{
/**
*
@var string
*/
protected $table = 'joe.users';

Conclusion

Through those steps we can interact with PostgreSQL Multi schema system

Kategori: php

Yorumlar

Bir cevap yazın