Skip to content

Commit 14c5562

Browse files
committed
fix: Forge::modifyColumn() for Postgre handler
1 parent 09b69af commit 14c5562

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

system/Database/Postgre/Forge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected function _alterTable(string $alterType, string $table, $processedField
109109

110110
if (! empty($field['default'])) {
111111
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escapeIdentifiers($field['name'])
112-
. " SET DEFAULT {$field['default']}";
112+
. " SET {$field['default']}";
113113
}
114114

115115
$nullable = true; // Nullable by default.

tests/system/Database/Live/ForgeTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,28 @@ public function testProcessIndexesWithForeignKeyOnly(): void
18181818
$this->forge->dropTable('user2', true);
18191819
}
18201820

1821+
public function testChangeDefaultFieldValueWithModifyColumn(): void
1822+
{
1823+
$this->forge->addField([
1824+
'delivery_sum' => ['type' => 'int', 'constraint' => 6, 'default' => 10],
1825+
'delivery_free_sum' => ['type' => 'int', 'constraint' => 6, 'default' => 10],
1826+
])->addKey('id', true)->createTable('test_stores', true);
1827+
1828+
$this->forge->modifyColumn('test_stores', [
1829+
'delivery_sum' => ['type' => 'int', 'constraint' => 6, 'default' => 100],
1830+
'delivery_free_sum' => ['type' => 'int', 'constraint' => 6, 'default' => 1000],
1831+
]);
1832+
1833+
$expected = ['delivery_sum' => '100', 'delivery_free_sum' => '1000'];
1834+
1835+
$fields = $this->db->getFieldData('test_stores');
1836+
$results = array_column($fields, 'default', 'name');
1837+
1838+
$this->assertSame($expected, $results);
1839+
1840+
$this->forge->dropTable('test_stores', true);
1841+
}
1842+
18211843
private function createUser2TableWithKeys(): void
18221844
{
18231845
$fields = [

user_guide_src/source/changelogs/v4.6.4.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Deprecations
3030
Bugs Fixed
3131
**********
3232

33+
- **Forge:** Fixed a bug in ``Postgre`` where changing a column's default value using ``Config\Database\Forge::modifyColumn()`` produced incorrect SQL syntax.
34+
3335
See the repo's
3436
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
3537
for a complete list of bugs fixed.

0 commit comments

Comments
 (0)