[Django] #22898: Specify backend name for custom SQL

10 views
Skip to first unread message

Django

unread,
Jun 24, 2014, 11:35:06 PM6/24/14
to django-...@googlegroups.com
#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.

Django

unread,
Jun 25, 2014, 12:17:15 AM6/25/14
to django-...@googlegroups.com
#22898: Specify backend name for custom SQL
-------------------------------------+-------------------------------------

Reporter: shaung | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) | Resolution:
Severity: Normal | Triage Stage:
Keywords: custom sql | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by shaung):

* needs_better_patch: => 0
* version: 1.6 => master
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/22898#comment:1>

Django

unread,
Jun 25, 2014, 3:23:59 AM6/25/14
to django-...@googlegroups.com
#22898: Specify backend name for custom SQL
-------------------------------------+-------------------------------------
Reporter: shaung | Owner: nobody
Type: New feature | Status: closed

Component: Core (Management | Version: master
commands) | Resolution: wontfix

Severity: Normal | Triage Stage:
Keywords: custom sql | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* 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>

Reply all
Reply to author
Forward
0 new messages