Opened 8 years ago

Closed 4 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@…> 8 years ago.
database_pre_syncdb patch
db_pre_sync_r6799.patch (2.4 KB) - added by gav 8 years ago.
pre_sync_updated.patch (4.2 KB) - added by Silver_Ghost 4 years ago.
Updated patch. Tests included.
pre_syncdb_updated.patch (8.5 KB) - added by Silver_Ghost 4 years ago.
Updated patch with tests.

Download all attachments as: .zip

Change History (18)

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

database_pre_syncdb patch

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 follow-up: Changed 8 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 8 years ago by ubernostrum

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 8 years ago by gav

comment:4 Changed 8 years ago by gav

The patch above implements the pre_dbsync signal idea against r6799.

comment:5 Changed 8 years ago by jacob

  • Triage Stage changed from Design decision needed to Accepted

comment:6 Changed 5 years ago by adamnelson

  • Patch needs improvement set

Patch needs update to latest svn revision.

comment:7 Changed 4 years ago by gabrielhurley

  • Severity set to Normal
  • Type set to New feature

comment:8 Changed 4 years ago by baumer1122

  • Component changed from Core (Other) to Core (Management commands)
  • Easy pickings unset
  • Needs documentation set
  • UI/UX unset

comment:9 Changed 4 years ago by Silver_Ghost

  • Needs tests set
  • Owner changed from nobody to Silver_Ghost
  • Status changed from new to assigned

comment:10 Changed 4 years ago by Silver_Ghost

  • Cc Silver_Ghost added

Changed 4 years ago by Silver_Ghost

Updated patch. Tests included.

comment:11 Changed 4 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 4 years ago by Silver_Ghost

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

Changed 4 years ago by Silver_Ghost

Updated patch with tests.

comment:13 Changed 4 years ago by Silver_Ghost

  • Needs documentation unset
  • Owner Silver_Ghost deleted
  • Status changed from assigned to new

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 4 years ago by SmileyChris

  • Resolution set to wontfix
  • Status changed from new to closed

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