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

Move schema split for SQLite CREATE INDEX only #6352

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented Apr 5, 2024

Q A
Type bug
Fixed issues n/a

Summary

SqlitePlatform::getCreatePrimaryKeySQL method must receive original table name, the split is intended for SQLite CREATE INDEX statement only.

@mvorisek mvorisek force-pushed the fix_primary_index_schema_split branch 4 times, most recently from c4a7206 to 0d1617e Compare April 5, 2024 19:15
@derrabus
Copy link
Member

derrabus commented Apr 7, 2024

There is no functional test included. We're making assertions purely on the generated SQL. Thus, the test does not really reproduce a bug that's fixed with this change.

Furthermore, you're testing an implementation detail: how the table name is passed from getCreateIndexSQL() to getCreatePrimaryKeySQL(). As a user of the DBAL library, I couldn't care less how the table is represented as long as my primary key is created correctly.

If I'm not mistaken, this change is supposed to fix a problem regarding the creation of primary keys on tables outside of the main schema. So, can we create a functional test that attempts exactly that?

Comment on lines 260 to 265
$indexDef = new Index('i', ['a', 'b']);
self::assertSame(
'CREATE INDEX main.i ON mytable (a, b)',
$this->platform->getCreateIndexSQL($indexDef, 'main.mytable'),
);
Copy link
Member

Choose a reason for hiding this comment

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

This method contains two test scenarios in a single test. Furthermore, this first scenario is green without your changes. It does not really cover anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have split the test into two.

The first test tests if expected SQL is generated when a table name with schema is given.

The second test tests if unmodified table/column is passed to SqlitePlatform::getCreatePrimaryKeySQL().

@mvorisek mvorisek force-pushed the fix_primary_index_schema_split branch from d24cf43 to 20fbd75 Compare April 7, 2024 22:31
@mvorisek mvorisek requested a review from derrabus April 8, 2024 21:56
@derrabus
Copy link
Member

derrabus commented May 3, 2024

This comment hasn't been addressed as far as I can tell: #6352 (comment)

@mvorisek
Copy link
Contributor Author

mvorisek commented May 3, 2024

Function test (ie. test with DB) cannot be made as https://github.com/doctrine/dbal/blob/3.8.4/src/Platforms/SqlitePlatform.php#L995 always throws. Thus the test is coded to test the behaviour using overrided method.

@derrabus
Copy link
Member

derrabus commented May 3, 2024

If the scenario is an overridden platform, can't we run a functional test with an overridden platform?

@mvorisek
Copy link
Contributor Author

mvorisek commented May 3, 2024

Adding/altering primary key is not supported by SQLite using one SQL statement, thus I belive the current test cannot be coded better.

In anycase, we need to override the platform method to test this. This is what the current test does. It does not change the behaviour in sense of any currently generated SQL, but fixes what is passed to a public overridable method.

@mvorisek
Copy link
Contributor Author

@greg0ire @SenseException can I please have your review here?

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

It's unclear to me what exactly you are attempting to fix here. Seems very theoretical. Can you let us know what prompted you to send this PR?

@mvorisek
Copy link
Contributor Author

@greg0ire the moved part is in the code solely to create right CREATE INDEX syntax when schema in the table name is present. It is evident that wrong table (table without schema) is passed to getCreatePrimaryKeySQL otherwise. In our codebase we override SqlitePlatform to support schema (using SQLite ATTACH) and this change is bugfix.

I hope it is clear the code needs to be moved and I have asserted that with a test which fail otherwise. If the impl. is fine, let's merge it please.

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

It is way clearer when you disclose your motivations, yes.

@derrabus derrabus added this to the 3.8.6 milestone Jun 18, 2024
@derrabus derrabus merged commit a0c9416 into doctrine:3.8.x Jun 18, 2024
92 checks passed
derrabus added a commit to derrabus/dbal that referenced this pull request Jun 18, 2024
* 3.8.x:
  Move schema split for SQLite CREATE INDEX only (doctrine#6352)
  PHPStan 1.11.5 (doctrine#6446)
  Revert "Merge pull request doctrine#6413 from achterin/bugfix/foreign_key_name_change_detection"
  CI: Update MariaDB versions (doctrine#6426)
  CI MariaDB: add 11.4, remove 11.0 (doctrine#6432)
  Fix typo in the portability documentation (doctrine#6430)
derrabus added a commit to derrabus/dbal that referenced this pull request Jun 18, 2024
* 3.8.x:
  Move schema split for SQLite CREATE INDEX only (doctrine#6352)
  PHPStan 1.11.5 (doctrine#6446)
  Revert "Merge pull request doctrine#6413 from achterin/bugfix/foreign_key_name_change_detection"
@mvorisek mvorisek deleted the fix_primary_index_schema_split branch June 18, 2024 12:48
derrabus added a commit to derrabus/dbal that referenced this pull request Jun 19, 2024
* 4.0.x:
  PHPUnit 10.5.21 (doctrine#6447)
  Move schema split for SQLite CREATE INDEX only (doctrine#6352)
  PHPStan 1.11.5 (doctrine#6446)
  Revert "Merge pull request doctrine#6413 from achterin/bugfix/foreign_key_name_change_detection"
derrabus added a commit to derrabus/dbal that referenced this pull request Jun 19, 2024
* 4.1.x: (25 commits)
  Simplify signature of fetchTableOptionsByTable
  Add MariaDb1010Platform for fetchTableOptionsByTable
  PHPUnit 10.5.21 (doctrine#6447)
  Move schema split for SQLite CREATE INDEX only (doctrine#6352)
  PHPStan 1.11.5 (doctrine#6446)
  Default to distinct union queries (doctrine#6439)
  Revert "Merge pull request doctrine#6413 from achterin/bugfix/foreign_key_name_change_detection"
  Add `QueryBuilder` support for `UNION` clause (doctrine#6369)
  CI: Update MariaDB versions (doctrine#6426)
  CI MariaDB: add 11.4, remove 11.0 (doctrine#6432)
  Display warnings when running PHPUnit in CI (doctrine#6431)
  Fix typo in the portability documentation (doctrine#6430)
  Fix MariaDB fetching of default table character-set (doctrine#6361) (doctrine#6425)
  Fix the portability documentation (doctrine#6429)
  Update tests/Platforms/AbstractPlatformTestCase.php
  Update tests/Platforms/AbstractPlatformTestCase.php
  add test
  Fix: Skip type comparison if disableTypeComments is true
  Remove redundant variable (doctrine#6326)
  Fix test names to reflect their actual purpose
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants