Skip to content

Backwards migrations not always executed (plus missing template) #1122

@stronk7

Description

@stronk7

Hi,

this comes from #1121, where it was discussed about piccolo not executing backwards migrations (not sure which ones are and which ones aren't, I'm afraid).

In that discussion, @sinisaos provided a quick-patch that, apparently made those backwards migrations to start working and this issue is about to consider that fix, or a better one.

Basically, this is the migration step:

from piccolo.apps.migrations.auto.migration_manager import MigrationManager

from myapp.tables import TestTable

ID = "2024-10-28T20:07:36:439746"
VERSION = "1.21.0"
DESCRIPTION = "test-add-drop-index"


async def forwards():
    manager = MigrationManager(
        migration_id=ID, app_name="", description=DESCRIPTION,
    )

    async def run():
        await TestTable.create_index(
            columns = ["col1", "col2"], # or ([TestTable.col1, TestTable.col2])
            if_not_exists = True
        ).run()

    manager.add_raw(run)
    return manager

async def backwards():
    manager = MigrationManager(
        migration_id=ID, app_name="", description=DESCRIPTION
    )

    async def run():
        await TestTable.drop_index(
            columns=["col1", "col2"], # or ([TestTable.col1, TestTable.col2])
            if_exists=True
        ).run()

    manager.add_raw(run)
    return manager

(yes, it creates a composite index on migration, because the models don't support them)

And the problem is that, while piccolo migrations forwards myapp works and the index is created, trying to backwards it doesn't work at all, with the code not being invoked ever.

And that's it, so far. Again, the linked discussion has a "working" solution (tested here) and contains other details that may be of interest.

Ciao :-)

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