Skip to content

Migration is unrecognised if already ran migration id is specified and there are any not launched after it #1359

Description

@metakot

TL,DR:

piccolo migrations forwards foo.bar migration1
ok
piccolo migrations forwards foo.bar migration2
ok
piccolo migrations backwards foo.bar
ok
piccolo migrations forwards foo.bar migration1
migration1 is unrecognised

should be 🏁 No migrations need to be run

So I have quite a few apps and migrations that have become dependent on each other, and to make them work correctly I use this script:

#!/bin/bash
set -e
piccolo migrations forwards session_auth
piccolo migrations forwards user
piccolo migrations forwards apps.employee
piccolo migrations forwards apps.car
piccolo migrations forwards apps.price 2024-05-21T06:27:34:451504   # <-- breaks here
piccolo migrations forwards apps.rent
piccolo migrations forwards apps.price   # again because of subsequent dependent migrations
piccolo migrations forwards all  # everything else
python main.py

the specified migration in app "apps.price" is needed by subsequent migrations in dependent apps (apps.rent).
Everything was working fine until I decided to add new migration to the apps.price.

The structure of migrations directory is:

appsprice_2024_05_21t06_27_34_451504.py  # created back when piccolo was 1.5.0
appsprice_2024_05_21t06_31_03_491490.py  # created back when piccolo was 1.5.0
appsprice_2024_05_21t06_54_59_701243.py  # created back when piccolo was 1.5.0
appsprice_2026_02_24t22_16_29_046939.py  # fresh piccolo version
appsprice_2026_02_24t22_20_02_371610.py  # fresh piccolo version

What is happening in

message = f"{self.migration_id} is unrecognised"

print(ids)
['2024-05-21T06:27:34:451504', '2024-05-21T06:31:03:491490', '2024-05-21T06:54:59:701243', '2026-02-24T22:16:29:046939', '2026-02-24T22:20:02:371610']
print(already_ran)
['2024-05-21T06:27:34:451504', '2024-05-21T06:31:03:491490', '2024-05-21T06:54:59:701243']
print(havent_run)
['2026-02-24T22:16:29:046939', '2026-02-24T22:20:02:371610']

And of course the mentioned 2024-05-21T06:27:34:451504 is absent in havent_run because it is already ran and piccolo shows 2024-05-21T06:27:34:451504 is unrecognised.

What I propose:

change this line to

if len(havent_run) == 0 or self.migration_id in already_ran:  # or reuse set(already_ran)

so then piccolo successfully prints 🏁 No migrations need to be run

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions