Opened 10 years ago

Closed 5 years ago

#4528 closed New feature (wontfix)

Add DATABASE_PRE_SYNCDB to settings

Reported by: Johan Bergström <bugs@…> Owned by:
Component: Core (Management commands) Version: master
Severity: Normal Keywords: database_pre_syncdb sql syncdb
Cc: Silver_Ghost Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

DATABASE_PRE_SYNCDB is a way of letting users execute SQL before tables are created (for instance through syncdb).
The main reason for this is users which don't have control over their db - in practise, no rights to set default modes (which has been brought up earlier). This would allow users to set the "correct" charset and storage engine for his/her tables.
Another useful feature is that django now has the possibility to create a database.
Here's a "real world" example:

DATABASE_PRE_SYNCDB = (
    "CREATE DATABASE IF NOT EXISTS %s" % DATABASE_NAME,
    "SET storage_engine=INNODB",
)

Alternative approaches to this has been suggested, such as:

  • Alter tables after the table has been created (refs: wiki:AlterModelOnSyncDB)
  • Export SQL, modify and import manually

I personally think this implementation is cleaner and allows greater flexibility.

Attachments (4)

pre_syncdb_sql_hook.patch (818 bytes) - added by Johan Bergström <bugs@…> 10 years ago.
database_pre_syncdb patch
db_pre_sync_r6799.patch (2.4 KB) - added by George Vilches 9 years ago.
pre_sync_updated.patch (4.2 KB) - added by Silver_Ghost 5 years ago.
Updated patch. Tests included.
pre_syncdb_updated.patch (8.5 KB) - added by Silver_Ghost 5 years ago.
Updated patch with tests.

Download all attachments as: .zip

Change History (18)

Changed 10 years ago by Johan Bergström <bugs@…>

Attachment: pre_syncdb_sql_hook.patch added

database_pre_syncdb patch

comment:1 Changed 9 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 9 years ago by George Vilches <gav@…>

If we're going allow modifications before all the sync activities, why not just create a pre_syncdb signal. That way it won't be yet another setting to clutter the 99% case, but people could easily add the dispatcher to a management.py in their own app.

Or, with the new management refactor, maybe a user should just add their own command entirely, and have their command call the syncdb command?

comment:3 in reply to:  2 Changed 9 years ago by James Bennett

Replying to George Vilches <gav@thataddress.com>:

If we're going allow modifications before all the sync activities, why not just create a pre_syncdb signal. That way it won't be yet another setting to clutter the 99% case, but people could easily add the dispatcher to a management.py in their own app.

Or, with the new management refactor, maybe a user should just add their own command entirely, and have their command call the syncdb command?

I like both of these ideas. Feel like writing up an implementation of one of them?

Changed 9 years ago by George Vilches

Attachment: db_pre_sync_r6799.patch added

comment:4 Changed 9 years ago by George Vilches

The patch above implements the pre_dbsync signal idea against r6799.

comment:5 Changed 9 years ago by Jacob

Triage Stage: Design decision neededAccepted

comment:6 Changed 7 years ago by Adam Nelson

Patch needs improvement: set

Patch needs update to latest svn revision.

comment:7 Changed 6 years ago by Gabriel Hurley

Severity: Normal
Type: New feature

comment:8 Changed 5 years ago by Peter Baumgartner

Component: Core (Other)Core (Management commands)
Easy pickings: unset
Needs documentation: set
UI/UX: unset

comment:9 Changed 5 years ago by Silver_Ghost

Needs tests: set
Owner: changed from nobody to Silver_Ghost
Status: newassigned

comment:10 Changed 5 years ago by Silver_Ghost

Cc: Silver_Ghost added

Changed 5 years ago by Silver_Ghost

Attachment: pre_sync_updated.patch added

Updated patch. Tests included.

comment:11 Changed 5 years ago by Silver_Ghost

Easy pickings: set
Needs tests: unset
Patch needs improvement: unset

I put tests in regressiontests/syncdb according to advice from Russell.

comment:12 Changed 5 years ago by Silver_Ghost

Test for check that pre_syncdb is emitted at the right time added.

Changed 5 years ago by Silver_Ghost

Attachment: pre_syncdb_updated.patch added

Updated patch with tests.

comment:13 Changed 5 years ago by Silver_Ghost

Needs documentation: unset
Owner: Silver_Ghost deleted
Status: assignednew

Added send of pre_syncdb signal in flush command and documentation. Documentation probably is not good enough but I can't write better because of my poor English.

comment:14 Changed 5 years ago by Chris Beaven

Resolution: wontfix
Status: newclosed

It seems like this ticket has been hijacked for a different purpose. I'm wontfixing the idea of a DATABASE_PRE_SYNCDB setting, but not a pre_syncdb signal.

We have ticket #11398 to track that, I'll move Silver_Ghost's patch there.

Note: See TracTickets for help on using tickets.
Back to Top