Skip to content

Commit

Permalink
fix version sort
Browse files Browse the repository at this point in the history
  • Loading branch information
long2ice committed Jul 28, 2020
1 parent 18cb75f commit e1ffcb6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ChangeLog
0.2.2
-----
- Fix postgres drop fk.
- Fix version sort.

0.2.1
-----
Expand Down
5 changes: 4 additions & 1 deletion aerich/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def get_old_model_file(cls):

@classmethod
def get_all_version_files(cls) -> List[str]:
return sorted(filter(lambda x: x.endswith("json"), os.listdir(cls.migrate_location)))
return sorted(
filter(lambda x: x.endswith("json"), os.listdir(cls.migrate_location)),
key=lambda x: x.split("_")[0],

This comment has been minimized.

Copy link
@maxim-s-barabash

maxim-s-barabash Jul 28, 2020

-            key=lambda x: x.split("_")[0],
+            key=lambda x: int(x.split("_")[0]),

This comment has been minimized.

Copy link
@maxim-s-barabash

maxim-s-barabash Jul 28, 2020

def test_sort_all_version_files(mocker):
    """pytest-mock
    """
    mocker.patch(
        "os.listdir",
        return_value=[
            "1_datetime_update.json",
            "11_datetime_update.json",
            "10_datetime_update.json",
            "2_datetime_update.json",
        ],
    )

    Migrate.migrate_location = '.'

    assert Migrate.get_all_version_files() == [
        "1_datetime_update.json",
        "2_datetime_update.json",
        "10_datetime_update.json",
        "11_datetime_update.json",
    ]

This comment has been minimized.

Copy link
@long2ice

long2ice Jul 29, 2020

Author Member

Thanks that correction!

)

@classmethod
async def get_last_version(cls) -> Aerich:
Expand Down

0 comments on commit e1ffcb6

Please sign in to comment.