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.
* needs_better_patch: => 0
* version: 1.6 => master
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/22898#comment:1>
* status: new => closed
* resolution: => wontfix
Comment:
As you can read in the documentation, custom SQL is deprecated.
https://docs.djangoproject.com/en/dev/howto/initial-data/#providing-
initial-sql-data
The recommended path now is to use data migrations, where you should be
able to consult settings and run (SQL) code accordingly.
--
Ticket URL: <https://code.djangoproject.com/ticket/22898#comment:2>