-1

query:

UPDATE "table_name"
SET properties = properties || jsonb_build_object('$ip', ip)
WHERE ip IS NOT NULL;

I am running a Django migration, I need the reverse sql that undo the results of executing this query and restores the table in the previous state.

Because when I run the django migration test for the following operation:

operations = [
        # migrations.RunPython(migrate_event_ip_to_property, rollback),
        migrations.RunSQL(
            """
            UPDATE "table_name"
            SET properties = properties || jsonb_build_object('$ip', ip)
            WHERE ip IS NOT NULL;
            """,
            None
        )
    ]

I get IrreversibleError. I think if I provide the reverse sql, instead of None, it might work

futurenext110
  • 1,991
  • 6
  • 26
  • 31

1 Answers1

0

I think you are out of luck looking for a raw solution from postgresql as SQL transaction was already commited by Django migration. See Postgresql ROLLBACK

But in this case you can revert to last working migration using:

./manage.py migrate app XXXX_last_working_migration

As stated in Django's django-admin docs migrate section here

gl4ssiest
  • 167
  • 8