django-migrate-sql-deux

Ever wanted to have Django migrations help you managed SQL functions and other entities? Introducing django-migrate-sql-deux, if you have this problem, give it a spin!

I encountered this problem a while back, and found Bogdan Klichuk’s django-migrate-sql package, which worked well at the time, but looked no longer maintained. However, as Django evolved, the package needed some tweaks to keep up to date, so I resolved to fork it.

It’s now up to date to the current supported versions of Django 4.2-5.2 and Python 3.10-3.14 (Python 3.9 support was just dropped).

PS: Thanks @jacobtylerwalls for the Django Chat mention which prompted me to promote it a bit more here.

5 Likes

Oooh very cool. Thanks for mentioning it!

This is a cool idea, and similar to what I’ve built in the past for views. Good work reviving it!

One small suggestion for improvement: run textwrap.dedent() on SQL strings by default, so SQLItems can use natural indentation:

SQLItem(
    "make_sum",
    """
    create or replace function make_sum(a int, b int) returns int as $$
      begin return a + b;
      end;
    $$ language plpgsql;
    """,
    reverse_sql="""
        drop function make_sum(int, int);
    """
)
1 Like