Skip to content

Commit 213f0b9

Browse files
committed
refactor: add $columnNamesToDrop
1 parent 04b6643 commit 213f0b9

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

system/Database/SQLSRV/Forge.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,17 @@ protected function _alterTable(string $alterType, string $table, $processedField
136136
{
137137
// Handle DROP here
138138
if ($alterType === 'DROP') {
139+
$columnNamesToDrop = $processedFields;
140+
139141
// check if fields are part of any indexes
140142
$indexData = $this->db->getIndexData($table);
141143

142144
foreach ($indexData as $index) {
143-
if (is_string($processedFields)) {
144-
$processedFields = explode(',', $processedFields);
145+
if (is_string($columnNamesToDrop)) {
146+
$columnNamesToDrop = explode(',', $columnNamesToDrop);
145147
}
146148

147-
$fld = array_intersect($processedFields, $index->fields);
149+
$fld = array_intersect($columnNamesToDrop, $index->fields);
148150

149151
// Drop index if field is part of an index
150152
if ($fld !== []) {
@@ -155,7 +157,7 @@ protected function _alterTable(string $alterType, string $table, $processedField
155157
$fullTable = $this->db->escapeIdentifiers($this->db->schema) . '.' . $this->db->escapeIdentifiers($table);
156158

157159
// Drop default constraints
158-
$fields = implode(',', $this->db->escape((array) $processedFields));
160+
$fields = implode(',', $this->db->escape((array) $columnNamesToDrop));
159161

160162
$sql = <<<SQL
161163
SELECT name
@@ -172,7 +174,7 @@ protected function _alterTable(string $alterType, string $table, $processedField
172174

173175
$sql = 'ALTER TABLE ' . $fullTable . ' DROP ';
174176

175-
$fields = array_map(static fn ($item) => 'COLUMN [' . trim($item) . ']', (array) $processedFields);
177+
$fields = array_map(static fn ($item) => 'COLUMN [' . trim($item) . ']', (array) $columnNamesToDrop);
176178

177179
return $sql . implode(',', $fields);
178180
}

system/Database/SQLite3/Forge.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ protected function _alterTable(string $alterType, string $table, $processedField
120120
{
121121
switch ($alterType) {
122122
case 'DROP':
123+
$columnNamesToDrop = $processedFields;
124+
123125
$sqlTable = new Table($this->db, $this);
124126

125127
$sqlTable->fromTable($table)
126-
->dropColumn($processedFields)
128+
->dropColumn($columnNamesToDrop)
127129
->run();
128130

129131
return ''; // Why empty string?

0 commit comments

Comments
 (0)