Must a Django Database Support Migrations?Django 1.7 adds schema migration support and this behavior is currently requiredto be able to effectively use Django and run the test suite. I opened ticket#21841 [1], which requests adding a DatabaseFeature to disable schemamigrations. This ticket prompted an IRC discussion between Russell and myselfthat ended with the question, must a database backend support schema migrationsto be compliant with Django 1.7? We're hoping to get opinions from others aboutthis to figure out how to proceed.
Database backend compliance is defined by its ability to pass Django's testsuite. A fully compliant database can pass 100% of tests dealing with thedatabase. If a database backend raises NotImplementedError for schema_editor, itis currently 0% compliant because it cannot create the database tables.If database backends are not required to support migrations, then there wouldneed to be some form of fallback behavior to provide a Django 1.6 syncdb-esquebehavior. It would create the schema without attempting alterations.Why Disable Migrations?1) Not all projects need schema migrations or want Django to manage themigrations. My primary project has Django working against a legacy database andrelies upon an external tool (and a DBA) to manage schema changes in ourenvironment. This workflow uses syncdb to create the tables in to a temporarydatabase and then compares it will an external tool that generates an SQL diff.This diff is tested by the DBA before being applied to the production database.This basic workflow will continue even after upgrading to Django 1.7.This scenario does not necessarily need to be handled as a database feature.Russell's idea during the IRC discussion was a database configuration that actsas a safety to prevent migrations from being applied; similar to managed models.
2) NoSQL databases don't necessarily have an enforced schema. What wouldmigration mean for NoSQL? Would it noop or attempt to update existing data? Dowe even care because NoSQL is not officially supported by Django?
3) The database backend or driver doesn't support altering the schema in a waythat would work with Django's schema migrations API. I can't think of any thatwould be used with Django, but people still use mysql despite its many faults,so anything is possible.
Potential Issues With Optional Support1) If migration support is optional, a concern was raised that backends thatdon't support it would give users a lesser experience and potentially makeDjango look bad.While this might be possible, the same concern holds true for any existingdatabase backend that is buggy, doesn't fully implement the existing API, or theunderlying database itself is slow or lacks basic functionality (e.g.referential integrity, ACID compliance, etc).
Currently unknown level of effort or complexity to allow the migrationsto fallback to a Django 1.6 syncdb-esque behavior.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/33933764.nuWK3GA93E%40deblack.
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.
My thoughts in brief on this:- Database backends don't support migrations - they support schema alteration via SchemaEditor. This could be used separately from migrations if something wants it, and is meant to be an API on its own, so the backend is not the place to say if you want migrations or not.
- There is some merit to the ability to turn off migrations on a per-backend basis, via a DATABASES setting, but bear in mind that routers already let you do this (with the allow_migrate method). The only extra thing it would achieve is not having Django record migrations in the django_migrations table, but it also looks like it would be useful for tests if you hadn't written that part yet.
- I feel like a DB backend should at least implement SchemaEditor even if it returns NotImplementedError for most of the endpoints; even in the weirdest relational system, you can still manage create/delete model without too much difficulty.
- Bear in mind that the plan is to remove DatabaseCreation entirely in favour of SchemaEditor in a few releases' time (and backends are more than welcome to make DatabaseCreation use SchemaEditor behind the scenes if they want), so at that point if you don't implement it the backend is only ever good for querying, which to me feels like an incomplete backend.
- I'm not sure what the future of ./manage.py sqlall is, but it's going to have to be ported to SchemaEditor in future anyway, so it's only useful in the transition.Looking at the discussion, I think the best thing to do is:- Make the schema and migrations test skip if connection.schema_editor() raises a NotImplementedError (not too hard, we can implement connection.has_schema_editor as a boolean to switch on)
- Provide some way to skip the "creating models" part of test setup, so SchemaEditor is never needed during it
I still think all the current third-party backends should be able to provide a partial SchemaEditor implementation though, as at minimum they all have the DatabaseCreation code in place to make new models. Bear in mind that the ./manage.py sqlmigrate command lets you turn migrations into SQL scripts to send to your DBA (and many DBAs appreciate having some SQL they can work from - I know ours do), so having the ability to make that SQL is useful even if Django never runs it.
My request would probably be better read as "Must a database backend support schema alterations?", which also implies its ability to do a migration that alters the schema. Data only migrations would still technically be possible without the ability to alter the schema, but I'm not sure if that functionality would be as useful by itself.
I think we all agree that any database backend must continue to be able to create or delete schema objects, or provide something like Oracle's TEST_CREATE setting to allow that to be done as a non-Django step. I think it is reasonable to require any backend to support that portion of SchemaEditor.I think we should have a property on DatabaseFeature that sniffs SchemaEditor to figure out whether it supports alterations. That would let us use the existing database feature decorators to skip tests.
I'm not sure I like this generic plan, but I don't have all of the details and the discussion can be deferred until a later date. There is some value in having a distinction between something that creates just the databases (or files) and something that creates the schema inside of the databases.
Other than time constraints, is there a reason not to update DatabaseCreation in Django 1.7 so that is little more than a proxy to SchemaEditor for the create/delete sql? I think we all agree that any database backend must be able to create/delete the schema, so I don't think it makes much of a difference whether that happens in DatabaseCreation or SchemaEditor. All of the database backend API has been deemed internal API on several occasions, so it should be safe to make this sort of change and also not necessarily be subject to the alpha feature freeze. I'd be happy to work on this.
I think it's okay to require SchemaEditor to exist with minimal functionality. It would be ideal if this minimal SchemaEditor was provided. Disabling the alterations with a DatabaseFeature would make the existing BaseDatabaseSchemaEditor on par with BaseDatabaseCreation's ability to create/delete schema objects.
On Wed, Jan 22, 2014 at 5:15 PM, Michael Manfre <mma...@gmail.com> wrote:
My request would probably be better read as "Must a database backend support schema alterations?", which also implies its ability to do a migration that alters the schema. Data only migrations would still technically be possible without the ability to alter the schema, but I'm not sure if that functionality would be as useful by itself.I would say "yes", if something wants to claim to be a fully-supported Django backend. In this day and age being able to alter the schema is something that a framework/ORM should be providing, IMO.
I think it's okay to require SchemaEditor to exist with minimal functionality. It would be ideal if this minimal SchemaEditor was provided. Disabling the alterations with a DatabaseFeature would make the existing BaseDatabaseSchemaEditor on par with BaseDatabaseCreation's ability to create/delete schema objects.
When you say "provided", what do you mean? The current base SchemaEditor provides a lot and once we've fixed up some of the issues you raised with the MSSQL patch it should be a lot better, certainly within reason to inherit it and just set the alteration stuff to NotImplementedError.
What about moving this kind of migration support from database driver
to django core as an universal fallback ?
My argument for this is that it is remarkably hard to do schema
migrations properly even for backends which "support it". You do not
want to end up with 3 days downtime "while the database migrates"
because you trusted django to do the right thing and it worked ok in
your (small) test database.
Automatic migrations are very useful at development time, but need
lots of TLC when done in production environment. They are hard enough
to orchestrate propery at pure SQL level. Adding an extra layer on top
with largely undefined performance characteristics makes things much
more complikated still.
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/e3bd21ad-6aec-4686-a037-69d486f969a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/81dcde2e-babb-4714-829e-b9308f3672cd%40googlegroups.com.
Hi.
Before v1.7 there were no migrations and Django was quite useful (for example with South as an 3rd party app). What happened then?I think that migrations can be decoupled from core and you just don't want to do this for some unknown reason.I'll prepare a pull request if it will not be dropped because of some kind of ethos.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/2907b0fa-e705-4208-8138-01c75bac02fe%40googlegroups.com.