Skip to content
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

Merged
merged 10 commits into from
Oct 28, 2019
Merged

[Proposal] Add --skip-drop option #44

merged 10 commits into from
Oct 28, 2019

Conversation

touyu
Copy link
Contributor

@touyu touyu commented Oct 27, 2019

issue: #43

I implemented the --skip-drop option as one way to avoid destructive changes.
Please consider it.

@@ -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"`
Copy link
Collaborator

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?

Copy link
Contributor Author

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 !

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)
Copy link
Collaborator

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;.

Copy link
Contributor Author

@touyu touyu Oct 28, 2019

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.

@k0kubun
Copy link
Collaborator

k0kubun commented Oct 28, 2019

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.

@touyu touyu changed the title [Proposal] Add safety option [Proposal] Add --skip-drop option Oct 28, 2019
@touyu
Copy link
Contributor Author

touyu commented Oct 28, 2019

@k0kubun
Thank you for reviews.
I would be happy if you could check it again.

Copy link
Collaborator

@k0kubun k0kubun left a 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.

@k0kubun k0kubun merged commit fa5d0dd into sqldef:master Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants