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

fix: [SQLite3][Postgres][SQLSRV][OCI8] Forge::modifyColumn() changes NULL constraint incorrectly #7371

Merged
merged 15 commits into from
Apr 27, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Mar 23, 2023

Description
See #7302

  • The $forge->modifyColumn() has been fixed. Due to a bug, in previous versions, SQLite3/Postgres/SQLSRV might change NULL/NOT NULL unpredictably.
  • In previous versions, the OCI8 driver did not change NULL/NOT NULL when you don’t specify null value.
  • Now in all database drivers $forge->modifyColumn() always sets NULL when you don’t specify null value.

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

@kenjis kenjis changed the title fix: SQLite3 Forge::modifyColumn() changes NULL incorrectly fix: [SQLite3] Forge::modifyColumn() changes NULL incorrectly Mar 23, 2023
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Mar 23, 2023
@kenjis
Copy link
Member Author

kenjis commented Mar 23, 2023

Because sanity-tests fail, we cannot run database-live-tests...

@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch 2 times, most recently from 6338612 to 156419a Compare March 23, 2023 06:02
@kenjis kenjis marked this pull request as draft March 23, 2023 06:04
@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch 2 times, most recently from 6d2bfe1 to 89c4bc8 Compare March 23, 2023 06:41
@kenjis kenjis mentioned this pull request Mar 23, 2023
5 tasks
@kenjis
Copy link
Member Author

kenjis commented Mar 23, 2023

Okay. SQLite3 database-live-tests passed.
https://github.com/codeigniter4/CodeIgniter4/actions/runs/4497811722

$this->db->resetDataCache();

$col1 = $this->getMetaData('col1', 'forge_test_modify');
$this->assertTrue($col1->nullable); // Nullable if not specified.
Copy link
Member Author

@kenjis kenjis Mar 23, 2023

Choose a reason for hiding this comment

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

@codeigniter4/database-team Should this be false? What do you think?

Maybe different databases have different defaults when not specifying null or not null?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have also changed the behavior of other drivers to match the behavior of MySQL.

@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch from 89c4bc8 to 7480fd5 Compare March 23, 2023 08:11
@kenjis
Copy link
Member Author

kenjis commented Mar 23, 2023

I didn't know but the following test passes on MySQL.

        $this->forge->dropTable('forge_test_modify', true);

        $this->forge->addField([
            'col1' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false],
            'col2' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false],
            'col3' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false],
        ]);
        $this->forge->createTable('forge_test_modify');

        $this->forge->modifyColumn('forge_test_modify', [
            'col1' => ['name' => 'new_name', 'type' => 'VARCHAR', 'constraint' => 1],
            'col2' => ['type' => 'VARCHAR', 'constraint' => 1, 'null' => true],
            'col3' => ['type' => 'VARCHAR', 'constraint' => 1, 'null' => false],
        ]);

        $this->db->resetDataCache();

        $col1 = $this->getMetaData('new_name', 'forge_test_modify');
        $this->assertTrue($col1->nullable); // Nullable if not specified.
        $col2 = $this->getMetaData('col2', 'forge_test_modify');
        $this->assertTrue($col2->nullable);
        $col3 = $this->getMetaData('col3', 'forge_test_modify');
        $this->assertFalse($col3->nullable);

Added notes in the docs: 3b8a428

@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch 3 times, most recently from 8068beb to 20cfb13 Compare March 23, 2023 08:34
@kenjis kenjis added the database Issues or pull requests that affect the database layer label Mar 24, 2023
@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch from 20cfb13 to 16177e7 Compare March 24, 2023 02:24
@kenjis kenjis changed the title fix: [SQLite3] Forge::modifyColumn() changes NULL incorrectly fix: [SQLite3][Postgres] Forge::modifyColumn() changes NULL incorrectly Mar 24, 2023
@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch from 07d4457 to 7e13c3a Compare March 24, 2023 02:55
@kenjis kenjis changed the title fix: [SQLite3][Postgres] Forge::modifyColumn() changes NULL incorrectly fix: [SQLite3][Postgres][SQLSRV] Forge::modifyColumn() changes NULL incorrectly Mar 24, 2023
@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch 4 times, most recently from 9c05b29 to e8e7a6b Compare March 24, 2023 04:20
@kenjis kenjis changed the title fix: [SQLite3][Postgres][SQLSRV] Forge::modifyColumn() changes NULL incorrectly fix: [SQLite3][Postgres][SQLSRV][OCI8] Forge::modifyColumn() changes NULL incorrectly Mar 24, 2023
@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch from 5c2f42f to 88c087c Compare March 24, 2023 06:52
@kenjis kenjis added the breaking change Pull requests that may break existing functionalities label Mar 24, 2023
@kenjis kenjis changed the title fix: [SQLite3][Postgres][SQLSRV][OCI8] Forge::modifyColumn() changes NULL incorrectly fix: [SQLite3][Postgres][SQLSRV][OCI8] Forge::modifyColumn() changes NULL constraint incorrectly Mar 24, 2023
@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch from e4be766 to 4653dff Compare March 24, 2023 07:45
@kenjis
Copy link
Member Author

kenjis commented Mar 27, 2023

Rebased and add upgrade note.

@kenjis kenjis marked this pull request as ready for review March 27, 2023 00:38
@kenjis
Copy link
Member Author

kenjis commented Apr 8, 2023

@codeigniter4/database-team Please review.

@kenjis
Copy link
Member Author

kenjis commented Apr 25, 2023

Any comment?

@samsonasik samsonasik requested a review from michalsn April 25, 2023 01:40
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

I would prefer someone DB to take a look too but the code makes sense and tests look good so I trust this is appropriate.

@kenjis
Copy link
Member Author

kenjis commented Apr 26, 2023

I believe this code is okay. The issue is that this behavior is okay.

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.

I think that using:

null value

Could be a bit misleading, and some users may think they should define their table fields as null (at least for me). So, we could use something more specific.

user_guide_src/source/dbmgmt/forge.rst Outdated Show resolved Hide resolved
user_guide_src/source/changelogs/v4.3.4.rst Outdated Show resolved Hide resolved
user_guide_src/source/changelogs/v4.3.4.rst Outdated Show resolved Hide resolved
user_guide_src/source/changelogs/v4.3.4.rst Outdated Show resolved Hide resolved
user_guide_src/source/installation/upgrade_434.rst Outdated Show resolved Hide resolved
@kenjis kenjis force-pushed the fix-modifyColumn-SQLite3 branch from bbbebf7 to 3b416c8 Compare April 26, 2023 23:03
@kenjis
Copy link
Member Author

kenjis commented Apr 26, 2023

@michalsn Exactly! Applied your suggestions.

@kenjis kenjis requested a review from michalsn April 26, 2023 23:04
@kenjis kenjis merged commit 90762f3 into codeigniter4:develop Apr 27, 2023
@kenjis kenjis deleted the fix-modifyColumn-SQLite3 branch April 27, 2023 09:18
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants