diff --git a/contracts/database/migration/grammar.go b/contracts/database/migration/grammar.go index 0da9b8b90..a04f322fa 100644 --- a/contracts/database/migration/grammar.go +++ b/contracts/database/migration/grammar.go @@ -9,6 +9,8 @@ type Grammar interface { CompileCreate(blueprint Blueprint, query orm.Query) string // CompileDropIfExists Compile a drop table (if exists) command. CompileDropIfExists(blueprint Blueprint) string + // CompileTables Compile the query to determine the tables. + CompileTables(database string) string // GetAttributeCommands Get the commands for the schema build. GetAttributeCommands() []string // GetModifiers Get the column modifiers. diff --git a/contracts/database/migration/repository.go b/contracts/database/migration/repository.go index e1c2e5bea..4c638539f 100644 --- a/contracts/database/migration/repository.go +++ b/contracts/database/migration/repository.go @@ -1,26 +1,30 @@ package migration +type File struct { + ID uint + Migration string + Batch int +} + type Repository interface { - //// CreateRepository Create the migration repository data store. - //CreateRepository() - //// Delete Remove a migration from the log. - //Delete(migration string) - //// DeleteRepository Delete the migration repository data store. - //DeleteRepository() - //// GetLast Get the last migration batch. - //GetLast() - //// GetMigrationBatches Get the completed migrations with their batch numbers. - //GetMigrationBatches() - //// GetMigrations Get the list of migrations. - //GetMigrations(steps int) - //// GetMigrationsByBatch Get the list of the migrations by batch. - //GetMigrationsByBatch(batch int) - //// GetNextBatchNumber Get the next migration batch number. - //GetNextBatchNumber() - //// GetRan Get the completed migrations. - //GetRan() - //// Log that a migration was run. - //Log(file, batch string) - //// RepositoryExists Determine if the migration repository exists. - //RepositoryExists() + // CreateRepository Create the migration repository data store. + CreateRepository() error + // Delete Remove a migration from the log. + Delete(migration string) error + // DeleteRepository Delete the migration repository data store. + DeleteRepository() error + // GetLast Get the last migration batch. + GetLast() ([]File, error) + // GetMigrations Get the list of migrations. + GetMigrations(steps int) ([]File, error) + // GetMigrationsByBatch Get the list of the migrations by batch. + GetMigrationsByBatch(batch int) ([]File, error) + // GetNextBatchNumber Get the next migration batch number. + GetNextBatchNumber() (int, error) + // GetRan Get the completed migrations. + GetRan() ([]string, error) + // Log that a migration was run. + Log(file string, batch int) error + // RepositoryExists Determine if the migration repository exists. + RepositoryExists() bool } diff --git a/contracts/database/migration/schema.go b/contracts/database/migration/schema.go index 281677544..ba864ab37 100644 --- a/contracts/database/migration/schema.go +++ b/contracts/database/migration/schema.go @@ -2,11 +2,15 @@ package migration type Schema interface { // Create a new table on the schema. - Create(table string, callback func(table Blueprint)) + Create(table string, callback func(table Blueprint)) error // Connection Get the connection for the schema. Connection(name string) Schema // DropIfExists Drop a table from the schema if exists. - DropIfExists(table string) + DropIfExists(table string) error + // GetTables Get the tables that belong to the database. + GetTables() ([]Table, error) + // HasTable Determine if the given table exists. + HasTable(table string) bool // Register migrations. Register([]Migration) // Sql Execute a sql directly. @@ -18,14 +22,17 @@ type Schema interface { type Migration interface { // Signature Get the migration signature. Signature() string - // Connection Get the connection for the migration. - Connection() string // Up Run the migrations. Up() // Down Reverse the migrations. Down() } +type Connection interface { + // Connection Get the connection for the migration. + Connection() string +} + type Command struct { Algorithm string Column ColumnDefinition @@ -40,3 +47,9 @@ type Command struct { References []string Value string } + +type Table struct { + Comment string + Name string + Size int +} diff --git a/database/migration/blueprint.go b/database/migration/blueprint.go index 026d776c9..20e48d64c 100644 --- a/database/migration/blueprint.go +++ b/database/migration/blueprint.go @@ -21,14 +21,13 @@ type Blueprint struct { columns []*ColumnDefinition commands []*migration.Command prefix string - schema string table string } -func NewBlueprint(prefix, schema string) *Blueprint { +func NewBlueprint(prefix, table string) *Blueprint { return &Blueprint{ prefix: prefix, - schema: schema, + table: table, } } diff --git a/database/migration/grammars/postgres.go b/database/migration/grammars/postgres.go index 38d187262..49727a12e 100644 --- a/database/migration/grammars/postgres.go +++ b/database/migration/grammars/postgres.go @@ -37,6 +37,13 @@ func (r *Postgres) CompileDropIfExists(blueprint migration.Blueprint) string { return fmt.Sprintf("drop table if exists %s", blueprint.GetTableName()) } +func (r *Postgres) CompileTables(database string) string { + return "select c.relname as name, n.nspname as schema, pg_total_relation_size(c.oid) as size, " + + "obj_description(c.oid, 'pg_class') as comment from pg_class c, pg_namespace n " + + "where c.relkind in ('r', 'p') and n.oid = c.relnamespace and n.nspname not in ('pg_catalog', 'information_schema') " + + "order by c.relname" +} + func (r *Postgres) GetAttributeCommands() []string { return r.attributeCommands } diff --git a/database/migration/repository.go b/database/migration/repository.go new file mode 100644 index 000000000..5ea99b1b6 --- /dev/null +++ b/database/migration/repository.go @@ -0,0 +1,108 @@ +package migration + +import ( + "github.com/goravel/framework/contracts/database/migration" + "github.com/goravel/framework/contracts/database/orm" +) + +type Repository struct { + query orm.Query + schema migration.Schema + table string +} + +func NewRepository(query orm.Query, schema migration.Schema, table string) *Repository { + return &Repository{ + query: query, + schema: schema, + table: table, + } +} + +func (r *Repository) CreateRepository() error { + return r.schema.Create(r.table, func(table migration.Blueprint) { + table.ID() + table.String("migration") + table.Integer("batch") + }) +} + +func (r *Repository) Delete(migration string) error { + _, err := r.query.Table(r.table).Where("migration", migration).Delete() + + return err +} + +func (r *Repository) DeleteRepository() error { + return r.schema.DropIfExists(r.table) +} + +func (r *Repository) GetLast() ([]migration.File, error) { + var files []migration.File + lastBatchNumber, err := r.getLastBatchNumber() + if err != nil { + return nil, err + } + + if err := r.query.Table(r.table).Where("batch", lastBatchNumber).OrderByDesc("migration").Get(&files); err != nil { + return nil, err + } + + return files, nil +} + +func (r *Repository) GetMigrations(steps int) ([]migration.File, error) { + var files []migration.File + if err := r.query.Table(r.table).Where("batch >= 1").OrderByDesc("batch").OrderByDesc("migration").Limit(steps).Get(&files); err != nil { + return nil, err + } + + return files, nil +} + +func (r *Repository) GetMigrationsByBatch(batch int) ([]migration.File, error) { + var files []migration.File + if err := r.query.Table(r.table).Where("batch", batch).OrderByDesc("migration").Get(&files); err != nil { + return nil, err + } + + return files, nil +} + +func (r *Repository) GetNextBatchNumber() (int, error) { + lastBatchNumber, err := r.getLastBatchNumber() + if err != nil { + return 0, err + } + + return lastBatchNumber + 1, nil +} + +func (r *Repository) GetRan() ([]string, error) { + var migrations []string + if err := r.query.Table(r.table).OrderBy("batch").OrderBy("migration").Pluck("migration", &migrations); err != nil { + return nil, err + } + + return migrations, nil +} + +func (r *Repository) Log(file string, batch int) error { + return r.query.Table(r.table).Create(map[string]any{ + "migration": file, + "batch": batch, + }) +} + +func (r *Repository) RepositoryExists() bool { + return r.schema.HasTable(r.table) +} + +func (r *Repository) getLastBatchNumber() (int, error) { + var batch int + if err := r.query.Table(r.table).OrderByDesc("batch").Limit(1).Pluck("batch", &batch); err != nil { + return 0, err + } + + return batch, nil +} diff --git a/database/migration/repository_test.go b/database/migration/repository_test.go new file mode 100644 index 000000000..3e346d958 --- /dev/null +++ b/database/migration/repository_test.go @@ -0,0 +1,135 @@ +package migration + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + "github.com/goravel/framework/contracts/database" + "github.com/goravel/framework/database/gorm" + mocksorm "github.com/goravel/framework/mocks/database/orm" + "github.com/goravel/framework/support/docker" + "github.com/goravel/framework/support/env" +) + +type RepositoryTestSuite struct { + suite.Suite + driverToTestQuery map[database.Driver]*gorm.TestQuery +} + +func TestRepositoryTestSuite(t *testing.T) { + if env.IsWindows() { + t.Skip("Skipping tests of using docker") + } + + suite.Run(t, &RepositoryTestSuite{}) +} + +func (s *RepositoryTestSuite) SetupTest() { + postgresDocker := docker.Postgres() + postgresQuery := gorm.NewTestQuery(postgresDocker, true) + s.driverToTestQuery = map[database.Driver]*gorm.TestQuery{ + database.DriverPostgres: postgresQuery, + } +} + +func (s *RepositoryTestSuite) TestCreate_Delete_Exists() { + for driver, testQuery := range s.driverToTestQuery { + s.Run(driver.String(), func() { + repository, mockOrm := s.initRepository(testQuery) + + mockOrm.EXPECT().Connection(driver.String()).Return(mockOrm).Once() + mockOrm.EXPECT().Query().Return(repository.query).Once() + + err := repository.CreateRepository() + s.NoError(err) + + mockOrm.EXPECT().Query().Return(repository.query).Once() + + s.True(repository.RepositoryExists()) + + mockOrm.EXPECT().Connection(driver.String()).Return(mockOrm).Once() + mockOrm.EXPECT().Query().Return(repository.query).Once() + + err = repository.DeleteRepository() + s.NoError(err) + + mockOrm.EXPECT().Query().Return(repository.query).Once() + + s.False(repository.RepositoryExists()) + }) + } +} + +func (s *RepositoryTestSuite) TestRecord() { + for driver, testQuery := range s.driverToTestQuery { + s.Run(driver.String(), func() { + repository, mockOrm := s.initRepository(testQuery) + + mockOrm.EXPECT().Query().Return(repository.query).Once() + + if !repository.RepositoryExists() { + mockOrm.EXPECT().Connection(driver.String()).Return(mockOrm).Once() + mockOrm.EXPECT().Query().Return(repository.query).Once() + + s.NoError(repository.CreateRepository()) + } + + err := repository.Log("migration1", 1) + s.NoError(err) + + err = repository.Log("migration2", 1) + s.NoError(err) + + err = repository.Log("migration3", 2) + s.NoError(err) + + lastBatchNumber, err := repository.getLastBatchNumber() + s.NoError(err) + s.Equal(2, lastBatchNumber) + + nextBatchNumber, err := repository.GetNextBatchNumber() + s.NoError(err) + s.Equal(3, nextBatchNumber) + + ranMigrations, err := repository.GetRan() + s.NoError(err) + s.ElementsMatch([]string{"migration1", "migration2", "migration3"}, ranMigrations) + + migrations, err := repository.GetMigrations(2) + s.NoError(err) + s.Len(migrations, 2) + s.Equal("migration3", migrations[0].Migration) + s.Equal(2, migrations[0].Batch) + s.Equal("migration2", migrations[1].Migration) + s.Equal(1, migrations[1].Batch) + + migrations, err = repository.GetMigrationsByBatch(1) + s.NoError(err) + s.Len(migrations, 2) + s.Equal("migration2", migrations[0].Migration) + s.Equal(1, migrations[0].Batch) + s.Equal("migration1", migrations[1].Migration) + s.Equal(1, migrations[1].Batch) + + migrations, err = repository.GetLast() + s.NoError(err) + s.Len(migrations, 1) + s.Equal("migration3", migrations[0].Migration) + s.Equal(2, migrations[0].Batch) + + err = repository.Delete("migration1") + s.NoError(err) + + ranMigrations, err = repository.GetRan() + s.NoError(err) + s.ElementsMatch([]string{"migration2", "migration3"}, ranMigrations) + }) + } +} + +func (s *RepositoryTestSuite) initRepository(testQuery *gorm.TestQuery) (*Repository, *mocksorm.Orm) { + schema, mockOrm := initSchema(s.T(), testQuery) + + return NewRepository(testQuery.Query(), schema, "migrations"), mockOrm +} diff --git a/database/migration/respository.go b/database/migration/respository.go deleted file mode 100644 index d53a23310..000000000 --- a/database/migration/respository.go +++ /dev/null @@ -1,75 +0,0 @@ -package migration - -import ( - "github.com/goravel/framework/contracts/database/migration" - "github.com/goravel/framework/contracts/database/orm" -) - -type Repository struct { - orm orm.Orm - schema migration.Schema - table string -} - -func NewRepository(orm orm.Orm, schema migration.Schema, table string) *Repository { - return &Repository{ - orm: orm, - schema: schema, - table: table, - } -} - -func (r *Repository) CreateRepository() { - //TODO implement me - panic("implement me") -} - -func (r *Repository) Delete(migration string) { - //TODO implement me - panic("implement me") -} - -func (r *Repository) DeleteRepository() { - //TODO implement me - panic("implement me") -} - -func (r *Repository) GetLast() { - //TODO implement me - panic("implement me") -} - -func (r *Repository) GetMigrationBatches() { - //TODO implement me - panic("implement me") -} - -func (r *Repository) GetMigrations(steps int) { - //TODO implement me - panic("implement me") -} - -func (r *Repository) GetMigrationsByBatch(batch int) { - //TODO implement me - panic("implement me") -} - -func (r *Repository) GetNextBatchNumber() { - //TODO implement me - panic("implement me") -} - -func (r *Repository) GetRan() { - //TODO implement me - panic("implement me") -} - -func (r *Repository) Log(file, batch string) { - //TODO implement me - panic("implement me") -} - -func (r *Repository) RepositoryExists() { - //TODO implement me - panic("implement me") -} diff --git a/database/migration/schema.go b/database/migration/schema.go index 51788660c..ca5e31f27 100644 --- a/database/migration/schema.go +++ b/database/migration/schema.go @@ -14,53 +14,77 @@ import ( var _ migration.Schema = (*Schema)(nil) type Schema struct { - blueprint migration.Blueprint config config.Config connection string grammar migration.Grammar log log.Log migrations []migration.Migration orm contractsorm.Orm + prefix string } -func NewSchema(blueprint migration.Blueprint, config config.Config, connection string, log log.Log, orm contractsorm.Orm) *Schema { +func NewSchema(config config.Config, connection string, log log.Log, orm contractsorm.Orm) *Schema { driver := config.GetString(fmt.Sprintf("database.connections.%s.driver", connection)) + prefix := config.GetString(fmt.Sprintf("database.connections.%s.prefix", connection)) grammar := getGrammar(driver) return &Schema{ - blueprint: blueprint, config: config, connection: connection, grammar: grammar, log: log, orm: orm, + prefix: prefix, } } func (r *Schema) Connection(name string) migration.Schema { - prefix := r.config.GetString(fmt.Sprintf("database.connections.%s.prefix", name)) - dbSchema := r.config.GetString(fmt.Sprintf("database.connections.%s.schema", name)) - blueprint := NewBlueprint(prefix, dbSchema) - schema := NewSchema(blueprint, r.config, name, r.log, r.orm) - - return schema + return NewSchema(r.config, name, r.log, r.orm) } -func (r *Schema) Create(table string, callback func(table migration.Blueprint)) { - r.blueprint.SetTable(table) - r.blueprint.Create() - callback(r.blueprint) +func (r *Schema) Create(table string, callback func(table migration.Blueprint)) error { + blueprint := r.createBlueprint(table) + blueprint.Create() + callback(blueprint) // TODO catch error and rollback - _ = r.blueprint.Build(r.orm.Connection(r.connection).Query(), r.grammar) + return r.build(blueprint) +} + +func (r *Schema) DropIfExists(table string) error { + blueprint := r.createBlueprint(table) + blueprint.DropIfExists() + + // TODO catch error when run migrate command + return r.build(blueprint) +} + +func (r *Schema) GetTables() ([]migration.Table, error) { + var tables []migration.Table + if err := r.orm.Query().Raw(r.grammar.CompileTables("")).Scan(&tables); err != nil { + return nil, err + } + + return tables, nil } -func (r *Schema) DropIfExists(table string) { - r.blueprint.SetTable(table) - r.blueprint.DropIfExists() +func (r *Schema) HasTable(name string) bool { + blueprint := r.createBlueprint(name) + tableName := blueprint.GetTableName() - // TODO catch error - _ = r.blueprint.Build(r.orm.Connection(r.connection).Query(), r.grammar) + tables, err := r.GetTables() + if err != nil { + r.log.Errorf("failed to get %s tables: %v", r.connection, err) + return false + } + + for _, table := range tables { + if table.Name == tableName { + return true + } + } + + return false } func (r *Schema) Register(migrations []migration.Migration) { @@ -72,6 +96,14 @@ func (r *Schema) Sql(sql string) { _, _ = r.orm.Connection(r.connection).Query().Exec(sql) } +func (r *Schema) build(blueprint migration.Blueprint) error { + return blueprint.Build(r.orm.Connection(r.connection).Query(), r.grammar) +} + +func (r *Schema) createBlueprint(table string) migration.Blueprint { + return NewBlueprint(r.prefix, table) +} + func getGrammar(driver string) migration.Grammar { switch driver { case contractsdatabase.DriverMysql.String(): diff --git a/database/migration/schema_test.go b/database/migration/schema_test.go index f6a920b0d..5abad5567 100644 --- a/database/migration/schema_test.go +++ b/database/migration/schema_test.go @@ -1,31 +1,21 @@ package migration import ( - "fmt" "testing" "github.com/stretchr/testify/suite" - contractsdatabase "github.com/goravel/framework/contracts/database" + "github.com/goravel/framework/contracts/database" "github.com/goravel/framework/contracts/database/migration" - contractsorm "github.com/goravel/framework/contracts/database/orm" - contractstesting "github.com/goravel/framework/contracts/testing" "github.com/goravel/framework/database/gorm" - mocksconfig "github.com/goravel/framework/mocks/config" mocksorm "github.com/goravel/framework/mocks/database/orm" - mockslog "github.com/goravel/framework/mocks/log" - supportdocker "github.com/goravel/framework/support/docker" + "github.com/goravel/framework/support/docker" "github.com/goravel/framework/support/env" ) -type TestDB struct { - config contractstesting.DatabaseConfig - query contractsorm.Query -} - type SchemaSuite struct { suite.Suite - driverToTestDB map[contractsdatabase.Driver]TestDB + driverToTestQuery map[database.Driver]*gorm.TestQuery } func TestSchemaSuite(t *testing.T) { @@ -36,66 +26,44 @@ func TestSchemaSuite(t *testing.T) { suite.Run(t, &SchemaSuite{}) } -func (s *SchemaSuite) SetupSuite() { - postgresDocker := supportdocker.Postgres() - postgresQuery := gorm.NewTestQuery(postgresDocker) - s.driverToTestDB = map[contractsdatabase.Driver]TestDB{ - contractsdatabase.DriverPostgres: { - config: postgresDocker.Config(), - query: postgresQuery.Query(), - }, - } -} - func (s *SchemaSuite) SetupTest() { - -} - -func (s *SchemaSuite) TestConnection() { - schema, mockConfig, _, _ := initTest(s.T(), contractsdatabase.DriverMysql) - connection := contractsdatabase.DriverPostgres.String() - mockConfig.EXPECT().GetString(fmt.Sprintf("database.connections.%s.prefix", connection)).Return("goravel_").Once() - mockConfig.EXPECT().GetString(fmt.Sprintf("database.connections.%s.schema", connection)).Return("").Once() - mockConfig.EXPECT().GetString(fmt.Sprintf("database.connections.%s.driver", connection)).Return(connection).Once() - - s.NotNil(schema.Connection(connection)) - - // TODO Test the new schema is valid when implementing HasTable + postgresDocker := docker.Postgres() + postgresQuery := gorm.NewTestQuery(postgresDocker, true) + s.driverToTestQuery = map[database.Driver]*gorm.TestQuery{ + database.DriverPostgres: postgresQuery, + } } func (s *SchemaSuite) TestDropIfExists() { - for driver, testDB := range s.driverToTestDB { + for driver, testQuery := range s.driverToTestQuery { s.Run(driver.String(), func() { - schema, _, _, mockOrm := initTest(s.T(), driver) + schema, mockOrm := initSchema(s.T(), testQuery) table := "drop_if_exists" mockOrm.EXPECT().Connection(schema.connection).Return(mockOrm).Twice() - mockOrm.EXPECT().Query().Return(testDB.query).Twice() + mockOrm.EXPECT().Query().Return(testQuery.Query()).Twice() + s.NoError(schema.DropIfExists(table)) + s.NoError(schema.Create(table, func(table migration.Blueprint) { + table.String("name") + })) - schema.DropIfExists(table) + mockOrm.EXPECT().Query().Return(testQuery.Query()).Once() + s.True(schema.HasTable(table)) - schema.Create(table, func(table migration.Blueprint) { - table.String("name") - }) + mockOrm.EXPECT().Connection(schema.connection).Return(mockOrm).Once() + mockOrm.EXPECT().Query().Return(testQuery.Query()).Once() + s.NoError(schema.DropIfExists(table)) - // TODO Open below when implementing HasTable - //s.True(schema.schema.HasTable(table)) - //s.schema.DropIfExists(table) - //s.False(schema.schema.HasTable(table)) + mockOrm.EXPECT().Query().Return(testQuery.Query()).Once() + s.False(schema.HasTable(table)) }) } } -func initTest(t *testing.T, driver contractsdatabase.Driver) (*Schema, *mocksconfig.Config, *mockslog.Log, *mocksorm.Orm) { - blueprint := NewBlueprint("goravel_", "") - mockConfig := mocksconfig.NewConfig(t) - mockConfig.EXPECT().GetString(fmt.Sprintf("database.connections.%s.driver", driver)). - Return(driver.String()).Once() - mockLog := mockslog.NewLog(t) +func initSchema(t *testing.T, testQuery *gorm.TestQuery) (*Schema, *mocksorm.Orm) { mockOrm := mocksorm.NewOrm(t) + schema := NewSchema(testQuery.MockConfig(), testQuery.Docker().Driver().String(), nil, mockOrm) - schema := NewSchema(blueprint, mockConfig, driver.String(), mockLog, mockOrm) - - return schema, mockConfig, mockLog, mockOrm + return schema, mockOrm } diff --git a/database/service_provider.go b/database/service_provider.go index 4711bcd95..d38e19eb2 100644 --- a/database/service_provider.go +++ b/database/service_provider.go @@ -36,11 +36,8 @@ func (r *ServiceProvider) Register(app foundation.Application) { log := app.MakeLog() connection := config.GetString("database.default") - prefix := config.GetString(fmt.Sprintf("database.connections.%s.prefix", connection)) - schema := config.GetString(fmt.Sprintf("database.connections.%s.schema", connection)) - blueprint := migration.NewBlueprint(prefix, schema) - return migration.NewSchema(blueprint, config, connection, log, orm), nil + return migration.NewSchema(config, connection, log, orm), nil }) app.Singleton(BindingSeeder, func(app foundation.Application) (any, error) { return NewSeederFacade(), nil diff --git a/mocks/database/migration/Connection.go b/mocks/database/migration/Connection.go new file mode 100644 index 000000000..b6fb96962 --- /dev/null +++ b/mocks/database/migration/Connection.go @@ -0,0 +1,77 @@ +// Code generated by mockery. DO NOT EDIT. + +package migration + +import mock "github.com/stretchr/testify/mock" + +// Connection is an autogenerated mock type for the Connection type +type Connection struct { + mock.Mock +} + +type Connection_Expecter struct { + mock *mock.Mock +} + +func (_m *Connection) EXPECT() *Connection_Expecter { + return &Connection_Expecter{mock: &_m.Mock} +} + +// Connection provides a mock function with given fields: +func (_m *Connection) Connection() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Connection") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Connection_Connection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Connection' +type Connection_Connection_Call struct { + *mock.Call +} + +// Connection is a helper method to define mock.On call +func (_e *Connection_Expecter) Connection() *Connection_Connection_Call { + return &Connection_Connection_Call{Call: _e.mock.On("Connection")} +} + +func (_c *Connection_Connection_Call) Run(run func()) *Connection_Connection_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Connection_Connection_Call) Return(_a0 string) *Connection_Connection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Connection_Connection_Call) RunAndReturn(run func() string) *Connection_Connection_Call { + _c.Call.Return(run) + return _c +} + +// NewConnection creates a new instance of Connection. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewConnection(t interface { + mock.TestingT + Cleanup(func()) +}) *Connection { + mock := &Connection{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/database/migration/Grammar.go b/mocks/database/migration/Grammar.go index 98eeb12ad..863b52e2b 100644 --- a/mocks/database/migration/Grammar.go +++ b/mocks/database/migration/Grammar.go @@ -115,6 +115,52 @@ func (_c *Grammar_CompileDropIfExists_Call) RunAndReturn(run func(migration.Blue return _c } +// CompileTables provides a mock function with given fields: database +func (_m *Grammar) CompileTables(database string) string { + ret := _m.Called(database) + + if len(ret) == 0 { + panic("no return value specified for CompileTables") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(database) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_CompileTables_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CompileTables' +type Grammar_CompileTables_Call struct { + *mock.Call +} + +// CompileTables is a helper method to define mock.On call +// - database string +func (_e *Grammar_Expecter) CompileTables(database interface{}) *Grammar_CompileTables_Call { + return &Grammar_CompileTables_Call{Call: _e.mock.On("CompileTables", database)} +} + +func (_c *Grammar_CompileTables_Call) Run(run func(database string)) *Grammar_CompileTables_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Grammar_CompileTables_Call) Return(_a0 string) *Grammar_CompileTables_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_CompileTables_Call) RunAndReturn(run func(string) string) *Grammar_CompileTables_Call { + _c.Call.Return(run) + return _c +} + // GetAttributeCommands provides a mock function with given fields: func (_m *Grammar) GetAttributeCommands() []string { ret := _m.Called() diff --git a/mocks/database/migration/Migration.go b/mocks/database/migration/Migration.go index 3556d85e3..a8dd5932d 100644 --- a/mocks/database/migration/Migration.go +++ b/mocks/database/migration/Migration.go @@ -17,51 +17,6 @@ func (_m *Migration) EXPECT() *Migration_Expecter { return &Migration_Expecter{mock: &_m.Mock} } -// Connection provides a mock function with given fields: -func (_m *Migration) Connection() string { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Connection") - } - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// Migration_Connection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Connection' -type Migration_Connection_Call struct { - *mock.Call -} - -// Connection is a helper method to define mock.On call -func (_e *Migration_Expecter) Connection() *Migration_Connection_Call { - return &Migration_Connection_Call{Call: _e.mock.On("Connection")} -} - -func (_c *Migration_Connection_Call) Run(run func()) *Migration_Connection_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *Migration_Connection_Call) Return(_a0 string) *Migration_Connection_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Migration_Connection_Call) RunAndReturn(run func() string) *Migration_Connection_Call { - _c.Call.Return(run) - return _c -} - // Down provides a mock function with given fields: func (_m *Migration) Down() { _m.Called() diff --git a/mocks/database/migration/Repository.go b/mocks/database/migration/Repository.go index abc9e6336..7c3e518be 100644 --- a/mocks/database/migration/Repository.go +++ b/mocks/database/migration/Repository.go @@ -2,7 +2,10 @@ package migration -import mock "github.com/stretchr/testify/mock" +import ( + migration "github.com/goravel/framework/contracts/database/migration" + mock "github.com/stretchr/testify/mock" +) // Repository is an autogenerated mock type for the Repository type type Repository struct { @@ -17,6 +20,519 @@ func (_m *Repository) EXPECT() *Repository_Expecter { return &Repository_Expecter{mock: &_m.Mock} } +// CreateRepository provides a mock function with given fields: +func (_m *Repository) CreateRepository() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for CreateRepository") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Repository_CreateRepository_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRepository' +type Repository_CreateRepository_Call struct { + *mock.Call +} + +// CreateRepository is a helper method to define mock.On call +func (_e *Repository_Expecter) CreateRepository() *Repository_CreateRepository_Call { + return &Repository_CreateRepository_Call{Call: _e.mock.On("CreateRepository")} +} + +func (_c *Repository_CreateRepository_Call) Run(run func()) *Repository_CreateRepository_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Repository_CreateRepository_Call) Return(_a0 error) *Repository_CreateRepository_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Repository_CreateRepository_Call) RunAndReturn(run func() error) *Repository_CreateRepository_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: _a0 +func (_m *Repository) Delete(_a0 string) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Repository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type Repository_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - _a0 string +func (_e *Repository_Expecter) Delete(_a0 interface{}) *Repository_Delete_Call { + return &Repository_Delete_Call{Call: _e.mock.On("Delete", _a0)} +} + +func (_c *Repository_Delete_Call) Run(run func(_a0 string)) *Repository_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Repository_Delete_Call) Return(_a0 error) *Repository_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Repository_Delete_Call) RunAndReturn(run func(string) error) *Repository_Delete_Call { + _c.Call.Return(run) + return _c +} + +// DeleteRepository provides a mock function with given fields: +func (_m *Repository) DeleteRepository() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for DeleteRepository") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Repository_DeleteRepository_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteRepository' +type Repository_DeleteRepository_Call struct { + *mock.Call +} + +// DeleteRepository is a helper method to define mock.On call +func (_e *Repository_Expecter) DeleteRepository() *Repository_DeleteRepository_Call { + return &Repository_DeleteRepository_Call{Call: _e.mock.On("DeleteRepository")} +} + +func (_c *Repository_DeleteRepository_Call) Run(run func()) *Repository_DeleteRepository_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Repository_DeleteRepository_Call) Return(_a0 error) *Repository_DeleteRepository_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Repository_DeleteRepository_Call) RunAndReturn(run func() error) *Repository_DeleteRepository_Call { + _c.Call.Return(run) + return _c +} + +// GetLast provides a mock function with given fields: +func (_m *Repository) GetLast() ([]migration.File, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetLast") + } + + var r0 []migration.File + var r1 error + if rf, ok := ret.Get(0).(func() ([]migration.File, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []migration.File); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]migration.File) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Repository_GetLast_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLast' +type Repository_GetLast_Call struct { + *mock.Call +} + +// GetLast is a helper method to define mock.On call +func (_e *Repository_Expecter) GetLast() *Repository_GetLast_Call { + return &Repository_GetLast_Call{Call: _e.mock.On("GetLast")} +} + +func (_c *Repository_GetLast_Call) Run(run func()) *Repository_GetLast_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Repository_GetLast_Call) Return(_a0 []migration.File, _a1 error) *Repository_GetLast_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Repository_GetLast_Call) RunAndReturn(run func() ([]migration.File, error)) *Repository_GetLast_Call { + _c.Call.Return(run) + return _c +} + +// GetMigrations provides a mock function with given fields: steps +func (_m *Repository) GetMigrations(steps int) ([]migration.File, error) { + ret := _m.Called(steps) + + if len(ret) == 0 { + panic("no return value specified for GetMigrations") + } + + var r0 []migration.File + var r1 error + if rf, ok := ret.Get(0).(func(int) ([]migration.File, error)); ok { + return rf(steps) + } + if rf, ok := ret.Get(0).(func(int) []migration.File); ok { + r0 = rf(steps) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]migration.File) + } + } + + if rf, ok := ret.Get(1).(func(int) error); ok { + r1 = rf(steps) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Repository_GetMigrations_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMigrations' +type Repository_GetMigrations_Call struct { + *mock.Call +} + +// GetMigrations is a helper method to define mock.On call +// - steps int +func (_e *Repository_Expecter) GetMigrations(steps interface{}) *Repository_GetMigrations_Call { + return &Repository_GetMigrations_Call{Call: _e.mock.On("GetMigrations", steps)} +} + +func (_c *Repository_GetMigrations_Call) Run(run func(steps int)) *Repository_GetMigrations_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Repository_GetMigrations_Call) Return(_a0 []migration.File, _a1 error) *Repository_GetMigrations_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Repository_GetMigrations_Call) RunAndReturn(run func(int) ([]migration.File, error)) *Repository_GetMigrations_Call { + _c.Call.Return(run) + return _c +} + +// GetMigrationsByBatch provides a mock function with given fields: batch +func (_m *Repository) GetMigrationsByBatch(batch int) ([]migration.File, error) { + ret := _m.Called(batch) + + if len(ret) == 0 { + panic("no return value specified for GetMigrationsByBatch") + } + + var r0 []migration.File + var r1 error + if rf, ok := ret.Get(0).(func(int) ([]migration.File, error)); ok { + return rf(batch) + } + if rf, ok := ret.Get(0).(func(int) []migration.File); ok { + r0 = rf(batch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]migration.File) + } + } + + if rf, ok := ret.Get(1).(func(int) error); ok { + r1 = rf(batch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Repository_GetMigrationsByBatch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMigrationsByBatch' +type Repository_GetMigrationsByBatch_Call struct { + *mock.Call +} + +// GetMigrationsByBatch is a helper method to define mock.On call +// - batch int +func (_e *Repository_Expecter) GetMigrationsByBatch(batch interface{}) *Repository_GetMigrationsByBatch_Call { + return &Repository_GetMigrationsByBatch_Call{Call: _e.mock.On("GetMigrationsByBatch", batch)} +} + +func (_c *Repository_GetMigrationsByBatch_Call) Run(run func(batch int)) *Repository_GetMigrationsByBatch_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Repository_GetMigrationsByBatch_Call) Return(_a0 []migration.File, _a1 error) *Repository_GetMigrationsByBatch_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Repository_GetMigrationsByBatch_Call) RunAndReturn(run func(int) ([]migration.File, error)) *Repository_GetMigrationsByBatch_Call { + _c.Call.Return(run) + return _c +} + +// GetNextBatchNumber provides a mock function with given fields: +func (_m *Repository) GetNextBatchNumber() (int, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetNextBatchNumber") + } + + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func() (int, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() int); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Repository_GetNextBatchNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNextBatchNumber' +type Repository_GetNextBatchNumber_Call struct { + *mock.Call +} + +// GetNextBatchNumber is a helper method to define mock.On call +func (_e *Repository_Expecter) GetNextBatchNumber() *Repository_GetNextBatchNumber_Call { + return &Repository_GetNextBatchNumber_Call{Call: _e.mock.On("GetNextBatchNumber")} +} + +func (_c *Repository_GetNextBatchNumber_Call) Run(run func()) *Repository_GetNextBatchNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Repository_GetNextBatchNumber_Call) Return(_a0 int, _a1 error) *Repository_GetNextBatchNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Repository_GetNextBatchNumber_Call) RunAndReturn(run func() (int, error)) *Repository_GetNextBatchNumber_Call { + _c.Call.Return(run) + return _c +} + +// GetRan provides a mock function with given fields: +func (_m *Repository) GetRan() ([]string, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetRan") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func() ([]string, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Repository_GetRan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRan' +type Repository_GetRan_Call struct { + *mock.Call +} + +// GetRan is a helper method to define mock.On call +func (_e *Repository_Expecter) GetRan() *Repository_GetRan_Call { + return &Repository_GetRan_Call{Call: _e.mock.On("GetRan")} +} + +func (_c *Repository_GetRan_Call) Run(run func()) *Repository_GetRan_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Repository_GetRan_Call) Return(_a0 []string, _a1 error) *Repository_GetRan_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Repository_GetRan_Call) RunAndReturn(run func() ([]string, error)) *Repository_GetRan_Call { + _c.Call.Return(run) + return _c +} + +// Log provides a mock function with given fields: file, batch +func (_m *Repository) Log(file string, batch int) error { + ret := _m.Called(file, batch) + + if len(ret) == 0 { + panic("no return value specified for Log") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string, int) error); ok { + r0 = rf(file, batch) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Repository_Log_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Log' +type Repository_Log_Call struct { + *mock.Call +} + +// Log is a helper method to define mock.On call +// - file string +// - batch int +func (_e *Repository_Expecter) Log(file interface{}, batch interface{}) *Repository_Log_Call { + return &Repository_Log_Call{Call: _e.mock.On("Log", file, batch)} +} + +func (_c *Repository_Log_Call) Run(run func(file string, batch int)) *Repository_Log_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(int)) + }) + return _c +} + +func (_c *Repository_Log_Call) Return(_a0 error) *Repository_Log_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Repository_Log_Call) RunAndReturn(run func(string, int) error) *Repository_Log_Call { + _c.Call.Return(run) + return _c +} + +// RepositoryExists provides a mock function with given fields: +func (_m *Repository) RepositoryExists() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RepositoryExists") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// Repository_RepositoryExists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RepositoryExists' +type Repository_RepositoryExists_Call struct { + *mock.Call +} + +// RepositoryExists is a helper method to define mock.On call +func (_e *Repository_Expecter) RepositoryExists() *Repository_RepositoryExists_Call { + return &Repository_RepositoryExists_Call{Call: _e.mock.On("RepositoryExists")} +} + +func (_c *Repository_RepositoryExists_Call) Run(run func()) *Repository_RepositoryExists_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Repository_RepositoryExists_Call) Return(_a0 bool) *Repository_RepositoryExists_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Repository_RepositoryExists_Call) RunAndReturn(run func() bool) *Repository_RepositoryExists_Call { + _c.Call.Return(run) + return _c +} + // NewRepository creates a new instance of Repository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewRepository(t interface { diff --git a/mocks/database/migration/Schema.go b/mocks/database/migration/Schema.go index fcd5cb341..ff60a070f 100644 --- a/mocks/database/migration/Schema.go +++ b/mocks/database/migration/Schema.go @@ -69,8 +69,21 @@ func (_c *Schema_Connection_Call) RunAndReturn(run func(string) migration.Schema } // Create provides a mock function with given fields: table, callback -func (_m *Schema) Create(table string, callback func(migration.Blueprint)) { - _m.Called(table, callback) +func (_m *Schema) Create(table string, callback func(migration.Blueprint)) error { + ret := _m.Called(table, callback) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string, func(migration.Blueprint)) error); ok { + r0 = rf(table, callback) + } else { + r0 = ret.Error(0) + } + + return r0 } // Schema_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' @@ -92,19 +105,32 @@ func (_c *Schema_Create_Call) Run(run func(table string, callback func(migration return _c } -func (_c *Schema_Create_Call) Return() *Schema_Create_Call { - _c.Call.Return() +func (_c *Schema_Create_Call) Return(_a0 error) *Schema_Create_Call { + _c.Call.Return(_a0) return _c } -func (_c *Schema_Create_Call) RunAndReturn(run func(string, func(migration.Blueprint))) *Schema_Create_Call { +func (_c *Schema_Create_Call) RunAndReturn(run func(string, func(migration.Blueprint)) error) *Schema_Create_Call { _c.Call.Return(run) return _c } // DropIfExists provides a mock function with given fields: table -func (_m *Schema) DropIfExists(table string) { - _m.Called(table) +func (_m *Schema) DropIfExists(table string) error { + ret := _m.Called(table) + + if len(ret) == 0 { + panic("no return value specified for DropIfExists") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(table) + } else { + r0 = ret.Error(0) + } + + return r0 } // Schema_DropIfExists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DropIfExists' @@ -125,12 +151,115 @@ func (_c *Schema_DropIfExists_Call) Run(run func(table string)) *Schema_DropIfEx return _c } -func (_c *Schema_DropIfExists_Call) Return() *Schema_DropIfExists_Call { - _c.Call.Return() +func (_c *Schema_DropIfExists_Call) Return(_a0 error) *Schema_DropIfExists_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Schema_DropIfExists_Call) RunAndReturn(run func(string) error) *Schema_DropIfExists_Call { + _c.Call.Return(run) + return _c +} + +// GetTables provides a mock function with given fields: +func (_m *Schema) GetTables() ([]migration.Table, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetTables") + } + + var r0 []migration.Table + var r1 error + if rf, ok := ret.Get(0).(func() ([]migration.Table, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []migration.Table); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]migration.Table) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Schema_GetTables_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTables' +type Schema_GetTables_Call struct { + *mock.Call +} + +// GetTables is a helper method to define mock.On call +func (_e *Schema_Expecter) GetTables() *Schema_GetTables_Call { + return &Schema_GetTables_Call{Call: _e.mock.On("GetTables")} +} + +func (_c *Schema_GetTables_Call) Run(run func()) *Schema_GetTables_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Schema_GetTables_Call) Return(_a0 []migration.Table, _a1 error) *Schema_GetTables_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Schema_GetTables_Call) RunAndReturn(run func() ([]migration.Table, error)) *Schema_GetTables_Call { + _c.Call.Return(run) + return _c +} + +// HasTable provides a mock function with given fields: table +func (_m *Schema) HasTable(table string) bool { + ret := _m.Called(table) + + if len(ret) == 0 { + panic("no return value specified for HasTable") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(table) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// Schema_HasTable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HasTable' +type Schema_HasTable_Call struct { + *mock.Call +} + +// HasTable is a helper method to define mock.On call +// - table string +func (_e *Schema_Expecter) HasTable(table interface{}) *Schema_HasTable_Call { + return &Schema_HasTable_Call{Call: _e.mock.On("HasTable", table)} +} + +func (_c *Schema_HasTable_Call) Run(run func(table string)) *Schema_HasTable_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Schema_HasTable_Call) Return(_a0 bool) *Schema_HasTable_Call { + _c.Call.Return(_a0) return _c } -func (_c *Schema_DropIfExists_Call) RunAndReturn(run func(string)) *Schema_DropIfExists_Call { +func (_c *Schema_HasTable_Call) RunAndReturn(run func(string) bool) *Schema_HasTable_Call { _c.Call.Return(run) return _c }