-
-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] Add --skip-drop option #44
Conversation
cmd/mysqldef/mysqldef.go
Outdated
@@ -26,6 +26,7 @@ func parseOptions(args []string) (adapter.Config, *sqldef.Options) { | |||
File string `long:"file" description:"Read schema SQL from the file, rather than stdin" value-name:"sql_file" default:"-"` | |||
DryRun bool `long:"dry-run" description:"Don't run DDLs but just show them"` | |||
Export bool `long:"export" description:"Just dump the current schema to stdout"` | |||
Safety bool `long:"safety" description:"Not make destructive changes such as Drop"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel --skip-drop
might be more descriptive about what it does than --safety
. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think --skip-drop
is better than --safety
!
adapter/database.go
Outdated
transaction, err := d.DB().Begin() | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println("-- Apply --") | ||
for _, ddl := range ddls { | ||
if isSafety && strings.Contains(ddl, "DROP") { | ||
fmt.Printf("Not executed: %s;\n", ddl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqldef's output is designed to always be a valid input for mysql
/psql
. Could you prefix --
to make it a SQL comment?
And if you follow https://github.com/k0kubun/sqldef/pull/44/files#r339372757, it'd be -- Skipped: %s;
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand.
I think --Skipped: %s;
is good.
Could you add the same option to psqldef for consistency, and update the README as well? Also, it'd be really nice if we can have tests in mysqldef_test.go and psqldef_test.go. |
@k0kubun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job 👍
I'm a little concerned about just checking "DROP" inclusion in DDL (we could have DROP in a part of table/column/index names) and I'd prefer having a metadata like Drop: true
for each statement in the future. However, I believe this implementation would work for most of usual situations, so I'm merging this.
issue: #43
I implemented the
--skip-drop
option as one way to avoid destructive changes.Please consider it.