Skip to content

Commit

Permalink
fix nilaway
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl committed Oct 16, 2024
1 parent 77ede63 commit e0192c7
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 35 deletions.
6 changes: 2 additions & 4 deletions database/console/driver/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ func init() {
database.Register("sqlite", &Sqlite{})
}

var DefaultMigrationsTable = "schema_migrations"
var (
ErrDatabaseDirty = fmt.Errorf("database is dirty")
ErrNilConfig = fmt.Errorf("no config")
ErrNoDatabaseName = fmt.Errorf("no database name")
DefaultMigrationsTable = "schema_migrations"
ErrNilConfig = fmt.Errorf("no config")
)

type Config struct {
Expand Down
6 changes: 3 additions & 3 deletions database/console/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package migration

import (
"database/sql"
"errors"
"fmt"

"github.com/golang-migrate/migrate/v4"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/goravel/framework/contracts/database"
"github.com/goravel/framework/database/console/driver"
databasedb "github.com/goravel/framework/database/db"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support"
)

Expand All @@ -28,7 +28,7 @@ func getMigrate(config config.Config) (*migrate.Migrate, error) {
configBuilder := databasedb.NewConfigBuilder(config, connection)
writeConfigs := configBuilder.Writes()
if len(writeConfigs) == 0 {
return nil, errors.New("not found database configuration")
return nil, errors.OrmDatabaseConfigNotFound

Check warning on line 31 in database/console/migration/migrate.go

View check run for this annotation

Codecov / codecov/patch

database/console/migration/migrate.go#L31

Added line #L31 was not covered by tests
}

switch dbDriver {
Expand Down Expand Up @@ -110,6 +110,6 @@ func getMigrate(config config.Config) (*migrate.Migrate, error) {

return migrate.NewWithDatabaseInstance(dir, "sqlserver", instance)
default:
return nil, errors.New("database driver only support mysql, postgres, sqlite and sqlserver")
return nil, errors.OrmDriverNotSupported

Check warning on line 113 in database/console/migration/migrate.go

View check run for this annotation

Codecov / codecov/patch

database/console/migration/migrate.go#L113

Added line #L113 was not covered by tests
}
}
2 changes: 1 addition & 1 deletion database/console/migration/migrate_fresh_command.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package migration

import (
"errors"
"strings"

"github.com/golang-migrate/migrate/v4"

"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/color"
)

Expand Down
5 changes: 2 additions & 3 deletions database/console/migration/migrate_make_command.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package migration

import (
"errors"

"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/contracts/database/migration"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/color"
)

Expand Down Expand Up @@ -47,7 +46,7 @@ func (r *MigrateMakeCommand) Handle(ctx console.Context) error {
name, err = ctx.Ask("Enter the migration name", console.AskOption{
Validate: func(s string) error {
if s == "" {
return errors.New("the migration name cannot be empty")
return errors.MigrationNameIsRequired

Check warning on line 49 in database/console/migration/migrate_make_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/migration/migrate_make_command.go#L49

Added line #L49 was not covered by tests
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion database/console/migration/migrate_refresh_command.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package migration

import (
"errors"
"strconv"
"strings"

Expand All @@ -10,6 +9,7 @@ import (
"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/color"
)

Expand Down
3 changes: 1 addition & 2 deletions database/console/migration/migrate_reset_command.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package migration

import (
"errors"

"github.com/golang-migrate/migrate/v4"

"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/color"
)

Expand Down
2 changes: 1 addition & 1 deletion database/console/migration/migrate_rollback_command.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package migration

import (
"errors"
"strconv"

_ "github.com/go-sql-driver/mysql"
Expand All @@ -11,6 +10,7 @@ import (
"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/color"
)

Expand Down
18 changes: 8 additions & 10 deletions database/console/seed_command.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package console

import (
"errors"
"fmt"

"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/contracts/database/seeder"
contractsseeder "github.com/goravel/framework/contracts/database/seeder"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/color"
)

type SeedCommand struct {
config config.Config
seeder seeder.Facade
seeder contractsseeder.Facade
}

func NewSeedCommand(config config.Config, seeder seeder.Facade) *SeedCommand {
func NewSeedCommand(config config.Config, seeder contractsseeder.Facade) *SeedCommand {
return &SeedCommand{
config: config,
seeder: seeder,
Expand Down Expand Up @@ -85,19 +83,19 @@ func (receiver *SeedCommand) ConfirmToProceed(force bool) error {
return nil
}

return errors.New("application in production use --force to run this command")
return errors.DBForceIsRequiredInProduction
}

// GetSeeders returns a seeder instances
func (receiver *SeedCommand) GetSeeders(names []string) ([]seeder.Seeder, error) {
func (receiver *SeedCommand) GetSeeders(names []string) ([]contractsseeder.Seeder, error) {
if len(names) == 0 {
return receiver.seeder.GetSeeders(), nil
}
var seeders []seeder.Seeder
var seeders []contractsseeder.Seeder
for _, name := range names {
seeder := receiver.seeder.GetSeeder(name)
if seeder == nil {
return nil, fmt.Errorf("no seeder of %s found", name)
return nil, errors.DBSeederNotFound.Args(name)

Check warning on line 98 in database/console/seed_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/seed_command.go#L98

Added line #L98 was not covered by tests
}
seeders = append(seeders, seeder)
}
Expand Down
3 changes: 2 additions & 1 deletion database/console/seed_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/suite"

"github.com/goravel/framework/contracts/database/seeder"
"github.com/goravel/framework/errors"
configmocks "github.com/goravel/framework/mocks/config"
consolemocks "github.com/goravel/framework/mocks/console"
seedermocks "github.com/goravel/framework/mocks/database/seeder"
Expand Down Expand Up @@ -51,7 +52,7 @@ func (s *SeedCommandTestSuite) TestConfirmToProceed() {

s.mockContext.On("OptionBool", "force").Return(false).Once()
err = s.seedCommand.ConfirmToProceed(false)
s.EqualError(err, "application in production use --force to run this command")
s.ErrorIs(err, errors.DBForceIsRequiredInProduction)
}

func (s *SeedCommandTestSuite) TestGetSeeders() {
Expand Down
5 changes: 4 additions & 1 deletion database/migration/sql_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ type SqlDriverSuite struct {
suite.Suite
mockConfig *mocksconfig.Config
driverToTestQuery map[contractsdatabase.Driver]*gorm.TestQuery
driver *SqlDriver
}

func TestSqlDriverSuite(t *testing.T) {
if env.IsWindows() {
t.Skip("Skipping tests of using docker")
}

suite.Run(t, &SqlDriverSuite{})
}

Expand Down
15 changes: 8 additions & 7 deletions database/service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,19 @@ func (r *ServiceProvider) Boot(app foundation.Application) {
}

func (r *ServiceProvider) registerCommands(app foundation.Application) {
if artisanFacade := app.MakeArtisan(); artisanFacade != nil {
config := app.MakeConfig()
schema := app.MakeSchema()
seeder := app.MakeSeeder()
artisan := app.MakeArtisan()
config := app.MakeConfig()
schema := app.MakeSchema()
seeder := app.MakeSeeder()

Check warning on line 73 in database/service_provider.go

View check run for this annotation

Codecov / codecov/patch

database/service_provider.go#L70-L73

Added lines #L70 - L73 were not covered by tests

artisanFacade.Register([]contractsconsole.Command{
if artisan != nil && config != nil && schema != nil && seeder != nil {
artisan.Register([]contractsconsole.Command{
consolemigration.NewMigrateMakeCommand(config, schema),
consolemigration.NewMigrateCommand(config, schema),

Check warning on line 78 in database/service_provider.go

View check run for this annotation

Codecov / codecov/patch

database/service_provider.go#L75-L78

Added lines #L75 - L78 were not covered by tests
consolemigration.NewMigrateRollbackCommand(config),
consolemigration.NewMigrateResetCommand(config),
consolemigration.NewMigrateRefreshCommand(config, artisanFacade),
consolemigration.NewMigrateFreshCommand(config, artisanFacade),
consolemigration.NewMigrateRefreshCommand(config, artisan),
consolemigration.NewMigrateFreshCommand(config, artisan),

Check warning on line 82 in database/service_provider.go

View check run for this annotation

Codecov / codecov/patch

database/service_provider.go#L81-L82

Added lines #L81 - L82 were not covered by tests
consolemigration.NewMigrateStatusCommand(config),
console.NewModelMakeCommand(),
console.NewObserverMakeCommand(),
Expand Down
4 changes: 4 additions & 0 deletions errors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ var (
CryptMissingIVKey = New("decrypt payload error: missing iv key")
CryptMissingValueKey = New("decrypt payload error: missing value key")

DBForceIsRequiredInProduction = New("application in production use --force to run this command")
DBSeederNotFound = New("not found %s seeder")

EventListenerNotBind = New("event %v doesn't bind listeners")

FilesystemDefaultDiskNotSet = New("please set default disk")
Expand All @@ -62,6 +65,7 @@ var (
LogDriverNotSupported = New("invalid driver: %s, only support stack, single, daily, custom").SetModule(ModuleLog)
LogEmptyLogFilePath = New("empty log file path").SetModule(ModuleLog)

MigrationNameIsRequired = New("migration name cannot be empty")
MigrationUnsupportedDriver = New("unsupported migration driver: %s")

OrmDatabaseConfigNotFound = New("not found database configuration")
Expand Down
2 changes: 1 addition & 1 deletion support/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
TestModelNormal

// Switch this value to control the test model.
TestModel = TestModelMinimum
TestModel = TestModelNormal
)

type ContainerType string
Expand Down

0 comments on commit e0192c7

Please sign in to comment.