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

Add new command fore create migration file #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Rototot
Copy link

@Rototot Rototot commented Jul 21, 2023

No description provided.

@Rototot Rototot force-pushed the add-new-create-command branch from 28a5bc8 to d9b9105 Compare July 21, 2023 07:29
Copy link
Member

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

}

func create(migrationDir string, name string, extension string) (string, error) {
fileName := filepath.Join(
Copy link
Member

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.

"",
}, "\n")

f, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
Copy link
Member

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 :=.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

if err != nil {
return fileName, err
}
defer func(f *os.File) {
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done

}(f)

_, err = f.WriteString(fileContent)
if err != nil {
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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"
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to global scope

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),
Copy link
Member

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return ctn.Call(func(ctx context.Context, logger *zap.Logger) (err error) {
const extension string = "sql"

var name = "example"
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Rototot Rototot force-pushed the add-new-create-command branch 2 times, most recently from 19a62c5 to d82b676 Compare August 1, 2023 17:44
@Rototot Rototot force-pushed the add-new-create-command branch from 231bfee to c447944 Compare August 1, 2023 17:59
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