Skip to content

Commit ff79c8e

Browse files
committed
fix: SQLite3 Forge::modifyColumn() messes up table
1 parent f4e836c commit ff79c8e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

system/Database/SQLite3/Forge.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,22 @@ protected function _alterTable(string $alterType, string $table, $processedField
131131
return ''; // Why empty string?
132132
133133
case 'CHANGE':
134+
$fieldsToModify = [];
135+
136+
foreach ($processedFields as $processedField) {
137+
$name = $processedField['name'];
138+
$newName = $processedField['new_name'];
139+
140+
$field = $this->fields[$name];
141+
$field['name'] = $name;
142+
$field['new_name'] = $newName;
143+
144+
$fieldsToModify[] = $field;
145+
}
146+
134147
(new Table($this->db, $this))
135148
->fromTable($table)
136-
->modifyColumn($processedFields) // @TODO Bug: should be NOT processed fields
149+
->modifyColumn($fieldsToModify)
137150
->run();
138151

139152
return null; // Why null?

system/Database/SQLite3/Table.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,16 @@ protected function formatFields($fields)
392392
'null' => $field->nullable,
393393
];
394394

395+
if ($field->default === null) {
396+
// `null` means that the default value is not defined.
397+
unset($return[$field->name]['default']);
398+
} elseif ($field->default === 'NULL') {
399+
// 'NULL' means that the default value is NULL.
400+
$return[$field->name]['default'] = null;
401+
} else {
402+
$return[$field->name]['default'] = trim($field->default, "'");
403+
}
404+
395405
if ($field->primary_key) {
396406
$this->keys['primary'] = [
397407
'fields' => [$field->name],

0 commit comments

Comments
 (0)