Skip to content

Commit

Permalink
using new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobbrewer1 committed Jan 27, 2025
1 parent a31101d commit 5806ef4
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions pkg/migrations/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@ package migrations

import (
"fmt"
"sort"

"github.com/jacobbrewer1/goschema/pkg/models"
)

func (v *versioning) GetStatus() ([]*models.GoschemaMigrationVersion, error) {
sqlStmt := `
SELECT version
FROM goschema_migration_version
ORDER BY created_at DESC;
`

ids := make([]string, 0)
if err := v.db.Select(&ids, sqlStmt); err != nil {
return nil, fmt.Errorf("get status ids: %w", err)
versions, err := models.GetAllGoschemaMigrationVersion(v.db)

Check failure on line 11 in pkg/migrations/status.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

undefined: models.GetAllGoschemaMigrationVersion (typecheck)

Check failure on line 11 in pkg/migrations/status.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

undefined: models.GetAllGoschemaMigrationVersion) (typecheck)

Check failure on line 11 in pkg/migrations/status.go

View workflow job for this annotation

GitHub Actions / Code Approval

undefined: models.GetAllGoschemaMigrationVersion
if err != nil {
return nil, fmt.Errorf("error getting goschema migration versions: %w", err)
}

versions := make([]*models.GoschemaMigrationVersion, len(ids))
for i, id := range ids {
ver, err := models.GoschemaMigrationVersionByVersion(v.db, id)
if err != nil {
return nil, fmt.Errorf("get status version by version: %w", err)
}

versions[i] = ver
}
// Sort the versions by created_at.
sort.Slice(versions, func(i, j int) bool {
return versions[i].CreatedAt.Before(versions[j].CreatedAt)
})

return versions, nil
}

0 comments on commit 5806ef4

Please sign in to comment.