Skip to main content

Provides a method to run raw SQL in migrations with multiple databases

Project description

Migrations Plus provides a method to run raw SQL in Django migrations with multiple DB connections.

Install

Using pip:

$ pip install django-migrations-plus

API

RunSQL(sql, reverse_sql=None, state_operations=None, db='default')

Allows running of arbitrary SQL on the database - useful for more advanced features of database backends that Django doesn’t support directly, like partial indexes.

sql, and reverse_sql if provided, should be strings of SQL to run on the database. On most database backends (all but PostgreSQL), Django will split the SQL into individual statements prior to executing them. This requires installing the sqlparse Python library.

The state_operations argument is so you can supply operations that are equivalent to the SQL in terms of project state; for example, if you are manually creating a column, you should pass in a list containing an AddField operation here so that the autodetector still has an up-to-date state of the model (otherwise, when you next run makemigrations, it won’t see any operation that adds that field and so will try to run it again).

db should be a string with the name of the connection from your settings you want to run your SQL on.

Example

from django.db import migrations
import migrations_plus


class Migration(migrations.Migration):

    operations = [
        migrations_plus.RunSQL('DROP TABLE Students;')  # Runs only against connection 'default'
        migrations_plus.RunSQL('DROP TABLE OtherStudents;', db='other')  # Runs only against connection 'other'
    ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-migrations-plus-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

django_migrations_plus-0.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file django-migrations-plus-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django-migrations-plus-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e0167c8e8cc71dbf6582a423fe793e935d19080b57be74f32d039c94f638099a
MD5 057d91ae9e2dd99f370c9317cd584483
BLAKE2b-256 265852167f1bbfc3e37a24513ac7c214269a3c40f9b27c0bd49d8bd4b9b27a1d

See more details on using hashes here.

File details

Details for the file django_migrations_plus-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_migrations_plus-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad1d12d50007646e9e7915e3b4659df0eb54bc425add2aefab556e07175f90b4
MD5 8b3080bc8b4e8967145eb4c908e390fa
BLAKE2b-256 decd5def69778e81a5bd35290df524e6380aab062d88ecdc1720380f88048858

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page