Skip to main content

Django

Migrations

Use the RunSQL operation.

First, create a migration:

python manage.py makemigrations \
--empty \
--name electrify_items \
app_label

Then add a RunSQL operation to the generated migration file, e.g.:

from django.db import migrations

class Migration(migrations.Migration):
dependencies = []

operations = [
migrations.RunSQL(
"""
ALTER TABLE items
ENABLE ELECTRIC;
"""
)
]
end
end

Event sourcing

One way of consuming a change feed from Postgres in Python is to use the psycopg2.extras.LogicalReplicationConnection.

See Integrations -> Event sourcing for more information.