Skip to content

Conversation

@Sieg
Copy link

@Sieg Sieg commented Mar 24, 2021

The assumption that auto_increment is always the value for primary key is wrong.

As example:

  • there is a table user, where primary id is - userId which is a md5 random string.
  • Autoincrement is on the userNumber field, which is not primary, but by some reason it is there.

Now we add a user with haveInDatabase, and with specific id:['userId'=>'special']; what will endup in insertedRows? usesrId => 10 but should be userId=>'special'. As insertId for user was 10, and sure, it will not be cleaned up.

Sieg added 3 commits March 24, 2021 12:59
The assumption that auto_increment is always the value for primary key is wrong.

As example:
* there is a table user, where primary id is - userId which is a md5 random string.
* Autoincrement is on the userNumber field, which is not primary, but by some reason it is there.

Now we add a user with haveInDatabase, and with specific id:['userId'=>'special'], what will endup in insertedRows? usesrId => 10 for example, as insertId for user was 10, and sure, it will not be cleaned up.
@Naktibalda
Copy link
Member

Thanks for this contribution, but please create tests for the issue your change fixes.

We have a few test cases for primary key logic in https://github.com/Codeception/module-db/blob/master/tests/unit/Codeception/Module/Db/TestsForDb.php
Add your table to https://github.com/Codeception/module-db/tree/master/tests/data/dumps/

@Naktibalda
Copy link
Member

Replaced by #44

@Naktibalda Naktibalda closed this Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants