Skip to content

Commit

Permalink
fix: SQLite3 Forge::modifyColumn() messes up table
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jan 26, 2024
1 parent f4e836c commit 6db3322
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion system/Database/SQLite3/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,22 @@ protected function _alterTable(string $alterType, string $table, $processedField
return ''; // Why empty string?
case 'CHANGE':
$fieldsToModify = [];

foreach ($processedFields as $processedField) {
$name = $processedField['name'];
$new_name = $processedField['new_name'];

$field = $this->fields[$name];
$field['name'] = $name;
$field['new_name'] = $new_name;

$fieldsToModify[] = $field;
}

(new Table($this->db, $this))
->fromTable($table)
->modifyColumn($processedFields) // @TODO Bug: should be NOT processed fields
->modifyColumn($fieldsToModify)
->run();

return null; // Why null?
Expand Down
10 changes: 10 additions & 0 deletions system/Database/SQLite3/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ protected function formatFields($fields)
'null' => $field->nullable,
];

if ($field->default === null) {
// `null` means that the default value is not defined.
unset($return[$field->name]['default']);
} elseif ($field->default === 'NULL') {
// 'NULL' means that the default value is NULL.
$return[$field->name]['default'] = null;
} else {
$return[$field->name]['default'] = trim($field->default, "'");
}

if ($field->primary_key) {
$this->keys['primary'] = [
'fields' => [$field->name],
Expand Down

0 comments on commit 6db3322

Please sign in to comment.