is gii schema aware? #1435

Closed
gitrad opened this Issue Dec 5, 2013 · 10 comments

Comments

Projects
None yet
4 participants
@gitrad
Contributor

gitrad commented Dec 5, 2013

it seems gii is not schema aware.
i deleted schema "public" ( in pgsql ) and created a new schema named: "office" with owner the role: "officeuser". i set dsn for this. but when i go to gii to create models it says there isnt any table ( but there is some ). is gii schema aware? is it possible to override default schema in application and/or in gii?

@nineinchnick

This comment has been minimized.

Show comment
Hide comment
@nineinchnick

nineinchnick Dec 5, 2013

Contributor

You can override which schema is searched by PostgreSQL when you don't specify it. Check out the paragraph about search path.

I think gii should allow to use '*' prefixed with schema name. It works when you put in the full prefixed table name.

Contributor

nineinchnick commented Dec 5, 2013

You can override which schema is searched by PostgreSQL when you don't specify it. Check out the paragraph about search path.

I think gii should allow to use '*' prefixed with schema name. It works when you put in the full prefixed table name.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 5, 2013

Member

@nineinchnick any idea how to implement it? I'm not into PostgreSQL for a long time and at the time we've used it it was default schema.

Member

samdark commented Dec 5, 2013

@nineinchnick any idea how to implement it? I'm not into PostgreSQL for a long time and at the time we've used it it was default schema.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 5, 2013

Member

Try entering office.* in the table field.

Member

qiangxue commented Dec 5, 2013

Try entering office.* in the table field.

@nineinchnick

This comment has been minimized.

Show comment
Hide comment
@nineinchnick

nineinchnick Dec 5, 2013

Contributor

Sorry, I didn't check. The code is there so it should work. So gii is schema aware and for non-default schema (public) changing the schema search path in PostgreSQL should be absolutely sufficient.

I'm going to confirm that in a sec.

Contributor

nineinchnick commented Dec 5, 2013

Sorry, I didn't check. The code is there so it should work. So gii is schema aware and for non-default schema (public) changing the schema search path in PostgreSQL should be absolutely sufficient.

I'm going to confirm that in a sec.

@nineinchnick

This comment has been minimized.

Show comment
Hide comment
@nineinchnick

nineinchnick Dec 5, 2013

Contributor

It's not working, it tries to match the table name with the schema prefixed to a pattern without it.

From vendor/yiisoft/yii2-gii/yii/gii/generators/model/Generator.php:

            foreach ($db->schema->getTableNames($schema) as $table) {
                if (preg_match($pattern, $table)) { 
                    $tableNames[] = $schema === '' ? $table : ($schema . '.' . $table);
                }
            }

$pattern is: '/^TABLE_PREFIX\w+$/', it should contain the schema. I'm going to make a PR in a sec.

Contributor

nineinchnick commented Dec 5, 2013

It's not working, it tries to match the table name with the schema prefixed to a pattern without it.

From vendor/yiisoft/yii2-gii/yii/gii/generators/model/Generator.php:

            foreach ($db->schema->getTableNames($schema) as $table) {
                if (preg_match($pattern, $table)) { 
                    $tableNames[] = $schema === '' ? $table : ($schema . '.' . $table);
                }
            }

$pattern is: '/^TABLE_PREFIX\w+$/', it should contain the schema. I'm going to make a PR in a sec.

@nineinchnick

This comment has been minimized.

Show comment
Hide comment
@nineinchnick

nineinchnick Dec 5, 2013

Contributor

Ignore anything about schema search path in this issue, this is not relevant because gii only uses catalog tables to find existing tables.

Contributor

nineinchnick commented Dec 5, 2013

Ignore anything about schema search path in this issue, this is not relevant because gii only uses catalog tables to find existing tables.

@gitrad

This comment has been minimized.

Show comment
Hide comment
@gitrad

gitrad Dec 5, 2013

Contributor

entering office.* doesn't work. but office.person ( the table name ) works.
with fix made by nineinchnick it makes no change for " office.* ".

Contributor

gitrad commented Dec 5, 2013

entering office.* doesn't work. but office.person ( the table name ) works.
with fix made by nineinchnick it makes no change for " office.* ".

@qiangxue qiangxue closed this in 64ef54b Dec 5, 2013

@gitrad

This comment has been minimized.

Show comment
Hide comment
@gitrad

gitrad Dec 5, 2013

Contributor

@qiangxue the fix did not work for me. changed public to office in yii\dbpgsql\schema.php manually (line:28):

public $defaultSchema = 'office';

and it worked. i have several backend each one with special db user and special schema granted to that user
( with "one" codebase and don't want touching the framework code.)
is there any way to override shema in every backend ( eg. in backend\config\params.php -> dsn ).

Contributor

gitrad commented Dec 5, 2013

@qiangxue the fix did not work for me. changed public to office in yii\dbpgsql\schema.php manually (line:28):

public $defaultSchema = 'office';

and it worked. i have several backend each one with special db user and special schema granted to that user
( with "one" codebase and don't want touching the framework code.)
is there any way to override shema in every backend ( eg. in backend\config\params.php -> dsn ).

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Dec 5, 2013

Member

I'm wondering why it won't work. As I don't have a test environment at the moment, could you help check what is the result of $db->schema->getTableNames($schema), $schema and $pattern at line 495 in yii\gii\generators\model\Generator? Thanks.

Member

qiangxue commented Dec 5, 2013

I'm wondering why it won't work. As I don't have a test environment at the moment, could you help check what is the result of $db->schema->getTableNames($schema), $schema and $pattern at line 495 in yii\gii\generators\model\Generator? Thanks.

@nineinchnick

This comment has been minimized.

Show comment
Hide comment
@nineinchnick

nineinchnick Dec 5, 2013

Contributor

It works for me.

Contributor

nineinchnick commented Dec 5, 2013

It works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment