-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add new command fore create migration file #4
base: master
Are you sure you want to change the base?
Conversation
28a5bc8
to
d9b9105
Compare
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.
Please fix all notices.
internal/command/migrate_create.go
Outdated
} | ||
|
||
func create(migrationDir string, name string, extension string) (string, error) { | ||
fileName := filepath.Join( |
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.
Merge please all variables declaration to var block.
internal/command/migrate_create.go
Outdated
"", | ||
}, "\n") | ||
|
||
f, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) |
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.
Same code style notice use var
instead of :=
.
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.
fixed
internal/command/migrate_create.go
Outdated
if err != nil { | ||
return fileName, err | ||
} | ||
defer func(f *os.File) { |
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.
Remove please defer function argument because copy pointers this is bad idea.
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.
ok, done
internal/command/migrate_create.go
Outdated
}(f) | ||
|
||
_, err = f.WriteString(fileContent) | ||
if err != nil { |
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.
Simplify this to return fileName, err
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.
fixed
internal/command/migrate_create.go
Outdated
Args: cobra.MaximumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return ctn.Call(func(ctx context.Context, logger *zap.Logger) (err error) { | ||
const extension string = "sql" |
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.
Make please this const as package global const.
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.
Moved to global scope
internal/command/migrate_create.go
Outdated
However some SQL commands (for example creating an index concurrently in PostgreSQL) | ||
cannot be executed inside a transaction. In order to execute such a command in a migration, | ||
the migration can be run using the notransaction option https://github.com/rubenv/sql-migrate`, | ||
Args: cobra.MaximumNArgs(1), |
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.
Use cobra.ExactArgs(1) instead of cobra.MaximumNArgs(1)
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.
done
internal/command/migrate_create.go
Outdated
return ctn.Call(func(ctx context.Context, logger *zap.Logger) (err error) { | ||
const extension string = "sql" | ||
|
||
var name = "example" |
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.
This block should be removed.
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.
done
19a62c5
to
d82b676
Compare
231bfee
to
c447944
Compare
No description provided.