Opened 16 years ago

Closed 10 years ago

#8348 closed New feature (fixed)

Feature request: -n/--no-act option to syncdb

Reported by: Kenneth Arnold Owned by: anonymous
Component: Core (Management commands) Version: dev
Severity: Normal Keywords: syncdb
Cc: kenneth.arnold@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I'm about to run syncdb on a project I help maintain, but I don't know what it's going to add to the database because I may not have been the last one to touch it.

It would be helpful to have a -n/--no-act option that would report what it would do, but not actually do it.

Attachments (2)

8348-default_to_all_apps.diff (8.2 KB ) - added by Graham King 15 years ago.
Makes all the command that take a list of apps default to all the apps if none are given on the command line
8343-prompt.diff (4.9 KB ) - added by Graham King 15 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 by Malcolm Tredinnick, 16 years ago

Triage Stage: UnreviewedAccepted

This is a reasonable request. It's different from sqlall or anything like that, since it doesn't require an app to be specified.

An alternative implementation is to allow the app name to sqlall to be optional, defaulting to "all applications". This feels a little more natural to me, since it avoids adding another hyphen-prefixed option.

comment:2 by anonymous, 15 years ago

Owner: changed from nobody to anonymous
Status: newassigned

comment:3 by Graham King, 15 years ago

Owner: changed from anonymous to Graham King
Status: assignednew

comment:4 by Graham King, 15 years ago

Status: newassigned

by Graham King, 15 years ago

Makes all the command that take a list of apps default to all the apps if none are given on the command line

comment:5 by Graham King, 15 years ago

Has patch: set
Triage Stage: AcceptedDesign decision needed

Attached is a patch that does what Malcolm suggested, a bit wider even, so that all AppCommand that don't get given an app default to all the apps. It includes updates to the tests so that they still all pass. I think defaulting to all the apps makes sense. The only command that could of been dangerous is 'reset' and it will give you the warning for each app you try to reset.

But I don't think that's what the bug is about. 'sqlall' prints all the SQL necessary to create the database, whereas we want to see just the SQL that syncdb would execute. We want a '--pretend' option (like Gentoo's portage) which shows what it would do without doing it. And that turns out to be a tricky problem.

The post_sync signal fire during the syncdb run makes it difficult to know what is going to run, so we have to go wider than just the syncdb command. And some of the post_sync listeners reply on being able to 'select' from tables created in syncdb, so the SQL has to actually run. And transactions don't cover SQL DDL statements (CREATE, ALTER, etc), at least in MySQL InnoDB, so we can't rollback.
Here's what I tried doing :

  • Just printing out the SQL in syncdb instead of running it. This doesn't cover the post_sync listeners, and breaks any later selects.
  • I tried monkey patching connection.cursor to create pretend cursors that log instead of executing. This was the most promising, but it breaks SELECTs down the line.
  • I tried starting a transaction and rolling back at the end. That doesn't work with MyISAM, and more importantly doesn't cover DDL statements, which is most of what syncdb does.

I think the solution is for --pretend to copy the whole database, using the 'dumpdata' command and parts of the 'testserver' command, run on the copy whilst logging the SQL, and drop the copy. That's some heavy lifting, so I'm setting this back to 'Design Decision Needed' for a yes or no on database copy, or suggestions on a better way of approaching this.

comment:6 by Kenneth Arnold, 15 years ago

A possible compromise is a -i/--interactive option: ask before actually making a modification.

comment:7 by Graham King, 15 years ago

Needs documentation: set
Triage Stage: Design decision neededAccepted

Apologies for taking so long to get back to this, and thanks for the suggestion kcarnold.

The 8343-prompt patch adds a '--prompt' option to syncdb ('interactive' already means something different to syncdb), which will display each line of SQL and ask for confirmation before executing it.

It works by wrapping the cursor in a CursorInteractiveWrapper, which is similar to the CursorDebugWrapper.

by Graham King, 15 years ago

Attachment: 8343-prompt.diff added

comment:8 by Graham King, 15 years ago

Needs documentation: unset

Updated 8343-prompt.diff to include docs.

Tested on MySQL. Needs testing on Postgres, sqlite and Oracle.

BTW, please ignore the typo in the name, it should be 8348-prompt, to match the ticket number.

comment:9 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:10 by Luke Plant, 13 years ago

Severity: Normal
Type: New feature

comment:11 by patchhammer, 13 years ago

Easy pickings: unset
Patch needs improvement: set

8343-prompt.diff fails to apply cleanly on to trunk

comment:12 by anonymous, 13 years ago

Owner: changed from Graham King to anonymous
Status: assignednew

comment:13 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:14 by Aymeric Augustin, 10 years ago

Resolution: fixed
Status: newclosed

django-admin.py migration --list provides this feature in Django 1.7.

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