Opened 16 years ago
Closed 11 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)
Change History (16)
comment:1 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:4 by , 16 years ago
Status: | new → assigned |
---|
by , 16 years ago
Attachment: | 8348-default_to_all_apps.diff added |
---|
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 , 16 years ago
Has patch: | set |
---|---|
Triage Stage: | Accepted → Design 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 , 16 years ago
A possible compromise is a -i/--interactive
option: ask before actually making a modification.
comment:7 by , 16 years ago
Needs documentation: | set |
---|---|
Triage Stage: | Design decision needed → Accepted |
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 , 16 years ago
Attachment: | 8343-prompt.diff added |
---|
comment:8 by , 16 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:10 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:11 by , 14 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
8343-prompt.diff fails to apply cleanly on to trunk
comment:12 by , 14 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:14 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
django-admin.py migration --list
provides this feature in Django 1.7.
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.