S
S
Stanislav Khmelevsky2016-04-14 20:00:35
PostgreSQL
Stanislav Khmelevsky, 2016-04-14 20:00:35

Why doesn't Yii2 use defaultSchema in PostgreSQL?

There are VPS: Debian 8.3 , NGINX 1.8 , FPM , PHP7 , PostgreSQL 9.4 , Yii2 .
There is a website and a copy on a subdomain: site.io , dev.site.io
There are 2 schemes in the database: public and developer . The main site works on the public
scheme , everything is super. I created a dev subdomain and there was an urgent need to delete all data from the database. I created a developer scheme with a similar structure as on public In the Yii config I wrote:



db => [
    ...
    'schemaMap' => [
        'pgsql'=> [
            'class'=>'yii\db\pgsql\Schema',
            'defaultSchema' => 'developer',
        ]
    ],
];

  • Cleared the tables on the developer schema
  • Cleared the cache
  • Disable query caching
  • Disabled schema caching

Attention, question!
Why does a site on a subdomain continue to display data from the public schema?!
  • Both sites use the same username and password to connect.
  • When executing queries in the console, with an explicit schema in the query, everything works as it should
  • $table->fullNamein yii/db/pgsql/schemaoutputs developer.tablename, i.e. requests must go explicitly to the desired schema

In principle, if you uncomment the search_path
parameter in /etc/postgresql/9.4/main/postgresql.conf and add the necessary schemas to it,
then everything will be ok. But I think it's some kind of anal pain!
Or am I wrong, life is pain and everything is as it should be?
Help me figure it out please!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2016-04-15
@socode

The base plans weren't made for that.
Make for dev exactly a separate user and a separate database.

E
Elena Stepanova, 2016-04-24
@Insolita

in config

'db'=>[
         'class' => 'yii\db\Connection',
         .....
        'schemaMap' => [
                'pgsql' => [
                'class' => 'yii\db\pgsql\Schema',
                'defaultSchema' => 'myschema', //specify your schema here
                ]
        ],
         'on afterOpen' => function ($event) {
                $event->sender->createCommand("SET search_path TO myschema")->execute();
         }
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question