Skip to content

Commit f0f76e1

Browse files
oguzhanToguzhantogay
and
oguzhantogay
authored
fix: fix column unsigned change in update (#108)
fix column unsigned change in update Co-authored-by: oguzhantogay <[email protected]>
1 parent e21cc6b commit f0f76e1

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

src/Mvc/Model/Migration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ public function morphTable(string $tableName, array $definition): void
570570
$changed = true;
571571
}
572572

573+
if ($localFields[$fieldName]->isUnsigned() != $column->isUnsigned()) {
574+
$changed = true;
575+
}
576+
573577
if ($changed === true) {
574578
try {
575579
self::$connection->modifyColumn($tableName, $tableSchema, $column, $column);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Phalcon\Db\Column;
4+
use Phalcon\Db\Index;
5+
use Phalcon\Migrations\Mvc\Model\Migration;
6+
7+
class UpdateColumnUnsignedMigration_100 extends Migration
8+
{
9+
/**
10+
* Define the table structure
11+
*
12+
* @return void
13+
* @throws \Phalcon\Db\Exception
14+
*/
15+
public function morph()
16+
{
17+
$this->morphTable('update_unsigned_column', [
18+
'columns' => [
19+
new Column(
20+
'id',
21+
[
22+
'type' => Column::TYPE_INTEGER,
23+
'size' => 10,
24+
'unsigned' => true,
25+
'notNull' => true,
26+
'first' => true,
27+
'primary' => true,
28+
'autoIncrement' => true,
29+
]
30+
)
31+
],
32+
]);
33+
}
34+
}

tests/mysql/MigrationsCest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,47 @@ public function generateWithExportOnCreate(MysqlTester $I): void
407407
);
408408
}
409409

410+
public function updateColumnUnsigned(MysqlTester $mysqlTester): void
411+
{
412+
$dbName = getenv('MYSQL_TEST_DB_DATABASE');
413+
$tableName = 'update_unsigned_column';
414+
$migrationsDir = codecept_output_dir(__FUNCTION__);
415+
416+
$mysqlTester->getPhalconDb()->createTable($tableName, $dbName, [
417+
'columns' => [
418+
new Column('id', [
419+
'type' => Column::TYPE_INTEGER,
420+
'size' => 10,
421+
'unsigned' => false,
422+
'notNull' => true,
423+
'first' => true,
424+
'primary' => true,
425+
'autoIncrement' => true,
426+
]),
427+
],
428+
]);
429+
430+
ob_start();
431+
Migrations::generate([
432+
'migrationsDir' => $migrationsDir,
433+
'config' => $mysqlTester->getMigrationsConfig(),
434+
'tableName' => '@',
435+
]);
436+
ob_clean();
437+
438+
ob_start();
439+
Migrations::run([
440+
'migrationsDir' => codecept_data_dir('issues/109'),
441+
'config' => $mysqlTester->getMigrationsConfig(),
442+
'migrationsInDb' => true,
443+
]);
444+
ob_clean();
445+
446+
$columns = $mysqlTester->getPhalconDb()->describeColumns($tableName);
447+
448+
$mysqlTester->asserttrue($columns[0]->isUnsigned());
449+
}
450+
410451
public function nullableTimestamp(MysqlTester $I): void
411452
{
412453
$dbName = getenv('MYSQL_TEST_DB_DATABASE');

0 commit comments

Comments
 (0)