This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. Updating dependency versions 3. Fixed lint comments 4. Refactoring GitHub Actions
- Loading branch information
Showing
9 changed files
with
198 additions
and
204 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
golang 1.20.8 | ||
golang 1.20.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
go-dependencies: | ||
# https://asdf-vm.com/ | ||
asdf install golang | ||
# | ||
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint@latest && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | ||
go get -u github.com/onsi/ginkgo/v2@latest && go install github.com/onsi/ginkgo/v2/ginkgo@latest | ||
asdf install golang || : | ||
|
||
# https://github.com/securego/gosec | ||
go get -u github.com/securego/gosec/v2/cmd/gosec@latest && go install github.com/securego/gosec/v2/cmd/gosec@latest | ||
go install github.com/securego/gosec/v2/cmd/gosec@latest | ||
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest | ||
# | ||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | ||
go install github.com/nunnatsa/ginkgolinter/cmd/ginkgolinter@latest | ||
# | ||
go get -u golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest && go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest | ||
go install github.com/onsi/ginkgo/v2/ginkgo@latest | ||
# | ||
go install github.com/vektra/mockery/v2@latest | ||
# | ||
asdf reshim golang || : | ||
# | ||
go get -u -t -v ./... || : | ||
asdf reshim golang | ||
|
||
go-generate: | ||
go-generate: go-dependencies | ||
mockery | ||
go generate ./... | ||
|
||
go-test: | ||
golangci-lint run ./... | ||
go vet -vettool=$(which shadow) ./... | ||
go-lint: go-dependencies | ||
golangci-lint run | ||
ginkgolinter ./... | ||
go vet -vettool=$$(go env GOPATH)/bin/shadow ./... | ||
|
||
go-test: go-lint | ||
gosec ./... | ||
ginkgo -r -race --cover --coverprofile=.coverage-details.out ./... | ||
go tool cover -func=.coverage-details.out -o=.coverage.out | ||
ginkgo -r -race --cover --coverprofile=.coverage-ginkgo.out --junit-report=junit-report.xml ./... | ||
go tool cover -func=.coverage-ginkgo.out -o=.coverage.out | ||
cat .coverage.out | ||
|
||
go-all: go-dependencies go-generate go-test | ||
go-all-tests: go-dependencies go-generate go-lint go-test | ||
|
||
go-all: go-all-tests | ||
go mod tidy || : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package db | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/juju/zaputil/zapctx" | ||
"github.com/pkg/errors" | ||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func (receiver *DB) migrationDB() error { | ||
logger := zapctx.Default.Sugar() | ||
|
||
migrationDir, err := receiver.prepareMigrationDB() | ||
if err != nil { | ||
e := errors.Wrap(err, "database migration error") | ||
logger.Error(e) | ||
|
||
return e | ||
} else if len(migrationDir) == 0 { | ||
logger.Warn("Source for database migration not found - migration skipped") | ||
|
||
return nil | ||
} | ||
|
||
logger.Infof("Directory with database migrations: %s", migrationDir) | ||
|
||
// We connect to the database with the rights to edit the database schema | ||
sqlDb, err := sql.Open(receiver.Config.Dialect, receiver.getDSN(*receiver.connSchemaCredential)) | ||
if err != nil { | ||
logger.Error(fmt.Errorf("failed to connect to database to run migrations: %w", err)) | ||
|
||
return ErrDbMigration | ||
} | ||
|
||
defer func() { | ||
if e := sqlDb.Close(); e != nil { | ||
logger.Error(fmt.Errorf("failed to disconnect from database: %w", e)) | ||
} | ||
}() | ||
|
||
if e := goose.Up(sqlDb, migrationDir, goose.WithAllowMissing()); e != nil { | ||
logger.Error(e) | ||
|
||
return ErrDbMigration | ||
} | ||
|
||
logger.Info("Database migration completed") | ||
|
||
return nil | ||
} | ||
|
||
func (receiver *DB) prepareMigrationDB() (string, error) { | ||
if err := goose.SetDialect(receiver.Config.Dialect); err != nil { | ||
return "", err //nolint:wrapcheck | ||
} | ||
|
||
logger := zapctx.Default.Sugar() | ||
|
||
if receiver.dbEmbedMigrations != nil { | ||
logger.Debug("Configure Goose using embedded FS for migrations") | ||
|
||
goose.SetBaseFS(receiver.dbEmbedMigrations) | ||
|
||
return "migrations", nil | ||
} | ||
|
||
migrationDir := receiver.Config.GooseMigrationDir | ||
if len(migrationDir) != 0 { | ||
// Checking the availability of the directory with database migrations | ||
_, err := os.Stat(migrationDir) | ||
if errors.Is(err, os.ErrNotExist) { | ||
logger.Error(fmt.Errorf("directory '%s' with database migrations not found: %w", migrationDir, err)) | ||
|
||
return "", err //nolint:wrapcheck | ||
} | ||
|
||
logger.Infof("Directory with database migrations: %s", migrationDir) | ||
} | ||
|
||
return migrationDir, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.