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

Add Forge::processIndexes() to create indexes on existing table #6676

Merged
merged 20 commits into from
Oct 20, 2022

Conversation

sclubricants
Copy link
Member

@sclubricants sclubricants commented Oct 12, 2022

Closes #4814

This PR allows creating indexes on an existing table.

It is used following addKey(), addPrimaryKey(), addUniqueKey(), and addForeignKey() to add indexes to an existing table. It is used instead of or in place of createTable().

This is the last part of #6430

Fixes #6453

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@sclubricants sclubricants added bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer 4.3 enhancement PRs that improve existing functionalities labels Oct 12, 2022
@sclubricants
Copy link
Member Author

@codeigniter4/database-team Please Review

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial thoughts.

system/Database/Forge.php Outdated Show resolved Hide resolved
system/Database/Forge.php Outdated Show resolved Hide resolved
system/Database/Forge.php Outdated Show resolved Hide resolved
system/Database/Forge.php Outdated Show resolved Hide resolved
system/Database/Forge.php Outdated Show resolved Hide resolved
system/Database/MySQLi/Forge.php Outdated Show resolved Hide resolved
system/Database/SQLite3/Forge.php Outdated Show resolved Hide resolved
system/Database/SQLite3/Table.php Outdated Show resolved Hide resolved
@kenjis kenjis added the breaking change Pull requests that may break existing functionalities label Oct 14, 2022
@sclubricants sclubricants force-pushed the processIndexes branch 2 times, most recently from 44f461f to 9803845 Compare October 18, 2022 16:26
sclubricants and others added 11 commits October 19, 2022 18:00
Setting $asQuery to true will retrieve a stand alone query rather than the partial statement used with CREATE TABLE.
Makes method return a stand alone query
This will construct the queries used to create indexes and run them.
A bit of code that checks that the field actually exists in the table. Since it now may be called without first declaring fields then it needed moved to after processIndexes() so I moved it to _processForeignKeys().
SQLite needed methods for the Table class to add keys to existing table.
Co-authored-by: Michal Sniatala <[email protected]>
Co-authored-by: Michal Sniatala <[email protected]>
@kenjis
Copy link
Member

kenjis commented Oct 20, 2022

Can you add a test case for without foreign key name?

@sclubricants
Copy link
Member Author

I can, but I don't see it as necessary because _processForeignKeys() is called the same as with create table and there are tests that cover this already. I used names because it simplified the test. Your not going to get anymore code coverage with a test without names.

@kenjis
Copy link
Member

kenjis commented Oct 20, 2022

As far as coverage is concerned, the coverage value we are getting now is line coverage, which means nothing more than knowing lines that are not covered.

Just because the coverage does not increase does not mean that the additional tests are useless or not. At the very least, branch coverage should be compared.

Looking at the implementation in this foreign key case, there is certainly no need to add it.
And as you say, testForeignKey() covers it.

Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I want to keep a test method short. If a test method is too long, it will be difficult to tell what is being tested. See #6676 (comment)

Other than that, I'm okay.

@sclubricants sclubricants requested a review from kenjis October 20, 2022 17:10
Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks!

Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@kenjis kenjis merged commit 1569c20 into codeigniter4:4.3 Oct 20, 2022
@sclubricants sclubricants deleted the processIndexes branch October 20, 2022 23:17
@MGatner
Copy link
Member

MGatner commented Oct 21, 2022

🕺🥳🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants