Skip to content

Commit e52a9fb

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
2 parents ff97eaf + b40b0ff commit e52a9fb

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎src/Controllers/Table/Structure/MoveColumnsController.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ private function generateAlterTableSql(string $createTableSql, array $moveColumn
9393
$parser = new Parser($createTableSql);
9494
/** @var CreateStatement $statement */
9595
$statement = $parser->statements[0];
96-
/** @var CreateDefinition[] $fields */
96+
/** @var CreateDefinition[] $fields For CREATE TABLE statement the type is CreateDefinition[] */
9797
$fields = $statement->fields;
9898
$columns = [];
9999
$columnNames = [];
100100
foreach ($fields as $field) {
101-
if ($field->name === null) {
101+
if ($field->name === null || $field->isConstraint === true || $field->key !== null) {
102102
continue;
103103
}
104104

‎tests/unit/Controllers/Table/Structure/MoveColumnsControllerTest.php‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,45 @@ public static function providerForTestGenerateAlterTableSql(): array
178178
CHANGE `0` `0` enum('yes','no') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'no' FIRST
179179
SQL,
180180
],
181+
// with foreign key
182+
[
183+
<<<'SQL'
184+
CREATE TABLE orders (
185+
order_id INT AUTO_INCREMENT PRIMARY KEY,
186+
user_id INT NOT NULL,
187+
order_date DATE NOT NULL,
188+
amount DECIMAL(10, 2) NOT NULL,
189+
status VARCHAR(50) DEFAULT 'pending',
190+
CONSTRAINT fk_user
191+
FOREIGN KEY (user_id)
192+
REFERENCES users(user_id)
193+
ON DELETE CASCADE
194+
ON UPDATE CASCADE
195+
)
196+
SQL,
197+
['order_id','user_id','order_date','status','amount'],
198+
<<<'SQL'
199+
ALTER TABLE `orders`
200+
CHANGE `status` `status` varchar(50) DEFAULT 'pending' AFTER `order_date`
201+
SQL,
202+
],
203+
// With non-primary index
204+
[
205+
<<<'SQL'
206+
CREATE TABLE `test_table` (
207+
`id` int(11) NOT NULL AUTO_INCREMENT,
208+
`val` int(11) DEFAULT NULL,
209+
`note` varchar(100) DEFAULT NULL,
210+
PRIMARY KEY (`id`),
211+
KEY `val_index` (`val`)
212+
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
213+
SQL,
214+
['id', 'note', 'val'],
215+
<<<'SQL'
216+
ALTER TABLE `test_table`
217+
CHANGE `note` `note` varchar(100) DEFAULT NULL AFTER `id`
218+
SQL,
219+
],
181220
];
182221
// phpcs:enable
183222
}

0 commit comments

Comments
 (0)