#5858: Model Meta option: disable SQL generation
-----------------------+----------------------------------------------------
Reporter: honeyman | Owner: nobody
Status: new | Component: Database wrapper
Version: 0.96 | Keywords:
Stage: Unreviewed | Has_patch: 1
-----------------------+----------------------------------------------------
A new Meta option would be nice to have for models. It could selectively
disable generation of SQL (related to the model) in operations like
sqlreset/sqlall/etc.
Proposed option name is sql_generation_required; default value (no legacy
behaviour change) is True. If sql_generation_required is False for the
model, this means that the SQL generation on sqlreset/sqlall/syncdb/etc
does not perform any DROP TABLE/ALTER TABLE/CREATE TABLE/CREATE INDEX for
this model. Note that sqlcustom still generates the code related to this
model (if someone wants to block the custom datafill from getting into the
sqlall file, one should remove the custom sql datafill rather than set any
meta options).
Real life use case is: django application which heavily mixes the tables
generated automatically by Django ORM and the custom SQL code - custom
indexes, custom constraints, custom views. If we want to create an SQL
view and use it in Django, the most obvious way is to create the SQL view
manually (CREATE VIEW myview AS ...), and then generate the Django model
resembling this view (class MyView(models.Model): class Meta: db_table =
'myview'). But this will mean, that any attempt to regenerate the django-
controlled tables (manage.py reset mysite) will cause an attempt to drop
this model like it was a table (DROP TABLE myview;) and recreate it again
(CREATE TABLE myview (...) ) - and both actions will fail.
The most simple way to fix this is to mark only the custom-controlled
model ("myview" in our case) in the way so that "manage.py reset mysite"
will not touch it at all. This could be done in the following way:
class MyView(models.Model):
class Meta:
db_table = 'myview'
sql_generation_required = False
...
Below goes the proposed patch for this feature; sorry for GNU diff format
and for being based on 0.96 rather than trunk - no SVN here.
--
Ticket URL: <http://code.djangoproject.com/ticket/5858>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---