yiisoft / yii-gii

Yii code generator extension
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
33 stars 18 forks source link

Allow to use dot in middle of table name in AR command #133

Closed vjik closed 1 month ago

vjik commented 1 month ago

For example, table with scheme in PostgreSQL: booking.room.

Need to fix Regex validation rule:

https://github.com/yiisoft/yii-gii/blob/ca67155160516f6d6710a249921f36758f916291/src/Generator/ActiveRecord/Command.php#L26-L31

ahmadasjad commented 1 month ago

Should we also allow digits at the start of the table name?

samdark commented 1 month ago

Yes. Table names such as 123 are valid.

ahmadasjad commented 1 month ago

There is another issue with TableExistsHandler https://github.com/yiisoft/yii-gii/blob/ca67155160516f6d6710a249921f36758f916291/src/Validator/TableExistsHandler.php#L28-L36

while validating, the validator itself throws an exception instead of showing the error on line 31

Error

{
    "type": "Yiisoft\\Db\\Exception\\Exception",
    "message": "SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'my_user'@'172.20.0.2' for table `xyz`.`abc`\nThe SQL being executed was: SHOW FULL COLUMNS FROM `xyz`.`abc`",
    "code": 0,
    "file": "/app/vendor/yiisoft/db/src/Exception/ConvertException.php",
    "line": 42,
    "trace": [...omited...],
}

I'll be handling it too.

BTW, what message we should show in this case?

vjik commented 1 month ago

BTW, what message we should show in this case?

I think need to add validator error with exception message.

ahmadasjad commented 1 month ago

Adding an exception message will not be good:

I think just setting $tableSchema as null should be fine, it'll fall back to the bottom part to add the message "Table "%s" does not exist."

vjik commented 1 month ago

"No access" is not "Not exist".

Yii Gii is tool for developer. Seems, show exception message in this context is OK.

ahmadasjad commented 1 month ago

Added