Opened 18 years ago

Closed 13 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: dev
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@…> 18 years ago.
database_pre_syncdb patch
db_pre_sync_r6799.patch (2.4 KB ) - added by George Vilches 17 years ago.
pre_sync_updated.patch (4.2 KB ) - added by Silver_Ghost 13 years ago.
Updated patch. Tests included.
pre_syncdb_updated.patch (8.5 KB ) - added by Silver_Ghost 13 years ago.
Updated patch with tests.

Download all attachments as: .zip

Change History (18)

by Johan Bergström <bugs@…>, 18 years ago

Attachment: pre_syncdb_sql_hook.patch added

database_pre_syncdb patch

comment:1 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by George Vilches <gav@…>, 17 years ago

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?

in reply to:  2 comment:3 by James Bennett, 17 years ago

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?

by George Vilches, 17 years ago

Attachment: db_pre_sync_r6799.patch added

comment:4 by George Vilches, 17 years ago

The patch above implements the pre_dbsync signal idea against r6799.

comment:5 by Jacob, 17 years ago

Triage Stage: Design decision neededAccepted

comment:6 by Adam Nelson, 15 years ago

Patch needs improvement: set

Patch needs update to latest svn revision.

comment:7 by Gabriel Hurley, 14 years ago

Severity: Normal
Type: New feature

comment:8 by Peter Baumgartner, 13 years ago

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

comment:9 by Silver_Ghost, 13 years ago

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

comment:10 by Silver_Ghost, 13 years ago

Cc: Silver_Ghost added

by Silver_Ghost, 13 years ago

Attachment: pre_sync_updated.patch added

Updated patch. Tests included.

comment:11 by Silver_Ghost, 13 years ago

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

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

comment:12 by Silver_Ghost, 13 years ago

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

by Silver_Ghost, 13 years ago

Attachment: pre_syncdb_updated.patch added

Updated patch with tests.

comment:13 by Silver_Ghost, 13 years ago

Needs documentation: unset
Owner: Silver_Ghost removed
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 by Chris Beaven, 13 years ago

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