Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Migrations processed with wrong order #23

@ogbofjnr

Description

@ogbofjnr

In v1 there is a problem that migrations are not sorted by creation date so they are displayed and processed in the wrong order.
Please add sorting to the Migrator get migrations.
This code worked for me:

public function getMigrations(): array
    {
        $result = [];
        foreach ($this->repository->getMigrations() as $migration) {
            //Populating migration status and execution time (if any)
            $result[] = $migration->withState($this->resolveStatus($migration->getState()));
        }

        usort($result, function ($a, $b)
        {
            $aTimeCreated=$a->getState()->getTimeCreated();
            $bTimeCreated=$b->getState()->getTimeCreated();
            if ($aTimeCreated == $bTimeCreated) {
                return 0;
            }
            return ($aTimeCreated < $bTimeCreated) ? -1 : 1;
        });

        return $result;
    }

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