Django

Code

Ticket #6064 (assigned)

Opened 11 months ago

Last modified 4 months ago

Allow database connection initialization commands

Reported by: jacob Assigned to: floguy (accepted)
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords:
Cc: telenieko@telenieko.com, dan90, floguy@gmail.com, jshaffer, sam@robots.org.uk, feteanumarius@yahoo.com, contact@jfsimon.fr, greg@gregturner.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

There's sometimes a need to pass specific SQL that'll get executed at the beginning of every database connection (for just one example see #1051).

This could be in the form of a setting, a signal, or perhaps some other mechanism.

Attachments

6064.diff (5.6 kB) - added by floguy on 12/01/07 18:27:03.
Patch to add CONNECTION_INIT_SQL setting and use it on connection initialization.
6064-using-signals.diff (7.8 kB) - added by floguy on 12/04/07 14:51:08.
Changed the implementation method to emit a signal instead of execute a tuple from the settings.

Change History

11/30/07 15:16:13 changed by jacob

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

12/01/07 07:36:24 changed by telenieko

  • cc set to telenieko@telenieko.com.

cc'ing me

12/01/07 08:45:46 changed by jacob

See also #3460.

12/01/07 18:25:50 changed by floguy

  • cc changed from telenieko@telenieko.com to telenieko@telenieko.com, floguy@gmail.com.
  • has_patch set to 1.
  • needs_tests set to 1.

Wrote a patch to fix this, with documentation. It should be fairly straighforward:

Added a CONNECTION_INIT_SQL setting, which is a tuple of strings to be executed on connection initialization.

For example,

CONNECTION_INIT_SQL = (
    'SET search_path TO django_application_schema',
)

would accomplish the same thing as ticket:1051

Ran test suite and there were no regressions, but tests for this new feature are needed.

12/01/07 18:27:03 changed by floguy

  • attachment 6064.diff added.

Patch to add CONNECTION_INIT_SQL setting and use it on connection initialization.

12/01/07 19:04:32 changed by floguy

  • owner changed from nobody to floguy.
  • status changed from new to assigned.

12/01/07 22:04:23 changed by Simon G <dev@simon.net.nz>

  • needs_tests deleted.
  • stage changed from Accepted to Ready for checkin.

12/04/07 13:55:39 changed by jacob

  • needs_better_patch set to 1.
  • needs_tests set to 1.
  • stage changed from Ready for checkin to Accepted.

Looking at this, I *REALLY* don't like having SQL in the settings file. So I think that a connection-created signal is the right way to do this, not a setting.

12/04/07 14:50:49 changed by floguy

I have added a new patch which uses signals instead of a setting. I think you're right, too, that the signal method is better. It allows for more flexibility while not cluttering up the settings file. The only reason that I originally implemented the settings file originally was due to concerns about performance.

One thing: I wasn't sure where to put the new signal. It doesn't seem to fit where any of the other signals are defined, so I created django.db.backends.signals with this one signal in it.

12/04/07 14:51:08 changed by floguy

  • attachment 6064-using-signals.diff added.

Changed the implementation method to emit a signal instead of execute a tuple from the settings.

12/31/07 00:07:13 changed by anonymous

  • needs_better_patch deleted.
  • needs_tests deleted.

12/31/07 00:09:57 changed by jshaffer

  • cc changed from telenieko@telenieko.com, floguy@gmail.com to telenieko@telenieko.com, floguy@gmail.com, jshaffer.

01/21/08 06:04:43 changed by anonymous

  • cc changed from telenieko@telenieko.com, floguy@gmail.com, jshaffer to telenieko@telenieko.com, floguy@gmail.com, jshaffer, sam@robots.org.uk.

03/02/08 02:56:30 changed by MariusBoo

  • cc changed from telenieko@telenieko.com, floguy@gmail.com, jshaffer, sam@robots.org.uk to telenieko@telenieko.com, floguy@gmail.com, jshaffer, sam@robots.org.uk, feteanumarius@yahoo.com.

For anyone looking for a quick and dirty solution you ca define your table like this: db_table = '"django"."company"'. This will fool the quote function to think that your table is properly quoted. This also means that you have to specify the schema for each table manually.

05/28/08 01:41:44 changed by jfsimon_fr

  • cc changed from telenieko@telenieko.com, floguy@gmail.com, jshaffer, sam@robots.org.uk, feteanumarius@yahoo.com to telenieko@telenieko.com, floguy@gmail.com, jshaffer, sam@robots.org.uk, feteanumarius@yahoo.com, contact@jfsimon.fr.

cc'ing me too (hello !)

07/02/08 03:22:41 changed by cogat

  • cc changed from telenieko@telenieko.com, floguy@gmail.com, jshaffer, sam@robots.org.uk, feteanumarius@yahoo.com, contact@jfsimon.fr to telenieko@telenieko.com, floguy@gmail.com, jshaffer, sam@robots.org.uk, feteanumarius@yahoo.com, contact@jfsimon.fr, greg@gregturner.com.

07/02/08 07:52:06 changed by dan90

  • cc changed from telenieko@telenieko.com, floguy@gmail.com, jshaffer, sam@robots.org.uk, feteanumarius@yahoo.com, contact@jfsimon.fr, greg@gregturner.com to telenieko@telenieko.com, dan90, floguy@gmail.com, jshaffer, sam@robots.org.uk, feteanumarius@yahoo.com, contact@jfsimon.fr, greg@gregturner.com.

Add/Change #6064 (Allow database connection initialization commands)




Change Properties
Action