migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Lost column length with migration_snapshot

Open dmromanov opened this issue 6 years ago • 0 comments

This is a (multiple allowed):

  • [x] bug

  • [ ] enhancement

  • [ ] feature-discussion (RFC)

  • CakePHP Version: 3.6.2

  • Migrations plugin version: 1.8.1

  • Bake plugin version (if relevant): 1.7.3

  • Database server (MySQL, SQLite, Postgres): MySQL 5.7, 8.0

  • PHP Version: PHP 7.2.3

  • Platform / OS: Ubuntu 18.04

What you did

We have the following DB.

CREATE TABLE `tests` (
  `id` int(2) NOT NULL AUTO_INCREMENT,
  `ok_int` int(2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

After running bin/cake bake migration_snapshot TestLength Init I get:

<?php
use Migrations\AbstractMigration;

class TestLength extends AbstractMigration
{
    public function up()
    {

        $this->table('tests')
            ->addColumn('ok_int', 'integer', [
                'default' => null,
                'limit' => 2,
                'null' => false,
            ])
            ->create();
    }

    public function down()
    {
        $this->dropTable('tests');
    }
}

Length of the primary key was dropped. Which resulted in an incorrect DB. This is critical when using foreign keys in database: a mismatch of column lengths might cause a later created migrations to fail.

bake migraion_diff works and successfulu detects changes in primary column lengths. So it's just for migration_snapshot

Might be related to #331

dmromanov avatar May 13 '18 16:05 dmromanov