#6148: Add generic support for database schemas
-------------------------------------+-------------------------------------
Reporter: ikelly | Owner: akaariai
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: oracle postgresql | Needs documentation: 1
mysql schemas | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Comment (by akaariai):
I had an idea about this some time ago. Instead of building support for
{{{
class MyModel:
...
class Meta:
db_schema = 'foobar'
db_table = 'sometable'
}}}
we should implement something like this
{{{
class MyModel:
...
class Meta:
db_table = SchemaQualifiedTable('sometable', schema='foobar')
}}}
The idea is that the model's db_table is actually a class that knows how
to produce SQL for itself. This could be used for schema qualified tables,
and also for producing SQL view like behavior. That is, you could push in
a custom View("select * from foobar") object. Then for QuerySet
{{{
MyModel.objects.all()
}}}
django would produce SQL
{{{
SELECT * FROM (select * from foobar) T1
}}}
the SQL inside the parentheses is produced by the View() class.
Even if users can access schema qualified tables by implementing a
SchemaQualifiedTable class, we still need a bit more knowledge of the
schema inside Django. The SchemaQualifiedTable class would work for
existing databases, but the schema attribute of the table class must be
supported by Django in some places (for example introspecting if the table
already exists, and also automatic creation of the schema in migrations).
It would also be possible to use a dynamic schema if wanted (just
implement a custom Table class that changes the schema dynamically), but
Django wouldn't officially support dynamic schemas. The simple reason is
that nobody is ever going to implement delete cascades for dynamic
schemas. Also, multi-schema migrations seem like too hard of a problem to
solve.
--
Ticket URL: <https://code.djangoproject.com/ticket/6148#comment:155>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.09b881f101cb300e62ace555ba153999%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.