Skip to content

Migrations mis-use class names. #5459

@wjaspers

Description

@wjaspers

The migration system generates a classname from the migration's filename. While this may appear practical up front, it becomes a massive headache when someone manages to name two migrations the same way.

The migration system assumes the classname inside the file is the same as the last segment of the filename, and will currently load the wrong migration if and when a duplicate name is encountered.

2011_01_01_1234_create_magic_table.php

class CreateMagicTable {}

2013_01_01_1234_create_magic_table.php

class CreateMagicTableTakeTwo {}

Error

PHP Fatal error:  Cannot redeclare class CreateMagicTable in /app/database/migrations/2013_01_01_1234_create_magic_table.php on line 42
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Cannot redeclare class CreateMagicTable","file":"\/app\/database\/migrations\/2013_01_01_1234_create_magic_table.php","line":42}}

It would be ideal if the migration system followed Doctrine's practice(s) wherein the class is used that is actually declared inside the file. In my experience, suffixing the classname with the migration date (i.e. 201408010600) helps avoid overlap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions