Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is gii schema aware? #1435

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

is gii schema aware? #1435

gitrad opened this issue Dec 5, 2013 · 10 comments

Comments

@gitrad
Copy link
Contributor

@gitrad 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
Copy link
Contributor

@nineinchnick 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
Copy link
Member

@samdark 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
Copy link
Member

@qiangxue qiangxue commented Dec 5, 2013

Try entering office.* in the table field.

@nineinchnick
Copy link
Contributor

@nineinchnick 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
Copy link
Contributor

@nineinchnick 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
Copy link
Contributor

@nineinchnick 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
Copy link
Contributor Author

@gitrad 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
Copy link
Contributor Author

@gitrad 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
Copy link
Member

@qiangxue 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
Copy link
Contributor

@nineinchnick 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
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.