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: Forge::dropColumn() seems to always return false. #8931

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -2677,12 +2677,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/Forge.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\Forge\\:\\:dropColumn\\(\\) has parameter \\$columnNames with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/Forge.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\Forge\\:\\:modifyColumn\\(\\) has parameter \\$fields with no value type specified in iterable type array\\.$#',
Expand Down
2 changes: 1 addition & 1 deletion system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ public function addColumn(string $table, $fields): bool
}

/**
* @param array|string $columnNames column names to DROP
* @param list<string>|string $columnNames column names to DROP
*
* @return bool
*
Expand Down
37 changes: 26 additions & 11 deletions system/Database/SQLite3/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ public function dropDatabase(string $dbName): bool
protected function _alterTable(string $alterType, string $table, $processedFields)
{
switch ($alterType) {
case 'DROP':
$columnNamesToDrop = $processedFields;

$sqlTable = new Table($this->db, $this);

$sqlTable->fromTable($table)
->dropColumn($columnNamesToDrop)
->run();

return ''; // Why empty string?

case 'CHANGE':
$fieldsToModify = [];

Expand Down Expand Up @@ -164,6 +153,32 @@ protected function _alterTable(string $alterType, string $table, $processedField
}
}

/**
* @param list<string>|string $columnNames column names to DROP
*
* @return bool
*
* @throws DatabaseException
*/
public function dropColumn(string $table, $columnNames)
{
$sqlTable = new Table($this->db, $this);

$sqlExecuteResult = $sqlTable->fromTable($this->db->DBPrefix . $table)
->dropColumn($columnNames)
->run();

if ($sqlExecuteResult === false) {
if ($this->db->DBDebug) {
throw new DatabaseException('This feature is not available for the database you are using.');
kenjis marked this conversation as resolved.
Show resolved Hide resolved
kenjis marked this conversation as resolved.
Show resolved Hide resolved
}

return false;
}

return $sqlExecuteResult;
}

/**
* Process column
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
$this->forge->dropTable('', true);
}

public function testForeignKey(): void

Check warning on line 491 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 2.7750s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testForeignKey
{
$this->forge->dropTable('forge_test_invoices', true);
$this->forge->dropTable('forge_test_users', true);
Expand Down Expand Up @@ -1230,7 +1230,7 @@
$this->forge->dropTable('forge_test_1', true);
}

public function testSetKeyNames(): void

Check warning on line 1233 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.0142s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testSetKeyNames
{
$this->forge->dropTable('forge_test_1', true);

Expand Down Expand Up @@ -1317,7 +1317,8 @@

$this->assertTrue($this->db->fieldExists('name', 'forge_test_two'));

$this->forge->dropColumn('forge_test_two', 'name');
$result = $this->forge->dropColumn('forge_test_two', 'name');
$this->assertTrue($result);

$this->db->resetDataCache();

Expand Down Expand Up @@ -1665,7 +1666,7 @@
$this->forge->dropTable('forge_test_users', true);
}

public function testProcessIndexes(): void

Check warning on line 1669 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.4135s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testProcessIndexes
{
// make sure tables don't exist
$this->forge->dropTable('actions', true);
Expand Down
Empty file added writable/test_com.sitedb.web
kenjis marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
Loading