migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Add metadata of table when baking new migration

Open liviakuenzli opened this issue 8 years ago • 1 comments

This is a (multiple allowed):

  • [x] bug

  • [ ] enhancement

  • [ ] feature-discussion (RFC)

  • CakePHP Version: 3.5.4

  • Migrations plugin version: 1.7.1

  • Bake plugin version (if relevant): 1.3.7

  • Database server (MySQL, SQLite, Postgres): MySQL 5.7.20

  • PHP Version: 7.1.7

  • Platform / OS: Windows 10

What you did

We created a new database and added some tables and fields, then we created a snapshot as described in the documentation: https://book.cakephp.org/3.0/en/migrations.html#generating-migrations-from-an-existing-database it worked, but I feel like the baked migration is not complete, because the comment and the collation of the table were not taken into consideration. It uses the default collation, which is fine with us in this case (but it should take the collation of the table) and I added the table comments by hand like this:

$this->table('users', ['comment' => 'A user.'])
            ->addColumn('id', 'integer', [

It works fine now, but I shouldn't have to manually add the comments :)

To recreate, I created another new table, gave it some other collation than the database default and added a comment. The table is called test and it has two fields, one for the id and one varchar(45) named testcol.

This is the migration baked by using bin/cake bake migration_diff NameOfTheMigrations

<?php
use Migrations\AbstractMigration;

class NameOfTheMigrations extends AbstractMigration
{

    public function up()
    {

        $this->table('test')
            ->addColumn('testcol', 'string', [
                'comment' => 'Comment test col',
                'default' => null,
                'limit' => 45,
                'null' => true,
            ])
            ->create();
    }

    public function down()
    {

        $this->dropTable('test');
    }
}

As you can see, the table meta data like the comment or the collation are missing.

To sum up: I think migrations baked using migration_snapshot or migration_diff should include metadata for the table.

As a side note, the id field is not in this migration (I'm not sure why, I don't know the plugin that well) and the comment for said id field therefore gets lost too.

liviakuenzli avatar Oct 30 '17 15:10 liviakuenzli

While the missing table comments are probably a missing feature, the missing table collation can certainly be seen as a bug as it can lead to inconsistent states between developers - A thing you tried to work around with migrations in the first place.

ravage84 avatar Oct 31 '17 18:10 ravage84

Isnt this fixed in cake5 now?

dereuromark avatar Feb 21 '24 03:02 dereuromark

At this point I really don't know and don't care anymore, but if you say so I trust you :)

liviakuenzli avatar Feb 21 '24 06:02 liviakuenzli