Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stronk7 opened this issue Oct 30, 2024 · 0 comments
Open

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

stronk7 opened this issue Oct 30, 2024 · 0 comments

Comments

@stronk7
Copy link

stronk7 commented Oct 30, 2024

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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant