diff --git a/contracts/database/migration/blueprint.go b/contracts/database/migration/blueprint.go index e744862cc..2ea7f5deb 100644 --- a/contracts/database/migration/blueprint.go +++ b/contracts/database/migration/blueprint.go @@ -13,6 +13,8 @@ type Blueprint interface { DropIfExists() // GetAddedColumns Get the added columns. GetAddedColumns() []ColumnDefinition + // GetChangedColumns Get the changed columns. + GetChangedColumns() []ColumnDefinition // GetTableName Get the table name with prefix. GetTableName() string // HasCommand Determine if the blueprint has a specific command. diff --git a/contracts/database/migration/column.go b/contracts/database/migration/column.go index 106266481..19df8c726 100644 --- a/contracts/database/migration/column.go +++ b/contracts/database/migration/column.go @@ -3,6 +3,8 @@ package migration type ColumnDefinition interface { // AutoIncrement set the column as auto increment AutoIncrement() ColumnDefinition + // Change the column + Change() // GetAutoIncrement returns the autoIncrement value GetAutoIncrement() bool // GetChange returns the change value @@ -17,6 +19,8 @@ type ColumnDefinition interface { GetNullable() bool // GetType returns the type value GetType() string + // Nullable allow NULL values to be inserted into the column + Nullable() ColumnDefinition // Unsigned set the column as unsigned Unsigned() ColumnDefinition } diff --git a/contracts/database/migration/grammar.go b/contracts/database/migration/grammar.go index a04f322fa..b625a8988 100644 --- a/contracts/database/migration/grammar.go +++ b/contracts/database/migration/grammar.go @@ -5,6 +5,10 @@ import ( ) type Grammar interface { + // CompileAdd Compile an add column command. + CompileAdd(blueprint Blueprint) string + // CompileChange Compile a change column command into a series of SQL statements. + CompileChange(blueprint Blueprint) string // CompileCreate Compile a create table command. CompileCreate(blueprint Blueprint, query orm.Query) string // CompileDropIfExists Compile a drop table (if exists) command. diff --git a/contracts/database/migration/schema.go b/contracts/database/migration/schema.go index ba864ab37..bd606b3c6 100644 --- a/contracts/database/migration/schema.go +++ b/contracts/database/migration/schema.go @@ -16,7 +16,7 @@ type Schema interface { // Sql Execute a sql directly. Sql(sql string) // Table Modify a table on the schema. - //Table(table string, callback func(table Blueprint)) + Table(table string, callback func(table Blueprint)) error } type Migration interface { diff --git a/database/migration/blueprint.go b/database/migration/blueprint.go index 20e48d64c..f7293893c 100644 --- a/database/migration/blueprint.go +++ b/database/migration/blueprint.go @@ -1,8 +1,6 @@ package migration import ( - "fmt" - "github.com/goravel/framework/contracts/database/migration" ormcontract "github.com/goravel/framework/contracts/database/orm" "github.com/goravel/framework/support/convert" @@ -48,8 +46,6 @@ func (r *Blueprint) BigInteger(column string) migration.ColumnDefinition { func (r *Blueprint) Build(query ormcontract.Query, grammar migration.Grammar) error { for _, sql := range r.ToSql(query, grammar) { - // TODO remove - fmt.Println("sql:", sql) if _, err := query.Exec(sql); err != nil { return err } @@ -152,6 +148,10 @@ func (r *Blueprint) ToSql(query ormcontract.Query, grammar migration.Grammar) [] var statements []string for _, command := range r.commands { switch command.Name { + case commandAdd: + statements = append(statements, grammar.CompileAdd(r)) + case commandChange: + statements = append(statements, grammar.CompileChange(r)) case commandCreate: statements = append(statements, grammar.CompileCreate(r, query)) case commandDropIfExists: diff --git a/database/migration/column.go b/database/migration/column.go index 395534e5d..3fb9fa2ed 100644 --- a/database/migration/column.go +++ b/database/migration/column.go @@ -23,6 +23,10 @@ func (r *ColumnDefinition) AutoIncrement() migration.ColumnDefinition { return r } +func (r *ColumnDefinition) Change() { + r.change = convert.Pointer(true) +} + func (r *ColumnDefinition) GetAutoIncrement() (autoIncrement bool) { if r.autoIncrement != nil { return *r.autoIncrement @@ -75,6 +79,12 @@ func (r *ColumnDefinition) GetType() (ttype string) { return } +func (r *ColumnDefinition) Nullable() migration.ColumnDefinition { + r.nullable = convert.Pointer(true) + + return r +} + func (r *ColumnDefinition) Unsigned() migration.ColumnDefinition { r.unsigned = convert.Pointer(true) diff --git a/database/migration/grammars/postgres.go b/database/migration/grammars/postgres.go index 49727a12e..37c26fc52 100644 --- a/database/migration/grammars/postgres.go +++ b/database/migration/grammars/postgres.go @@ -29,6 +29,31 @@ func NewPostgres() *Postgres { return postgres } +func (r *Postgres) CompileAdd(blueprint migration.Blueprint) string { + return fmt.Sprintf("alter table %s %s", blueprint.GetTableName(), strings.Join(prefixArray("add column", getColumns(r, blueprint)), ",")) +} + +func (r *Postgres) CompileChange(blueprint migration.Blueprint) string { + var columns []string + for _, column := range blueprint.GetChangedColumns() { + var changes []string + + for _, modifier := range r.modifiers { + if change := modifier(blueprint, column); change != "" { + changes = append(changes, change) + } + } + + columns = append(columns, strings.Join(prefixArray("alter column "+column.GetName(), changes), ", ")) + } + + if len(columns) == 0 { + return "" + } + + return fmt.Sprintf("alter table %s %s", blueprint.GetTableName(), strings.Join(columns, ", ")) +} + func (r *Postgres) CompileCreate(blueprint migration.Blueprint, query orm.Query) string { return fmt.Sprintf("create table %s (%s)", blueprint.GetTableName(), strings.Join(getColumns(r, blueprint), ",")) } diff --git a/database/migration/grammars/postgres_test.go b/database/migration/grammars/postgres_test.go index 08e4227f9..834a35ad7 100644 --- a/database/migration/grammars/postgres_test.go +++ b/database/migration/grammars/postgres_test.go @@ -19,39 +19,122 @@ func TestPostgresSuite(t *testing.T) { } func (s *PostgresSuite) SetupTest() { - postgres := &Postgres{ - attributeCommands: []string{"comment"}, - serials: []string{"bigInteger"}, - } - postgres.modifiers = []func(contractsmigration.Blueprint, contractsmigration.ColumnDefinition) string{ - postgres.ModifyDefault, + s.grammar = NewPostgres() +} + +func (s *PostgresSuite) TestCompileChange() { + var ( + mockBlueprint *mocksmigration.Blueprint + mockColumn1 *mocksmigration.ColumnDefinition + mockColumn2 *mocksmigration.ColumnDefinition + ) + + tests := []struct { + name string + setup func() + expectSql string + }{ + { + name: "no changes", + setup: func() { + mockBlueprint.EXPECT().GetChangedColumns().Return([]contractsmigration.ColumnDefinition{}).Once() + }, + }, + { + name: "single change", + setup: func() { + mockColumn1.EXPECT().GetAutoIncrement().Return(false).Once() + mockColumn1.EXPECT().GetDefault().Return("goravel").Twice() + mockColumn1.EXPECT().GetName().Return("name").Once() + mockColumn1.EXPECT().GetChange().Return(true).Times(3) + mockColumn1.EXPECT().GetNullable().Return(true).Once() + mockBlueprint.EXPECT().GetTableName().Return("users").Once() + mockBlueprint.EXPECT().GetChangedColumns().Return([]contractsmigration.ColumnDefinition{mockColumn1}).Once() + }, + expectSql: "alter table users alter column name set default 'goravel', alter column name drop not null", + }, + { + name: "multiple changes", + setup: func() { + mockColumn1.EXPECT().GetAutoIncrement().Return(false).Once() + mockColumn1.EXPECT().GetDefault().Return("goravel").Twice() + mockColumn1.EXPECT().GetName().Return("name").Once() + mockColumn1.EXPECT().GetChange().Return(true).Times(3) + mockColumn1.EXPECT().GetNullable().Return(true).Once() + mockColumn2.EXPECT().GetAutoIncrement().Return(false).Once() + mockColumn2.EXPECT().GetDefault().Return(1).Twice() + mockColumn2.EXPECT().GetName().Return("age").Once() + mockColumn2.EXPECT().GetChange().Return(true).Times(3) + mockColumn2.EXPECT().GetNullable().Return(false).Once() + mockBlueprint.EXPECT().GetTableName().Return("users").Once() + mockBlueprint.EXPECT().GetChangedColumns().Return([]contractsmigration.ColumnDefinition{mockColumn1, mockColumn2}).Once() + }, + expectSql: "alter table users alter column name set default 'goravel', alter column name drop not null, alter column age set default '1', alter column age set not null", + }, } - s.grammar = postgres + for _, test := range tests { + s.Run(test.name, func() { + mockBlueprint = mocksmigration.NewBlueprint(s.T()) + mockColumn1 = mocksmigration.NewColumnDefinition(s.T()) + mockColumn2 = mocksmigration.NewColumnDefinition(s.T()) + + test.setup() + + sql := s.grammar.CompileChange(mockBlueprint) + + s.Equal(test.expectSql, sql) + }) + } } func (s *PostgresSuite) TestCompileCreate() { mockColumn1 := mocksmigration.NewColumnDefinition(s.T()) + mockColumn2 := mocksmigration.NewColumnDefinition(s.T()) + mockBlueprint := mocksmigration.NewBlueprint(s.T()) + + // postgres.go::CompileCreate + mockBlueprint.EXPECT().GetTableName().Return("users").Once() + // utils.go::getColumns + mockBlueprint.EXPECT().GetAddedColumns().Return([]contractsmigration.ColumnDefinition{ + mockColumn1, mockColumn2, + }).Once() + // utils.go::getColumns mockColumn1.EXPECT().GetName().Return("id").Once() + // utils.go::getType mockColumn1.EXPECT().GetType().Return("integer").Once() + // postgres.go::TypeInteger mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() + // postgres.go::ModifyDefault mockColumn1.EXPECT().GetChange().Return(false).Once() mockColumn1.EXPECT().GetDefault().Return(nil).Once() + // postgres.go::ModifyIncrement + mockColumn1.EXPECT().GetChange().Return(false).Once() + mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once() + mockColumn1.EXPECT().GetType().Return("integer").Once() + mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() + // postgres.go::ModifyNullable + mockColumn1.EXPECT().GetChange().Return(false).Once() + mockColumn1.EXPECT().GetNullable().Return(false).Once() - mockColumn2 := mocksmigration.NewColumnDefinition(s.T()) + // utils.go::getColumns mockColumn2.EXPECT().GetName().Return("name").Once() + // utils.go::getType mockColumn2.EXPECT().GetType().Return("string").Once() + // postgres.go::TypeString mockColumn2.EXPECT().GetLength().Return(100).Once() + // postgres.go::ModifyDefault mockColumn2.EXPECT().GetChange().Return(false).Once() mockColumn2.EXPECT().GetDefault().Return(nil).Once() + // postgres.go::ModifyIncrement + mockColumn2.EXPECT().GetChange().Return(false).Once() + mockBlueprint.EXPECT().HasCommand("primary").Return(false).Once() + mockColumn2.EXPECT().GetType().Return("string").Once() + // postgres.go::ModifyNullable + mockColumn2.EXPECT().GetChange().Return(false).Once() + mockColumn2.EXPECT().GetNullable().Return(true).Once() - mockBlueprint := mocksmigration.NewBlueprint(s.T()) - mockBlueprint.EXPECT().GetTableName().Return("users").Once() - mockBlueprint.EXPECT().GetAddedColumns().Return([]contractsmigration.ColumnDefinition{ - mockColumn1, mockColumn2, - }).Once() - - s.Equal("create table users (id serial,name varchar(100))", + s.Equal("create table users (id serial primary key not null,name varchar(100) null)", s.grammar.CompileCreate(mockBlueprint, nil)) } diff --git a/database/migration/grammars/utils.go b/database/migration/grammars/utils.go index 41e54112f..3d02a47df 100644 --- a/database/migration/grammars/utils.go +++ b/database/migration/grammars/utils.go @@ -56,3 +56,11 @@ func getType(grammar migration.Grammar, column migration.ColumnDefinition) strin return "" } + +func prefixArray(prefix string, values []string) []string { + for i, value := range values { + values[i] = prefix + " " + value + } + + return values +} diff --git a/database/migration/grammars/utils_test.go b/database/migration/grammars/utils_test.go index 7f5b39283..b02928791 100644 --- a/database/migration/grammars/utils_test.go +++ b/database/migration/grammars/utils_test.go @@ -63,3 +63,8 @@ func TestGetType(t *testing.T) { assert.Empty(t, getType(mockGrammar1, mockColumn1)) } + +func TestPrefixArray(t *testing.T) { + values := []string{"a", "b", "c"} + assert.Equal(t, []string{"prefix a", "prefix b", "prefix c"}, prefixArray("prefix", values)) +} diff --git a/database/migration/schema.go b/database/migration/schema.go index ca5e31f27..8c3b6bab9 100644 --- a/database/migration/schema.go +++ b/database/migration/schema.go @@ -96,6 +96,14 @@ func (r *Schema) Sql(sql string) { _, _ = r.orm.Connection(r.connection).Query().Exec(sql) } +func (r *Schema) Table(table string, callback func(table migration.Blueprint)) error { + blueprint := r.createBlueprint(table) + callback(blueprint) + + // TODO catch error and rollback + return r.build(blueprint) +} + func (r *Schema) build(blueprint migration.Blueprint) error { return blueprint.Build(r.orm.Connection(r.connection).Query(), r.grammar) } diff --git a/database/migration/schema_test.go b/database/migration/schema_test.go index 5abad5567..c1b44cc3c 100644 --- a/database/migration/schema_test.go +++ b/database/migration/schema_test.go @@ -61,6 +61,73 @@ func (s *SchemaSuite) TestDropIfExists() { } } +func (s *SchemaSuite) TestTable() { + for driver, testQuery := range s.driverToTestQuery { + s.Run(driver.String(), func() { + schema, mockOrm := initSchema(s.T(), testQuery) + + mockOrm.EXPECT().Connection(schema.connection).Return(mockOrm).Once() + mockOrm.EXPECT().Query().Return(testQuery.Query()).Times(3) + + err := schema.Create("changes", func(table migration.Blueprint) { + table.String("name") + }) + s.NoError(err) + s.True(schema.HasTable("changes")) + + tables, err := schema.GetTables() + s.NoError(err) + s.Greater(len(tables), 0) + + // Open this after implementing other methods + //s.Require().True(schema.HasColumn("changes", "name")) + //columns, err := schema.GetColumns("changes") + //s.Require().Nil(err) + //for _, column := range columns { + // if column.Name == "name" { + // s.False(column.AutoIncrement) + // s.Empty(column.Collation) + // s.Empty(column.Comment) + // s.Empty(column.Default) + // s.False(column.Nullable) + // s.Equal("character varying(255)", column.Type) + // s.Equal("varchar", column.TypeName) + // } + //} + // + //err = schema.Table("changes", func(table migration.Blueprint) { + // table.Integer("age") + // table.String("name").Comment("This is a name column").Default("goravel").Change() + //}) + //s.Nil(err) + //s.True(schema.HasTable("changes")) + //s.Require().True(schema.HasColumns("changes", []string{"name", "age"})) + //columns, err = schema.GetColumns("changes") + //s.Require().Nil(err) + //for _, column := range columns { + // if column.Name == "name" { + // s.False(column.AutoIncrement) + // s.Empty(column.Collation) + // s.Equal("This is a name column", column.Comment) + // s.Equal("'goravel'::character varying", column.Default) + // s.False(column.Nullable) + // s.Equal("character varying(255)", column.Type) + // s.Equal("varchar", column.TypeName) + // } + // if column.Name == "age" { + // s.False(column.AutoIncrement) + // s.Empty(column.Collation) + // s.Empty(column.Comment) + // s.Empty(column.Default) + // s.False(column.Nullable) + // s.Equal("integer", column.Type) + // s.Equal("int4", column.TypeName) + // } + //} + }) + } +} + 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) diff --git a/mocks/database/migration/Blueprint.go b/mocks/database/migration/Blueprint.go index 090ce20a1..e1a0ca9ec 100644 --- a/mocks/database/migration/Blueprint.go +++ b/mocks/database/migration/Blueprint.go @@ -180,6 +180,53 @@ func (_c *Blueprint_GetAddedColumns_Call) RunAndReturn(run func() []migration.Co return _c } +// GetChangedColumns provides a mock function with given fields: +func (_m *Blueprint) GetChangedColumns() []migration.ColumnDefinition { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetChangedColumns") + } + + var r0 []migration.ColumnDefinition + if rf, ok := ret.Get(0).(func() []migration.ColumnDefinition); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]migration.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_GetChangedColumns_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetChangedColumns' +type Blueprint_GetChangedColumns_Call struct { + *mock.Call +} + +// GetChangedColumns is a helper method to define mock.On call +func (_e *Blueprint_Expecter) GetChangedColumns() *Blueprint_GetChangedColumns_Call { + return &Blueprint_GetChangedColumns_Call{Call: _e.mock.On("GetChangedColumns")} +} + +func (_c *Blueprint_GetChangedColumns_Call) Run(run func()) *Blueprint_GetChangedColumns_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Blueprint_GetChangedColumns_Call) Return(_a0 []migration.ColumnDefinition) *Blueprint_GetChangedColumns_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_GetChangedColumns_Call) RunAndReturn(run func() []migration.ColumnDefinition) *Blueprint_GetChangedColumns_Call { + _c.Call.Return(run) + return _c +} + // GetTableName provides a mock function with given fields: func (_m *Blueprint) GetTableName() string { ret := _m.Called() diff --git a/mocks/database/migration/ColumnDefinition.go b/mocks/database/migration/ColumnDefinition.go index 75ae2ab27..ea3a070f1 100644 --- a/mocks/database/migration/ColumnDefinition.go +++ b/mocks/database/migration/ColumnDefinition.go @@ -67,6 +67,38 @@ func (_c *ColumnDefinition_AutoIncrement_Call) RunAndReturn(run func() migration return _c } +// Change provides a mock function with given fields: +func (_m *ColumnDefinition) Change() { + _m.Called() +} + +// ColumnDefinition_Change_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Change' +type ColumnDefinition_Change_Call struct { + *mock.Call +} + +// Change is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) Change() *ColumnDefinition_Change_Call { + return &ColumnDefinition_Change_Call{Call: _e.mock.On("Change")} +} + +func (_c *ColumnDefinition_Change_Call) Run(run func()) *ColumnDefinition_Change_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_Change_Call) Return() *ColumnDefinition_Change_Call { + _c.Call.Return() + return _c +} + +func (_c *ColumnDefinition_Change_Call) RunAndReturn(run func()) *ColumnDefinition_Change_Call { + _c.Call.Return(run) + return _c +} + // GetAutoIncrement provides a mock function with given fields: func (_m *ColumnDefinition) GetAutoIncrement() bool { ret := _m.Called() @@ -384,6 +416,53 @@ func (_c *ColumnDefinition_GetType_Call) RunAndReturn(run func() string) *Column return _c } +// Nullable provides a mock function with given fields: +func (_m *ColumnDefinition) Nullable() migration.ColumnDefinition { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Nullable") + } + + var r0 migration.ColumnDefinition + if rf, ok := ret.Get(0).(func() migration.ColumnDefinition); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(migration.ColumnDefinition) + } + } + + return r0 +} + +// ColumnDefinition_Nullable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Nullable' +type ColumnDefinition_Nullable_Call struct { + *mock.Call +} + +// Nullable is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) Nullable() *ColumnDefinition_Nullable_Call { + return &ColumnDefinition_Nullable_Call{Call: _e.mock.On("Nullable")} +} + +func (_c *ColumnDefinition_Nullable_Call) Run(run func()) *ColumnDefinition_Nullable_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_Nullable_Call) Return(_a0 migration.ColumnDefinition) *ColumnDefinition_Nullable_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_Nullable_Call) RunAndReturn(run func() migration.ColumnDefinition) *ColumnDefinition_Nullable_Call { + _c.Call.Return(run) + return _c +} + // Unsigned provides a mock function with given fields: func (_m *ColumnDefinition) Unsigned() migration.ColumnDefinition { ret := _m.Called() diff --git a/mocks/database/migration/Grammar.go b/mocks/database/migration/Grammar.go index 863b52e2b..bddc0d921 100644 --- a/mocks/database/migration/Grammar.go +++ b/mocks/database/migration/Grammar.go @@ -22,6 +22,98 @@ func (_m *Grammar) EXPECT() *Grammar_Expecter { return &Grammar_Expecter{mock: &_m.Mock} } +// CompileAdd provides a mock function with given fields: blueprint +func (_m *Grammar) CompileAdd(blueprint migration.Blueprint) string { + ret := _m.Called(blueprint) + + if len(ret) == 0 { + panic("no return value specified for CompileAdd") + } + + var r0 string + if rf, ok := ret.Get(0).(func(migration.Blueprint) string); ok { + r0 = rf(blueprint) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_CompileAdd_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CompileAdd' +type Grammar_CompileAdd_Call struct { + *mock.Call +} + +// CompileAdd is a helper method to define mock.On call +// - blueprint migration.Blueprint +func (_e *Grammar_Expecter) CompileAdd(blueprint interface{}) *Grammar_CompileAdd_Call { + return &Grammar_CompileAdd_Call{Call: _e.mock.On("CompileAdd", blueprint)} +} + +func (_c *Grammar_CompileAdd_Call) Run(run func(blueprint migration.Blueprint)) *Grammar_CompileAdd_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(migration.Blueprint)) + }) + return _c +} + +func (_c *Grammar_CompileAdd_Call) Return(_a0 string) *Grammar_CompileAdd_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_CompileAdd_Call) RunAndReturn(run func(migration.Blueprint) string) *Grammar_CompileAdd_Call { + _c.Call.Return(run) + return _c +} + +// CompileChange provides a mock function with given fields: blueprint +func (_m *Grammar) CompileChange(blueprint migration.Blueprint) string { + ret := _m.Called(blueprint) + + if len(ret) == 0 { + panic("no return value specified for CompileChange") + } + + var r0 string + if rf, ok := ret.Get(0).(func(migration.Blueprint) string); ok { + r0 = rf(blueprint) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_CompileChange_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CompileChange' +type Grammar_CompileChange_Call struct { + *mock.Call +} + +// CompileChange is a helper method to define mock.On call +// - blueprint migration.Blueprint +func (_e *Grammar_Expecter) CompileChange(blueprint interface{}) *Grammar_CompileChange_Call { + return &Grammar_CompileChange_Call{Call: _e.mock.On("CompileChange", blueprint)} +} + +func (_c *Grammar_CompileChange_Call) Run(run func(blueprint migration.Blueprint)) *Grammar_CompileChange_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(migration.Blueprint)) + }) + return _c +} + +func (_c *Grammar_CompileChange_Call) Return(_a0 string) *Grammar_CompileChange_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_CompileChange_Call) RunAndReturn(run func(migration.Blueprint) string) *Grammar_CompileChange_Call { + _c.Call.Return(run) + return _c +} + // CompileCreate provides a mock function with given fields: blueprint, query func (_m *Grammar) CompileCreate(blueprint migration.Blueprint, query orm.Query) string { ret := _m.Called(blueprint, query) diff --git a/mocks/database/migration/Schema.go b/mocks/database/migration/Schema.go index ff60a070f..7614ef16a 100644 --- a/mocks/database/migration/Schema.go +++ b/mocks/database/migration/Schema.go @@ -330,6 +330,53 @@ func (_c *Schema_Sql_Call) RunAndReturn(run func(string)) *Schema_Sql_Call { return _c } +// Table provides a mock function with given fields: table, callback +func (_m *Schema) Table(table string, callback func(migration.Blueprint)) error { + ret := _m.Called(table, callback) + + if len(ret) == 0 { + panic("no return value specified for Table") + } + + 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_Table_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Table' +type Schema_Table_Call struct { + *mock.Call +} + +// Table is a helper method to define mock.On call +// - table string +// - callback func(migration.Blueprint) +func (_e *Schema_Expecter) Table(table interface{}, callback interface{}) *Schema_Table_Call { + return &Schema_Table_Call{Call: _e.mock.On("Table", table, callback)} +} + +func (_c *Schema_Table_Call) Run(run func(table string, callback func(migration.Blueprint))) *Schema_Table_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(func(migration.Blueprint))) + }) + return _c +} + +func (_c *Schema_Table_Call) Return(_a0 error) *Schema_Table_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Schema_Table_Call) RunAndReturn(run func(string, func(migration.Blueprint)) error) *Schema_Table_Call { + _c.Call.Return(run) + return _c +} + // NewSchema creates a new instance of Schema. 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 NewSchema(t interface {