cmd/cli/handler_migrate.go
Function readMigrations
has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring. Open
Open
func readMigrations(migrationSourceFS fs.FS, expectedDialects []string) (map[string]*migrationGroup, error) {
mgs := make(map[string]*migrationGroup)
err := fs.WalkDir(migrationSourceFS, ".", func(p string, d fs.DirEntry, err2 error) error {
if err2 != nil {
fmt.Println("Warning: unexpected error " + err2.Error())
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function readMigrations
has 61 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func readMigrations(migrationSourceFS fs.FS, expectedDialects []string) (map[string]*migrationGroup, error) {
mgs := make(map[string]*migrationGroup)
err := fs.WalkDir(migrationSourceFS, ".", func(p string, d fs.DirEntry, err2 error) error {
if err2 != nil {
fmt.Println("Warning: unexpected error " + err2.Error())
Function readMigrations
has 11 return statements (exceeds 4 allowed). Open
Open
func readMigrations(migrationSourceFS fs.FS, expectedDialects []string) (map[string]*migrationGroup, error) {
mgs := make(map[string]*migrationGroup)
err := fs.WalkDir(migrationSourceFS, ".", func(p string, d fs.DirEntry, err2 error) error {
if err2 != nil {
fmt.Println("Warning: unexpected error " + err2.Error())
Method MigrateHandler.MigrateSQL
has 8 return statements (exceeds 4 allowed). Open
Open
func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) (err error) {
p, err := h.makePersister(cmd, args)
if err != nil {
return err
}
Method MigrateHandler.MigrateStatus
has 6 return statements (exceeds 4 allowed). Open
Open
func (h *MigrateHandler) MigrateStatus(cmd *cobra.Command, args []string) error {
p, err := h.makePersister(cmd, args)
if err != nil {
return err
}
Method migrationGroup.generateSQL
has 5 return statements (exceeds 4 allowed). Open
Open
func (mg migrationGroup) generateSQL(sourceFS fs.FS, target string) error {
ms := mg.Children
if mg.fallbackDownMigration != nil {
ms = append(ms, mg.fallbackDownMigration)
}
Method MigrateHandler.makePersister
has 5 return statements (exceeds 4 allowed). Open
Open
func (h *MigrateHandler) makePersister(cmd *cobra.Command, args []string) (p persistence.Persister, err error) {
var d driver.Registry
if flagx.MustGetBool(cmd, "read-from-env") {
d, err = driver.New(