#22898: Specify backend name for custom SQL
--------------------------------------------+------------------------
Reporter: shaung | Owner: nobody
Type: New feature | Status: new
Component: Core (Management commands) | Version: 1.6
Severity: Normal | Keywords: custom sql
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------------+------------------------
'''The problem:'''
Say I have a model named `AwesomeModel` which is managed but several
functions need to be created along with the table.
So I created a `awesomemodel.sql` and put all the DDLs in it. In this way
when running unittests the functions get created without problem.
Now as there are multiple DB backends defined in the `settings`, I'd like
the custom SQL run only for the `default` DB but not for `another_schema`:
{{{
DATABASES = {
"default": {
"ENGINE": "django_pyodbc",
# ...
},
"another_schema": {
"ENGINE": "django_pyodbc",
# ...
}
}
}}}
It seems that custom SQLs can be specified to be executed for certain
engines:
https://github.com/django/django/blob/master/django/core/management/sql.py#L221
{{{
# Find custom SQL, if it's available.
backend_name = connection.settings_dict['ENGINE'].split('.')[-1]
}}}
But for multiple backends that use the same engine, there is no way to
distinguish from them.
So changing the file name to `model_name.django_pyodbc.sql` does not solve
this problem.
'''Suggestion:'''
Add a new file custom SQL file name pattern to allow specify the target
backend by backend name:
`<Model Name>.<Engine Name>.<Backend Name>.sql`
(In my case it would be `awesomemodel.django_pyodbc.default.sql`)
--
Ticket URL: <https://code.djangoproject.com/ticket/22898>
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/049.402ed3de2d502aaa7f7feb8eb5cdcf33%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.