However the problem here is that this assumes the migrations know the used
database aliases. This doesn't work for 3rd party app migrations. For
these cases "for_vendor='mysql'/'postgresql'/..." argument would work
better.
Still, there might be need to allow skipping whole apps for migations -
say you have a 3rd party app you don't want to migrate on database other -
my understanding is that one can only skip all model operations on given
database, but there is no way to force skip of RunSQL and RunPython
commands, too. If it would be possible to define that the app in whole
shouldn't be migrated on database other, then there would be no problem
when running manage.py migrate.
--
Ticket URL: <https://code.djangoproject.com/ticket/22583>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Bug => New feature
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/22583#comment:1>
Comment (by andrewgodwin):
So, it's worth pointing out that RunPython can just switch on the value of
`schema_editor.connection` if it wants to make decisions about the current
database, so I'm not sure if I want to add extra logic to RunSQL?
Especially a run-per-backend thing...
--
Ticket URL: <https://code.djangoproject.com/ticket/22583#comment:2>
* status: new => closed
* resolution: => wontfix
Comment:
I'm going to WONTFIX this and suggest that people use RunPython instead to
do any custom logic; they can either call RunSQL from inside that or, more
easily, just use schema_editor.execute() if they wish to run raw SQL.
--
Ticket URL: <https://code.djangoproject.com/ticket/22583#comment:3>
Comment (by lorden):
I had this problem too and RunPython was not reliable enough. I created a
package to run raw SQL on a specific connection similar to the example
given in the ticket description: [https://pypi.python.org/pypi/django-
migrations-plus django-migrations-plus]. Contributions are appreciated!
--
Ticket URL: <https://code.djangoproject.com/ticket/22583#comment:4>
* status: closed => new
* has_patch: 0 => 1
* resolution: wontfix =>
Comment:
Reopening after discussing this on multiple occasions on IRC.
`RunPython` and `RunSQL` should query the database router like every other
operations and hints can be used to assist the router in taking a
decision. This is consistent with how db routing is performed in the other
parts of the system (i.e. `db_for_read` and `db_for_write`):
{{{
class MyRouter(object):
def allow_migrate(self, db, model, **hints):
if 'target_db' in hints:
return db == hints['target_db']
return True
RunPython(forwards, hints={'target_db': 'default'})
}}}
This also allows completely opting out of migrations for any given db
with:
{{{
class MyRouter(object):
def allow_migrate(self, db, model, **hints):
return db != 'excluded_db'
}}}
PR https://github.com/django/django/pull/3849
--
Ticket URL: <https://code.djangoproject.com/ticket/22583#comment:5>
* cc: loic (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/22583#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/22583#comment:7>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"8f4877c89d0f28e289399fbb46357623a49e7eb0"]:
{{{
#!CommitTicketReference repository=""
revision="8f4877c89d0f28e289399fbb46357623a49e7eb0"
Fixed #22583 -- Allowed RunPython and RunSQL to provide hints to the db
router.
Thanks Markus Holtermann and Tim Graham for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22583#comment:8>