I'm testing Yii to see it's benefits. I like yii a lot but when it comes to Postgresql connections I have some problems.
My db model uses different schemas for holding different data, but when I tried to inherit PgSqlSchema I noticed that schema was a constant 'DEFAULT_SCHEMA'. Is there any way to use Postgresql schemas extending PgsqlSchema class without lot of function rewriting? I need to do something like "SET search_path 'schema1,schema2,schema3'"
So your sequence relies on search_path? You can extend CDbConnection and override its init() method. In the method, after calling the parent's init(), you can execute this command to set the search_path.
In your app config, when you configure 'db', you need to specify its 'class' option to point to your new DB connection class.
It's because you are relying on search path to look for schema name. Yii has no way to know the exact schema name if the squence name is given without schema name.
Im sorry for digging out an old topic, but i have problem similar to its autor one. How can i set schema to work with? I have my db in other than ‘public’ schema, and i couldnt find where to set it. For my purpose i had to set DEFAULT_SCHEMA in CPgsqlSchema to be my schema. How to do it proper way?
edit:
changing DEFAULT_SCHEMAdid nothing, cause selects still use public schema
In Postgres de default search path is "$user", public
If you can create a role with the same name as the schema you would not have problems, the other way is to change the postgres configuration but its not good idea.
In Yii it would be nice to have another conection parameter like:
‘schema’=>‘myschema’
I used the Qiang recomendation and worked fine.
in protected/components/MydbConection.php
class MydbConection extends CDbConnection {
protected function initConnection($pdo)
{
parent::initConnection($pdo);
$stmt=$pdo->prepare("set search_path to yourschema, public");
$stmt->execute();
}
}