-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Improve BaseConnection::getForeignKeyData() and Forge::addForeignKey() #6468
Conversation
Can you add the structure in the user guide? |
@sclubricants Thank you for this PR. This is easy to understand! The new PHPStan reports new errors. We've fixed. Please rebase to get rid of the errors. There are a few GitHub Action check failures. Also please check. |
There are two ErrorException: Undefined property: stdClass::$constraint_name
$sql = '
SELECT
tc.constraint_name,
....
tc.table_name = ' . $this->escape($table);
if (($query = $this->query($sql)) === false) {
throw new DatabaseException(lang('Database.failGetForeignKeyData'));
}
$query = $query->getResultObject();
$indexes = [];
foreach ($query as $row) {
$indexes[$row->constraint_name]['constraint_name'] = $row->constraint_name; The only way I can see this failing is if MySql isn't returning the fields in lower case. I had this problem with Oracle in upper case. |
The last one is MySQL 8.0. |
31295eb
to
6bfd0be
Compare
Please write why you changed to uppercase in the commit message. We can easily know that this commit changed the column names to uppercase, |
What's the problems? |
When you call dropForeignKey() the table parameter gets prefixed by table prefix. I mentioned it elsewhere here.. |
Good question.. basically cause it worked. Its something I've never seen with MySql. MySql has always returned the same letter case as the sql is typed in my experience but for some reason the server you are running that test on returns upper case no matter what. Perhaps there might be a configuration for this? |
It seems MySQL 8 changed the behavior. what are the changes in mysql 8 result rowset case? - Stack Overflow |
Oh, we can't drop any key that does not begin with the DB prefix! CodeIgniter4/system/Database/Forge.php Lines 466 to 470 in a8072a5
The DB prefix was added in: |
We definitely want to have the prefix. Someone might have a different connection on same database with duplicates of tables but with different prefixes. This way we avoid name collision. |
Do we need the prefix for foreign key name? |
d05c1d8
to
36f4d86
Compare
On further review it appears that from 12.2 and on the identifier can be 128 bytes. However a user can set COMPATIBILITY to a lower version which could affect this.
OCI8 name suffix changed from _fk to _foreign
It seems its agreed that this is better being shorter.
Removed special naming for Oracle 12, Added the ability to set foreign key name, and added test.
Adding the db prefix was causing error when using custom foreign key names. Also refactored _processForeignKeys() to reduce duplicated code.
Co-authored-by: Michal Sniatala <[email protected]>
Kept one test to test default foreign key names - the rest set their own names. Removed the extra test to test setting names since this is done in other tests.
Co-authored-by: Michal Sniatala <[email protected]>
92d44c6
to
aa818d5
Compare
@sclubricants @michalsn Thank you! |
@kenjis said it best! Thanks to everyone for the work on this 🥳 |
BaseConnection::getForeignKeyData()
It aligns all DBMS to use the same naming convention.Forge::addForeignKey()
This is the first part of #6430
Checklist: