From 5776698d394b7887b8571c90dd4067b906e29c2b Mon Sep 17 00:00:00 2001 From: Wenbo Han Date: Sat, 30 Nov 2024 17:55:53 +0800 Subject: [PATCH] feat: [#280] Add Time methods (#733) * feat: [#280] Add Time methods * Add column methods, TODO: test UseCurrent, Default, etc * chore: update mocks * Add test cases, TODO: fix TestColumnMethods_Sqlite * chore: update mocks * test * Add test cases, TODO: optimize TestColumnExtraAttributes * chore: update mocks * Add test cases, TODO: optimize TestColumnExtraAttributes * fix test * fix test * fix test * Add test cases * Remove test --------- Co-authored-by: hwbrzzl --- contracts/database/schema/blueprint.go | 27 +- contracts/database/schema/column.go | 14 + contracts/database/schema/grammar.go | 14 + contracts/database/schema/index.go | 5 + database/gorm/test_utils.go | 2 +- database/schema/blueprint.go | 86 ++ database/schema/column.go | 71 +- database/schema/grammars/mysql.go | 89 +- database/schema/grammars/mysql_test.go | 54 + database/schema/grammars/postgres.go | 44 +- database/schema/grammars/postgres_test.go | 16 + database/schema/grammars/sqlite.go | 46 +- database/schema/grammars/sqlserver.go | 56 +- database/schema/grammars/sqlserver_test.go | 28 + database/schema/grammars/utils.go | 12 +- database/schema/grammars/utils_test.go | 3 + database/schema/schema_test.go | 1124 ++++++++++++-------- foundation/application.go | 1 - mocks/database/schema/Blueprint.go | 640 +++++++++++ mocks/database/schema/ColumnDefinition.go | 327 ++++++ mocks/database/schema/Grammar.go | 322 ++++++ support/carbon/carbon.go | 3 +- 22 files changed, 2477 insertions(+), 507 deletions(-) diff --git a/contracts/database/schema/blueprint.go b/contracts/database/schema/blueprint.go index 092ff3ee8..e5c529160 100644 --- a/contracts/database/schema/blueprint.go +++ b/contracts/database/schema/blueprint.go @@ -15,6 +15,12 @@ type Blueprint interface { Char(column string, length ...int) ColumnDefinition // Create Indicate that the table needs to be created. Create() + // Date Create a new date column on the table. + Date(column string) ColumnDefinition + // DateTime Create a new date-time column on the table. + DateTime(column string, precision ...int) ColumnDefinition + // DateTimeTz Create a new date-time column (with time zone) on the table. + DateTimeTz(column string, precision ...int) ColumnDefinition // Decimal Create a new decimal column on the table. Decimal(column string) ColumnDefinition // Double Create a new double column on the table. @@ -65,10 +71,26 @@ type Blueprint interface { SmallIncrements(column string) ColumnDefinition // SmallInteger Create a new small integer (2-byte) column on the table. SmallInteger(column string) ColumnDefinition + // SoftDeletes Add a "deleted at" timestamp for the table. + SoftDeletes(column ...string) ColumnDefinition + // SoftDeletesTz Add a "deleted at" timestampTz for the table. + SoftDeletesTz(column ...string) ColumnDefinition // String Create a new string column on the table. String(column string, length ...int) ColumnDefinition // Text Create a new text column on the table. Text(column string) ColumnDefinition + // Time Create a new time column on the table. + Time(column string, precision ...int) ColumnDefinition + // TimeTz Create a new time column (with time zone) on the table. + TimeTz(column string, precision ...int) ColumnDefinition + // Timestamp Create a new time column on the table. + Timestamp(column string, precision ...int) ColumnDefinition + // Timestamps Add nullable creation and update timestamps to the table. + Timestamps(precision ...int) + // TimestampsTz Add creation and update timestampTz columns to the table. + TimestampsTz(precision ...int) + // TimestampTz Create a new time column (with time zone) on the table. + TimestampTz(column string, precision ...int) ColumnDefinition // TinyIncrements Create a new auto-incrementing tiny integer (1-byte) column on the table. TinyIncrements(column string) ColumnDefinition // TinyInteger Create a new tiny integer (1-byte) column on the table. @@ -88,8 +110,3 @@ type Blueprint interface { // UnsignedTinyInteger Create a new unsigned tiny integer (1-byte) column on the table. UnsignedTinyInteger(column string) ColumnDefinition } - -type IndexConfig struct { - Algorithm string - Name string -} diff --git a/contracts/database/schema/column.go b/contracts/database/schema/column.go index ebcd25b01..54ec8748e 100644 --- a/contracts/database/schema/column.go +++ b/contracts/database/schema/column.go @@ -5,6 +5,8 @@ type ColumnDefinition interface { AutoIncrement() ColumnDefinition // Comment sets the comment value Comment(comment string) ColumnDefinition + // Default set the default value + Default(def any) ColumnDefinition // GetAllowed returns the allowed value GetAllowed() []string // GetAutoIncrement returns the autoIncrement value @@ -19,6 +21,8 @@ type ColumnDefinition interface { GetName() string // GetNullable returns the nullable value GetNullable() bool + // GetOnUpdate returns the onUpdate value + GetOnUpdate() any // GetPlaces returns the places value GetPlaces() int // GetPrecision returns the precision value @@ -27,8 +31,14 @@ type ColumnDefinition interface { GetTotal() int // GetType returns the type value GetType() string + // GetUseCurrent returns the useCurrent value + GetUseCurrent() bool + // GetUseCurrentOnUpdate returns the useCurrentOnUpdate value + GetUseCurrentOnUpdate() bool // IsSetComment returns true if the comment value is set IsSetComment() bool + // OnUpdate sets the column to use the value on update (Mysql only) + OnUpdate(value any) ColumnDefinition // Places set the decimal places Places(places int) ColumnDefinition // Total set the decimal total @@ -37,6 +47,10 @@ type ColumnDefinition interface { Nullable() ColumnDefinition // Unsigned set the column as unsigned Unsigned() ColumnDefinition + // UseCurrent set the column to use the current timestamp + UseCurrent() ColumnDefinition + // UseCurrentOnUpdate set the column to use the current timestamp on update (Mysql only) + UseCurrentOnUpdate() ColumnDefinition } type Column struct { diff --git a/contracts/database/schema/grammar.go b/contracts/database/schema/grammar.go index 72e938ada..2986b8061 100644 --- a/contracts/database/schema/grammar.go +++ b/contracts/database/schema/grammar.go @@ -39,6 +39,12 @@ type Grammar interface { TypeBigInteger(column ColumnDefinition) string // TypeChar Create the column definition for a char type. TypeChar(column ColumnDefinition) string + // TypeDate Create the column definition for a date type. + TypeDate(column ColumnDefinition) string + // TypeDateTime Create the column definition for a date-time type. + TypeDateTime(column ColumnDefinition) string + // TypeDateTimeTz Create the column definition for a date-time (with time zone) type. + TypeDateTimeTz(column ColumnDefinition) string // TypeDecimal Create the column definition for a decimal type. TypeDecimal(column ColumnDefinition) string // TypeDouble Create the column definition for a double type. @@ -61,6 +67,14 @@ type Grammar interface { TypeMediumText(column ColumnDefinition) string // TypeText Create the column definition for a text type. TypeText(column ColumnDefinition) string + // TypeTime Create the column definition for a time type. + TypeTime(column ColumnDefinition) string + // TypeTimeTz Create the column definition for a time (with time zone) type. + TypeTimeTz(column ColumnDefinition) string + // TypeTimestamp Create the column definition for a timestamp type. + TypeTimestamp(column ColumnDefinition) string + // TypeTimestampTz Create the column definition for a timestamp (with time zone) type. + TypeTimestampTz(column ColumnDefinition) string // TypeTinyInteger Create the column definition for a tiny integer type. TypeTinyInteger(column ColumnDefinition) string // TypeTinyText Create the column definition for a tiny text type. diff --git a/contracts/database/schema/index.go b/contracts/database/schema/index.go index bb0c12903..5837ba940 100644 --- a/contracts/database/schema/index.go +++ b/contracts/database/schema/index.go @@ -17,3 +17,8 @@ type IndexDefinition interface { Algorithm(algorithm string) IndexDefinition Name(name string) IndexDefinition } + +type IndexConfig struct { + Algorithm string + Name string +} diff --git a/database/gorm/test_utils.go b/database/gorm/test_utils.go index 2d490d53d..68382a63d 100644 --- a/database/gorm/test_utils.go +++ b/database/gorm/test_utils.go @@ -292,7 +292,7 @@ func (r *MockMysql) basic() { r.mockConfig.On("GetBool", "app.debug").Return(true) r.mockConfig.On("GetString", fmt.Sprintf("database.connections.%s.driver", r.connection)).Return(r.driver.String()) r.mockConfig.On("GetString", fmt.Sprintf("database.connections.%s.charset", r.connection)).Return("utf8mb4") - r.mockConfig.On("GetString", fmt.Sprintf("database.connections.%s.loc", r.connection)).Return("Local") + r.mockConfig.On("GetString", fmt.Sprintf("database.connections.%s.loc", r.connection)).Return("UTC") r.mockConfig.On("GetString", fmt.Sprintf("database.connections.%s.database", r.connection)).Return(r.database) mockPool(r.mockConfig) diff --git a/database/schema/blueprint.go b/database/schema/blueprint.go index 549f9d583..51dc557a4 100644 --- a/database/schema/blueprint.go +++ b/database/schema/blueprint.go @@ -64,6 +64,28 @@ func (r *Blueprint) Decimal(column string) schema.ColumnDefinition { return r.createAndAddColumn("decimal", column) } +func (r *Blueprint) Date(column string) schema.ColumnDefinition { + return r.createAndAddColumn("date", column) +} + +func (r *Blueprint) DateTime(column string, precision ...int) schema.ColumnDefinition { + columnImpl := r.createAndAddColumn("dateTime", column) + if len(precision) > 0 { + columnImpl.precision = &precision[0] + } + + return columnImpl +} + +func (r *Blueprint) DateTimeTz(column string, precision ...int) schema.ColumnDefinition { + columnImpl := r.createAndAddColumn("dateTimeTz", column) + if len(precision) > 0 { + columnImpl.precision = &precision[0] + } + + return columnImpl +} + func (r *Blueprint) Double(column string) schema.ColumnDefinition { return r.createAndAddColumn("double", column) } @@ -192,6 +214,24 @@ func (r *Blueprint) SmallInteger(column string) schema.ColumnDefinition { return r.createAndAddColumn("smallInteger", column) } +func (r *Blueprint) SoftDeletes(column ...string) schema.ColumnDefinition { + newColumn := "deleted_at" + if len(column) > 0 { + newColumn = column[0] + } + + return r.Timestamp(newColumn).Nullable() +} + +func (r *Blueprint) SoftDeletesTz(column ...string) schema.ColumnDefinition { + newColumn := "deleted_at" + if len(column) > 0 { + newColumn = column[0] + } + + return r.TimestampTz(newColumn).Nullable() +} + func (r *Blueprint) String(column string, length ...int) schema.ColumnDefinition { defaultLength := constants.DefaultStringLength if len(length) > 0 { @@ -208,6 +248,52 @@ func (r *Blueprint) Text(column string) schema.ColumnDefinition { return r.createAndAddColumn("text", column) } +func (r *Blueprint) Time(column string, precision ...int) schema.ColumnDefinition { + columnImpl := r.createAndAddColumn("time", column) + if len(precision) > 0 { + columnImpl.precision = &precision[0] + } + + return columnImpl +} + +func (r *Blueprint) TimeTz(column string, precision ...int) schema.ColumnDefinition { + columnImpl := r.createAndAddColumn("timeTz", column) + if len(precision) > 0 { + columnImpl.precision = &precision[0] + } + + return columnImpl +} + +func (r *Blueprint) Timestamp(column string, precision ...int) schema.ColumnDefinition { + columnImpl := r.createAndAddColumn("timestamp", column) + if len(precision) > 0 { + columnImpl.precision = &precision[0] + } + + return columnImpl +} + +func (r *Blueprint) Timestamps(precision ...int) { + r.Timestamp("created_at", precision...).Nullable() + r.Timestamp("updated_at", precision...).Nullable() +} + +func (r *Blueprint) TimestampsTz(precision ...int) { + r.TimestampTz("created_at", precision...).Nullable() + r.TimestampTz("updated_at", precision...).Nullable() +} + +func (r *Blueprint) TimestampTz(column string, precision ...int) schema.ColumnDefinition { + columnImpl := r.createAndAddColumn("timestampTz", column) + if len(precision) > 0 { + columnImpl.precision = &precision[0] + } + + return columnImpl +} + func (r *Blueprint) TinyIncrements(column string) schema.ColumnDefinition { return r.UnsignedTinyInteger(column).AutoIncrement() } diff --git a/database/schema/column.go b/database/schema/column.go index 5c2a93240..61acc814a 100644 --- a/database/schema/column.go +++ b/database/schema/column.go @@ -6,18 +6,21 @@ import ( ) type ColumnDefinition struct { - allowed []string - autoIncrement *bool - comment *string - def any - length *int - name *string - nullable *bool - places *int - precision *int - total *int - ttype *string - unsigned *bool + allowed []string + autoIncrement *bool + comment *string + def any + length *int + name *string + nullable *bool + onUpdate any + places *int + precision *int + total *int + ttype *string + unsigned *bool + useCurrent *bool + useCurrentOnUpdate *bool } func (r *ColumnDefinition) AutoIncrement() schema.ColumnDefinition { @@ -32,6 +35,12 @@ func (r *ColumnDefinition) Comment(comment string) schema.ColumnDefinition { return r } +func (r *ColumnDefinition) Default(def any) schema.ColumnDefinition { + r.def = def + + return r +} + func (r *ColumnDefinition) GetAllowed() []string { return r.allowed } @@ -80,6 +89,10 @@ func (r *ColumnDefinition) GetNullable() bool { return false } +func (r *ColumnDefinition) GetOnUpdate() any { + return r.onUpdate +} + func (r *ColumnDefinition) GetPlaces() (places int) { if r.places != nil { return *r.places @@ -112,6 +125,22 @@ func (r *ColumnDefinition) GetType() (ttype string) { return } +func (r *ColumnDefinition) GetUseCurrent() (useCurrent bool) { + if r.useCurrent != nil { + return *r.useCurrent + } + + return +} + +func (r *ColumnDefinition) GetUseCurrentOnUpdate() (useCurrentOnUpdate bool) { + if r.useCurrentOnUpdate != nil { + return *r.useCurrentOnUpdate + } + + return +} + func (r *ColumnDefinition) IsSetComment() bool { return r != nil && r.comment != nil } @@ -122,6 +151,12 @@ func (r *ColumnDefinition) Nullable() schema.ColumnDefinition { return r } +func (r *ColumnDefinition) OnUpdate(value any) schema.ColumnDefinition { + r.onUpdate = value + + return r +} + func (r *ColumnDefinition) Places(places int) schema.ColumnDefinition { r.places = convert.Pointer(places) @@ -139,3 +174,15 @@ func (r *ColumnDefinition) Unsigned() schema.ColumnDefinition { return r } + +func (r *ColumnDefinition) UseCurrent() schema.ColumnDefinition { + r.useCurrent = convert.Pointer(true) + + return r +} + +func (r *ColumnDefinition) UseCurrentOnUpdate() schema.ColumnDefinition { + r.useCurrentOnUpdate = convert.Pointer(true) + + return r +} diff --git a/database/schema/grammars/mysql.go b/database/schema/grammars/mysql.go index 3cdc869ae..172962873 100644 --- a/database/schema/grammars/mysql.go +++ b/database/schema/grammars/mysql.go @@ -27,6 +27,7 @@ func NewMysql(tablePrefix string) *Mysql { mysql.ModifyDefault, mysql.ModifyIncrement, mysql.ModifyNullable, + mysql.ModifyOnUpdate, } return mysql @@ -206,6 +207,22 @@ func (r *Mysql) ModifyIncrement(blueprint schema.Blueprint, column schema.Column return "" } +func (r *Mysql) ModifyOnUpdate(blueprint schema.Blueprint, column schema.ColumnDefinition) string { + onUpdate := column.GetOnUpdate() + if onUpdate != nil { + switch value := onUpdate.(type) { + case Expression: + return " on update " + string(value) + case string: + if onUpdate.(string) != "" { + return " on update " + value + } + } + } + + return "" +} + func (r *Mysql) TypeBigInteger(column schema.ColumnDefinition) string { return "bigint" } @@ -214,6 +231,34 @@ func (r *Mysql) TypeChar(column schema.ColumnDefinition) string { return fmt.Sprintf("char(%d)", column.GetLength()) } +func (r *Mysql) TypeDate(column schema.ColumnDefinition) string { + return "date" +} + +func (r *Mysql) TypeDateTime(column schema.ColumnDefinition) string { + current := "CURRENT_TIMESTAMP" + precision := column.GetPrecision() + if precision > 0 { + current = fmt.Sprintf("CURRENT_TIMESTAMP(%d)", precision) + } + if column.GetUseCurrent() { + column.Default(Expression(current)) + } + if column.GetUseCurrentOnUpdate() { + column.OnUpdate(Expression(current)) + } + + if precision > 0 { + return fmt.Sprintf("datetime(%d)", precision) + } else { + return "datetime" + } +} + +func (r *Mysql) TypeDateTimeTz(column schema.ColumnDefinition) string { + return r.TypeDateTime(column) +} + func (r *Mysql) TypeDecimal(column schema.ColumnDefinition) string { return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) } @@ -259,10 +304,6 @@ func (r *Mysql) TypeMediumText(column schema.ColumnDefinition) string { return "mediumtext" } -func (r *Mysql) TypeText(column schema.ColumnDefinition) string { - return "text" -} - func (r *Mysql) TypeSmallInteger(column schema.ColumnDefinition) string { return "smallint" } @@ -276,6 +317,46 @@ func (r *Mysql) TypeString(column schema.ColumnDefinition) string { return "varchar(255)" } +func (r *Mysql) TypeText(column schema.ColumnDefinition) string { + return "text" +} + +func (r *Mysql) TypeTime(column schema.ColumnDefinition) string { + if column.GetPrecision() > 0 { + return fmt.Sprintf("time(%d)", column.GetPrecision()) + } else { + return "time" + } +} + +func (r *Mysql) TypeTimeTz(column schema.ColumnDefinition) string { + return r.TypeTime(column) +} + +func (r *Mysql) TypeTimestamp(column schema.ColumnDefinition) string { + current := "CURRENT_TIMESTAMP" + precision := column.GetPrecision() + if precision > 0 { + current = fmt.Sprintf("CURRENT_TIMESTAMP(%d)", precision) + } + if column.GetUseCurrent() { + column.Default(Expression(current)) + } + if column.GetUseCurrentOnUpdate() { + column.OnUpdate(Expression(current)) + } + + if precision > 0 { + return fmt.Sprintf("timestamp(%d)", precision) + } else { + return "timestamp" + } +} + +func (r *Mysql) TypeTimestampTz(column schema.ColumnDefinition) string { + return r.TypeTimestamp(column) +} + func (r *Mysql) TypeTinyInteger(column schema.ColumnDefinition) string { return "tinyint" } diff --git a/database/schema/grammars/mysql_test.go b/database/schema/grammars/mysql_test.go index 76d917351..3bb624f71 100644 --- a/database/schema/grammars/mysql_test.go +++ b/database/schema/grammars/mysql_test.go @@ -32,6 +32,7 @@ func (s *MysqlSuite) TestCompileAdd() { mockColumn.EXPECT().GetDefault().Return("goravel").Twice() mockColumn.EXPECT().GetNullable().Return(false).Once() mockColumn.EXPECT().GetLength().Return(1).Once() + mockColumn.EXPECT().GetOnUpdate().Return(nil).Once() mockColumn.EXPECT().GetComment().Return("comment").Once() sql := s.grammar.CompileAdd(mockBlueprint, &contractsschema.Command{ @@ -73,6 +74,7 @@ func (s *MysqlSuite) TestCompileCreate() { mockColumn1.EXPECT().GetType().Return("integer").Once() // postgres.go::ModifyNullable mockColumn1.EXPECT().GetNullable().Return(false).Once() + mockColumn1.EXPECT().GetOnUpdate().Return(nil).Once() mockColumn1.EXPECT().GetComment().Return("id").Once() // utils.go::getColumns @@ -87,6 +89,7 @@ func (s *MysqlSuite) TestCompileCreate() { mockColumn2.EXPECT().GetType().Return("string").Once() // postgres.go::ModifyNullable mockColumn2.EXPECT().GetNullable().Return(true).Once() + mockColumn2.EXPECT().GetOnUpdate().Return(nil).Once() mockColumn2.EXPECT().GetComment().Return("name").Once() s.Equal("create table `goravel_users` (`id` int comment 'id' auto_increment primary key not null, `name` varchar(100) comment 'name' null, primary key using btree(`role_id`, `user_id`))", @@ -221,6 +224,7 @@ func (s *MysqlSuite) TestGetColumns() { mockColumn1.EXPECT().GetType().Return("integer").Twice() mockColumn1.EXPECT().GetDefault().Return(nil).Once() mockColumn1.EXPECT().GetNullable().Return(false).Once() + mockColumn1.EXPECT().GetOnUpdate().Return(nil).Once() mockColumn1.EXPECT().GetAutoIncrement().Return(true).Once() mockColumn1.EXPECT().GetComment().Return("id").Once() @@ -228,6 +232,7 @@ func (s *MysqlSuite) TestGetColumns() { mockColumn2.EXPECT().GetType().Return("string").Twice() mockColumn2.EXPECT().GetDefault().Return("goravel").Twice() mockColumn2.EXPECT().GetNullable().Return(true).Once() + mockColumn2.EXPECT().GetOnUpdate().Return(nil).Once() mockColumn2.EXPECT().GetLength().Return(10).Once() mockColumn2.EXPECT().GetComment().Return("name").Once() @@ -297,6 +302,39 @@ func (s *MysqlSuite) TestModifyIncrement() { s.Equal(" auto_increment primary key", s.grammar.ModifyIncrement(mockBlueprint, mockColumn)) } +func (s *MysqlSuite) TestModifyOnUpdate() { + mockBlueprint := mocksschema.NewBlueprint(s.T()) + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetOnUpdate().Return(Expression("CURRENT_TIMESTAMP")).Once() + + s.Equal(" on update CURRENT_TIMESTAMP", s.grammar.ModifyOnUpdate(mockBlueprint, mockColumn)) + + mockColumn.EXPECT().GetOnUpdate().Return("CURRENT_TIMESTAMP").Once() + s.Equal(" on update CURRENT_TIMESTAMP", s.grammar.ModifyOnUpdate(mockBlueprint, mockColumn)) + + mockColumn.EXPECT().GetOnUpdate().Return("").Once() + s.Empty(s.grammar.ModifyOnUpdate(mockBlueprint, mockColumn)) + + mockColumn.EXPECT().GetOnUpdate().Return(nil).Once() + s.Empty(s.grammar.ModifyOnUpdate(mockBlueprint, mockColumn)) +} + +func (s *MysqlSuite) TestTypeDateTime() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetPrecision().Return(3).Once() + mockColumn.EXPECT().GetUseCurrent().Return(true).Once() + mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP(3)")).Return(mockColumn).Once() + mockColumn.EXPECT().GetUseCurrentOnUpdate().Return(true).Once() + mockColumn.EXPECT().OnUpdate(Expression("CURRENT_TIMESTAMP(3)")).Return(mockColumn).Once() + s.Equal("datetime(3)", s.grammar.TypeDateTime(mockColumn)) + + mockColumn = mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetPrecision().Return(0).Once() + mockColumn.EXPECT().GetUseCurrent().Return(false).Once() + mockColumn.EXPECT().GetUseCurrentOnUpdate().Return(false).Once() + s.Equal("datetime", s.grammar.TypeDateTime(mockColumn)) +} + func (s *MysqlSuite) TestTypeDecimal() { mockColumn := mocksschema.NewColumnDefinition(s.T()) mockColumn.EXPECT().GetTotal().Return(4).Once() @@ -334,3 +372,19 @@ func (s *MysqlSuite) TestTypeString() { s.Equal("varchar(255)", s.grammar.TypeString(mockColumn2)) } + +func (s *MysqlSuite) TestTypeTimestamp() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetPrecision().Return(3).Once() + mockColumn.EXPECT().GetUseCurrent().Return(true).Once() + mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP(3)")).Return(mockColumn).Once() + mockColumn.EXPECT().GetUseCurrentOnUpdate().Return(true).Once() + mockColumn.EXPECT().OnUpdate(Expression("CURRENT_TIMESTAMP(3)")).Return(mockColumn).Once() + s.Equal("timestamp(3)", s.grammar.TypeTimestamp(mockColumn)) + + mockColumn = mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetPrecision().Return(0).Once() + mockColumn.EXPECT().GetUseCurrent().Return(false).Once() + mockColumn.EXPECT().GetUseCurrentOnUpdate().Return(false).Once() + s.Equal("timestamp", s.grammar.TypeTimestamp(mockColumn)) +} diff --git a/database/schema/grammars/postgres.go b/database/schema/grammars/postgres.go index cdfff45ba..0df36b109 100644 --- a/database/schema/grammars/postgres.go +++ b/database/schema/grammars/postgres.go @@ -221,6 +221,18 @@ func (r *Postgres) TypeChar(column schema.ColumnDefinition) string { return "char" } +func (r *Postgres) TypeDate(column schema.ColumnDefinition) string { + return "date" +} + +func (r *Postgres) TypeDateTime(column schema.ColumnDefinition) string { + return r.TypeTimestamp(column) +} + +func (r *Postgres) TypeDateTimeTz(column schema.ColumnDefinition) string { + return r.TypeTimestampTz(column) +} + func (r *Postgres) TypeDecimal(column schema.ColumnDefinition) string { return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) } @@ -270,10 +282,6 @@ func (r *Postgres) TypeMediumText(column schema.ColumnDefinition) string { return "text" } -func (r *Postgres) TypeText(column schema.ColumnDefinition) string { - return "text" -} - func (r *Postgres) TypeSmallInteger(column schema.ColumnDefinition) string { if column.GetAutoIncrement() { return "smallserial" @@ -291,6 +299,34 @@ func (r *Postgres) TypeString(column schema.ColumnDefinition) string { return "varchar" } +func (r *Postgres) TypeText(column schema.ColumnDefinition) string { + return "text" +} + +func (r *Postgres) TypeTime(column schema.ColumnDefinition) string { + return fmt.Sprintf("time(%d) without time zone", column.GetPrecision()) +} + +func (r *Postgres) TypeTimeTz(column schema.ColumnDefinition) string { + return fmt.Sprintf("time(%d) with time zone", column.GetPrecision()) +} + +func (r *Postgres) TypeTimestamp(column schema.ColumnDefinition) string { + if column.GetUseCurrent() { + column.Default(Expression("CURRENT_TIMESTAMP")) + } + + return fmt.Sprintf("timestamp(%d) without time zone", column.GetPrecision()) +} + +func (r *Postgres) TypeTimestampTz(column schema.ColumnDefinition) string { + if column.GetUseCurrent() { + column.Default(Expression("CURRENT_TIMESTAMP")) + } + + return fmt.Sprintf("timestamp(%d) with time zone", column.GetPrecision()) +} + func (r *Postgres) TypeTinyInteger(column schema.ColumnDefinition) string { return r.TypeSmallInteger(column) } diff --git a/database/schema/grammars/postgres_test.go b/database/schema/grammars/postgres_test.go index d08b9e482..e5b11ffda 100644 --- a/database/schema/grammars/postgres_test.go +++ b/database/schema/grammars/postgres_test.go @@ -390,3 +390,19 @@ func (s *PostgresSuite) TestTypeString() { s.Equal("varchar", s.grammar.TypeString(mockColumn2)) } + +func (s *PostgresSuite) TestTypeTimestamp() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetUseCurrent().Return(true).Once() + mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() + mockColumn.EXPECT().GetPrecision().Return(3).Once() + s.Equal("timestamp(3) without time zone", s.grammar.TypeTimestamp(mockColumn)) +} + +func (s *PostgresSuite) TestTypeTimestampTz() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetUseCurrent().Return(true).Once() + mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() + mockColumn.EXPECT().GetPrecision().Return(3).Once() + s.Equal("timestamp(3) with time zone", s.grammar.TypeTimestampTz(mockColumn)) +} diff --git a/database/schema/grammars/sqlite.go b/database/schema/grammars/sqlite.go index 881ebb6b9..a3d27350d 100644 --- a/database/schema/grammars/sqlite.go +++ b/database/schema/grammars/sqlite.go @@ -169,6 +169,18 @@ func (r *Sqlite) TypeChar(column schema.ColumnDefinition) string { return "varchar" } +func (r *Sqlite) TypeDate(column schema.ColumnDefinition) string { + return "date" +} + +func (r *Sqlite) TypeDateTime(column schema.ColumnDefinition) string { + return r.TypeTimestamp(column) +} + +func (r *Sqlite) TypeDateTimeTz(column schema.ColumnDefinition) string { + return r.TypeDateTime(column) +} + func (r *Sqlite) TypeDecimal(column schema.ColumnDefinition) string { return "numeric" } @@ -209,24 +221,44 @@ func (r *Sqlite) TypeMediumText(column schema.ColumnDefinition) string { return "text" } +func (r *Sqlite) TypeSmallInteger(column schema.ColumnDefinition) string { + return "integer" +} + +func (r *Sqlite) TypeString(column schema.ColumnDefinition) string { + return "varchar" +} + func (r *Sqlite) TypeText(column schema.ColumnDefinition) string { return "text" } -func (r *Sqlite) TypeTinyInteger(column schema.ColumnDefinition) string { - return "integer" +func (r *Sqlite) TypeTime(column schema.ColumnDefinition) string { + return "time" } -func (r *Sqlite) TypeTinyText(column schema.ColumnDefinition) string { - return "text" +func (r *Sqlite) TypeTimeTz(column schema.ColumnDefinition) string { + return r.TypeTime(column) } -func (r *Sqlite) TypeSmallInteger(column schema.ColumnDefinition) string { +func (r *Sqlite) TypeTimestamp(column schema.ColumnDefinition) string { + if column.GetUseCurrent() { + column.Default(Expression("CURRENT_TIMESTAMP")) + } + + return "datetime" +} + +func (r *Sqlite) TypeTimestampTz(column schema.ColumnDefinition) string { + return r.TypeTimestamp(column) +} + +func (r *Sqlite) TypeTinyInteger(column schema.ColumnDefinition) string { return "integer" } -func (r *Sqlite) TypeString(column schema.ColumnDefinition) string { - return "varchar" +func (r *Sqlite) TypeTinyText(column schema.ColumnDefinition) string { + return "text" } func (r *Sqlite) addForeignKeys(commands []*schema.Command) string { diff --git a/database/schema/grammars/sqlserver.go b/database/schema/grammars/sqlserver.go index e902a090b..0aa04518d 100644 --- a/database/schema/grammars/sqlserver.go +++ b/database/schema/grammars/sqlserver.go @@ -215,6 +215,18 @@ func (r *Sqlserver) TypeChar(column schema.ColumnDefinition) string { return fmt.Sprintf("nchar(%d)", column.GetLength()) } +func (r *Sqlserver) TypeDate(column schema.ColumnDefinition) string { + return "date" +} + +func (r *Sqlserver) TypeDateTime(column schema.ColumnDefinition) string { + return r.TypeTimestamp(column) +} + +func (r *Sqlserver) TypeDateTimeTz(column schema.ColumnDefinition) string { + return r.TypeTimestampTz(column) +} + func (r *Sqlserver) TypeDecimal(column schema.ColumnDefinition) string { return fmt.Sprintf("decimal(%d, %d)", column.GetTotal(), column.GetPlaces()) } @@ -260,10 +272,6 @@ func (r *Sqlserver) TypeMediumText(column schema.ColumnDefinition) string { return "nvarchar(max)" } -func (r *Sqlserver) TypeText(column schema.ColumnDefinition) string { - return "nvarchar(max)" -} - func (r *Sqlserver) TypeSmallInteger(column schema.ColumnDefinition) string { return "smallint" } @@ -277,6 +285,46 @@ func (r *Sqlserver) TypeString(column schema.ColumnDefinition) string { return "nvarchar(255)" } +func (r *Sqlserver) TypeText(column schema.ColumnDefinition) string { + return "nvarchar(max)" +} + +func (r *Sqlserver) TypeTime(column schema.ColumnDefinition) string { + if column.GetPrecision() > 0 { + return fmt.Sprintf("time(%d)", column.GetPrecision()) + } else { + return "time" + } +} + +func (r *Sqlserver) TypeTimeTz(column schema.ColumnDefinition) string { + return r.TypeTime(column) +} + +func (r *Sqlserver) TypeTimestamp(column schema.ColumnDefinition) string { + if column.GetUseCurrent() { + column.Default(Expression("CURRENT_TIMESTAMP")) + } + + if column.GetPrecision() > 0 { + return fmt.Sprintf("datetime2(%d)", column.GetPrecision()) + } else { + return "datetime" + } +} + +func (r *Sqlserver) TypeTimestampTz(column schema.ColumnDefinition) string { + if column.GetUseCurrent() { + column.Default(Expression("CURRENT_TIMESTAMP")) + } + + if column.GetPrecision() > 0 { + return fmt.Sprintf("datetimeoffset(%d)", column.GetPrecision()) + } else { + return "datetimeoffset" + } +} + func (r *Sqlserver) TypeTinyInteger(column schema.ColumnDefinition) string { return "tinyint" } diff --git a/database/schema/grammars/sqlserver_test.go b/database/schema/grammars/sqlserver_test.go index f0977e80a..ffb6dffa4 100644 --- a/database/schema/grammars/sqlserver_test.go +++ b/database/schema/grammars/sqlserver_test.go @@ -314,3 +314,31 @@ func (s *SqlserverSuite) TestTypeString() { s.Equal("nvarchar(255)", s.grammar.TypeString(mockColumn2)) } + +func (s *SqlserverSuite) TestTypeTimestamp() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetUseCurrent().Return(true).Once() + mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() + mockColumn.EXPECT().GetPrecision().Return(3).Twice() + s.Equal("datetime2(3)", s.grammar.TypeTimestamp(mockColumn)) + + mockColumn = mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetUseCurrent().Return(true).Once() + mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() + mockColumn.EXPECT().GetPrecision().Return(0).Once() + s.Equal("datetime", s.grammar.TypeTimestamp(mockColumn)) +} + +func (s *SqlserverSuite) TestTypeTimestampTz() { + mockColumn := mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetUseCurrent().Return(true).Once() + mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() + mockColumn.EXPECT().GetPrecision().Return(3).Twice() + s.Equal("datetimeoffset(3)", s.grammar.TypeTimestampTz(mockColumn)) + + mockColumn = mocksschema.NewColumnDefinition(s.T()) + mockColumn.EXPECT().GetUseCurrent().Return(true).Once() + mockColumn.EXPECT().Default(Expression("CURRENT_TIMESTAMP")).Return(mockColumn).Once() + mockColumn.EXPECT().GetPrecision().Return(0).Once() + s.Equal("datetimeoffset", s.grammar.TypeTimestampTz(mockColumn)) +} diff --git a/database/schema/grammars/utils.go b/database/schema/grammars/utils.go index 86e180069..eb74a2252 100644 --- a/database/schema/grammars/utils.go +++ b/database/schema/grammars/utils.go @@ -10,6 +10,8 @@ import ( "github.com/goravel/framework/contracts/database/schema" ) +type Expression string + func getCommandByName(commands []*schema.Command, name string) *schema.Command { commands = getCommandsByName(commands, name) if len(commands) == 0 { @@ -31,12 +33,14 @@ func getCommandsByName(commands []*schema.Command, name string) []*schema.Comman } func getDefaultValue(def any) string { - switch def.(type) { + switch value := def.(type) { case bool: - return "'" + cast.ToString(cast.ToInt(def)) + "'" + return "'" + cast.ToString(cast.ToInt(value)) + "'" + case Expression: + return string(value) + default: + return "'" + cast.ToString(def) + "'" } - - return "'" + cast.ToString(def) + "'" } func getType(grammar schema.Grammar, column schema.ColumnDefinition) string { diff --git a/database/schema/grammars/utils_test.go b/database/schema/grammars/utils_test.go index 29d6e673d..a963718ef 100644 --- a/database/schema/grammars/utils_test.go +++ b/database/schema/grammars/utils_test.go @@ -38,6 +38,9 @@ func TestGetDefaultValue(t *testing.T) { defString := "abc" assert.Equal(t, "'abc'", getDefaultValue(defString)) + + defExpression := Expression("abc") + assert.Equal(t, "abc", getDefaultValue(defExpression)) } func TestGetType(t *testing.T) { diff --git a/database/schema/schema_test.go b/database/schema/schema_test.go index 3ed4c243c..a0ec048be 100644 --- a/database/schema/schema_test.go +++ b/database/schema/schema_test.go @@ -2,12 +2,15 @@ package schema import ( "testing" + "time" + "github.com/spf13/cast" "github.com/stretchr/testify/suite" "github.com/goravel/framework/contracts/database" contractsschema "github.com/goravel/framework/contracts/database/schema" "github.com/goravel/framework/database/gorm" + "github.com/goravel/framework/support/carbon" "github.com/goravel/framework/support/docker" "github.com/goravel/framework/support/env" ) @@ -72,6 +75,15 @@ func (s *SchemaSuite) TestColumnMethods_Postgres() { s.Require().Nil(err) for _, column := range columns { + if column.Name == "another_deleted_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("timestamp(0) with time zone", column.Type) + s.Equal("timestamptz", column.TypeName) + } if column.Name == "big_integer" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -90,33 +102,42 @@ func (s *SchemaSuite) TestColumnMethods_Postgres() { s.Equal("character(255)", column.Type) s.Equal("bpchar", column.TypeName) } - //if column.Name == "date" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a date column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("date", column.Type) - // s.Equal("date", column.TypeName) - //} - //if column.Name == "date_time" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a date time column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(3) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "date_time_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a date time with time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(3) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} + if column.Name == "created_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("timestamp(2) without time zone", column.Type) + s.Equal("timestamp", column.TypeName) + } + if column.Name == "date" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a date column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("date", column.Type) + s.Equal("date", column.TypeName) + } + if column.Name == "date_time" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a date time column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("timestamp(3) without time zone", column.Type) + s.Equal("timestamp", column.TypeName) + } + if column.Name == "date_time_tz" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a date time with time zone column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("timestamp(3) with time zone", column.Type) + s.Equal("timestamptz", column.TypeName) + } if column.Name == "decimal" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -126,6 +147,15 @@ func (s *SchemaSuite) TestColumnMethods_Postgres() { s.Equal("numeric(4,1)", column.Type) s.Equal("numeric", column.TypeName) } + if column.Name == "deleted_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("timestamp(0) without time zone", column.Type) + s.Equal("timestamp", column.TypeName) + } if column.Name == "double" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -171,32 +201,14 @@ func (s *SchemaSuite) TestColumnMethods_Postgres() { s.Equal("integer", column.Type) s.Equal("int4", column.TypeName) } - //if column.Name == "deleted_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(0) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "another_deleted_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(0) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} - if column.Name == "string" { + if column.Name == "integer_default" { s.False(column.Autoincrement) s.Empty(column.Collation) - s.Equal("This is a string column", column.Comment) - s.Empty(column.Default) + s.Equal("This is a integer_default column", column.Comment) + s.Equal(1, cast.ToInt(column.Default)) s.False(column.Nullable) - s.Equal("character varying(255)", column.Type) - s.Equal("varchar", column.TypeName) + s.Equal("integer", column.Type) + s.Equal("int4", column.TypeName) } if column.Name == "json" { s.False(column.Autoincrement) @@ -216,33 +228,105 @@ func (s *SchemaSuite) TestColumnMethods_Postgres() { s.Equal("jsonb", column.Type) s.Equal("jsonb", column.TypeName) } - if column.Name == "text" { + if column.Name == "long_text" { s.False(column.Autoincrement) s.Empty(column.Collation) - s.Equal("This is a text column", column.Comment) + s.Equal("This is a long_text column", column.Comment) s.Empty(column.Default) s.False(column.Nullable) s.Equal("text", column.Type) s.Equal("text", column.TypeName) } - if column.Name == "long_text" { + if column.Name == "medium_text" { s.False(column.Autoincrement) s.Empty(column.Collation) - s.Equal("This is a long_text column", column.Comment) + s.Equal("This is a medium_text column", column.Comment) s.Empty(column.Default) s.False(column.Nullable) s.Equal("text", column.Type) s.Equal("text", column.TypeName) } - if column.Name == "medium_text" { + if column.Name == "string" { s.False(column.Autoincrement) s.Empty(column.Collation) - s.Equal("This is a medium_text column", column.Comment) + s.Equal("This is a string column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("character varying(255)", column.Type) + s.Equal("varchar", column.TypeName) + } + if column.Name == "string_default" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a string_default 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 == "text" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a text column", column.Comment) s.Empty(column.Default) s.False(column.Nullable) s.Equal("text", column.Type) s.Equal("text", column.TypeName) } + if column.Name == "time" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a time column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("time(2) without time zone", column.Type) + s.Equal("time", column.TypeName) + } + if column.Name == "time_tz" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a time with time zone column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("time(2) with time zone", column.Type) + s.Equal("timetz", column.TypeName) + } + if column.Name == "timestamp" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a timestamp without time zone column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("timestamp(2) without time zone", column.Type) + s.Equal("timestamp", column.TypeName) + } + if column.Name == "timestamp_tz" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a timestamp with time zone column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("timestamp(2) with time zone", column.Type) + s.Equal("timestamptz", column.TypeName) + } + if column.Name == "timestamp_use_current" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a timestamp_use_current column", column.Comment) + s.Equal("CURRENT_TIMESTAMP", column.Default) + s.False(column.Nullable) + s.Equal("timestamp(0) without time zone", column.Type) + s.Equal("timestamp", column.TypeName) + } + if column.Name == "timestamp_use_current_on_update" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a timestamp_use_current_on_update column", column.Comment) + s.Equal("CURRENT_TIMESTAMP", column.Default) + s.False(column.Nullable) + s.Equal("timestamp(0) without time zone", column.Type) + s.Equal("timestamp", column.TypeName) + } if column.Name == "tiny_text" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -252,60 +336,15 @@ func (s *SchemaSuite) TestColumnMethods_Postgres() { s.Equal("character varying(255)", column.Type) s.Equal("varchar", column.TypeName) } - //if column.Name == "time" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a time column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("time(2) without time zone", column.Type) - // s.Equal("time", column.TypeName) - //} - //if column.Name == "time_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a time with time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("time(2) with time zone", column.Type) - // s.Equal("timetz", column.TypeName) - //} - //if column.Name == "timestamp" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a timestamp without time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "timestamp_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a timestamp with time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(2) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} - //if column.Name == "created_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "updated_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} + if column.Name == "updated_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("timestamp(2) without time zone", column.Type) + s.Equal("timestamp", column.TypeName) + } if column.Name == "unsigned_integer" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -341,6 +380,13 @@ func (s *SchemaSuite) TestColumnMethods_Sqlite() { s.Require().Nil(err) for _, column := range columns { + if column.Name == "another_deleted_at" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("datetime", column.Type) + } if column.Name == "big_integer" { s.False(column.Autoincrement) s.Empty(column.Comment) @@ -355,33 +401,34 @@ func (s *SchemaSuite) TestColumnMethods_Sqlite() { s.False(column.Nullable) s.Equal("varchar", column.Type) } - //if column.Name == "date" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a date column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("date", column.Type) - // s.Equal("date", column.TypeName) - //} - //if column.Name == "date_time" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a date time column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(3) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "date_time_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a date time with time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(3) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} + if column.Name == "created_at" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("datetime", column.Type) + } + if column.Name == "date" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("date", column.Type) + } + if column.Name == "date_time" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetime", column.Type) + } + if column.Name == "date_time_tz" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetime", column.Type) + } if column.Name == "decimal" { s.False(column.Autoincrement) s.Empty(column.Comment) @@ -389,6 +436,13 @@ func (s *SchemaSuite) TestColumnMethods_Sqlite() { s.False(column.Nullable) s.Equal("numeric", column.Type) } + if column.Name == "deleted_at" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("datetime", column.Type) + } if column.Name == "double" { s.False(column.Autoincrement) s.Empty(column.Comment) @@ -424,30 +478,12 @@ func (s *SchemaSuite) TestColumnMethods_Sqlite() { s.False(column.Nullable) s.Equal("integer", column.Type) } - //if column.Name == "deleted_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(0) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "another_deleted_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(0) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} - if column.Name == "string" { + if column.Name == "integer_default" { s.False(column.Autoincrement) s.Empty(column.Comment) - s.Empty(column.Default) + s.Equal("'1'", column.Default) s.False(column.Nullable) - s.Equal("varchar", column.Type) + s.Equal("integer", column.Type) } if column.Name == "json" { s.False(column.Autoincrement) @@ -463,21 +499,35 @@ func (s *SchemaSuite) TestColumnMethods_Sqlite() { s.False(column.Nullable) s.Equal("text", column.Type) } - if column.Name == "text" { + if column.Name == "long_text" { s.False(column.Autoincrement) s.Empty(column.Comment) s.Empty(column.Default) s.False(column.Nullable) s.Equal("text", column.Type) } - if column.Name == "long_text" { + if column.Name == "medium_text" { s.False(column.Autoincrement) s.Empty(column.Comment) s.Empty(column.Default) s.False(column.Nullable) s.Equal("text", column.Type) } - if column.Name == "medium_text" { + if column.Name == "string" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("varchar", column.Type) + } + if column.Name == "string_default" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Equal("'goravel'", column.Default) + s.False(column.Nullable) + s.Equal("varchar", column.Type) + } + if column.Name == "text" { s.False(column.Autoincrement) s.Empty(column.Comment) s.Empty(column.Default) @@ -491,60 +541,55 @@ func (s *SchemaSuite) TestColumnMethods_Sqlite() { s.False(column.Nullable) s.Equal("text", column.Type) } - //if column.Name == "time" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a time column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("time(2) without time zone", column.Type) - // s.Equal("time", column.TypeName) - //} - //if column.Name == "time_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a time with time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("time(2) with time zone", column.Type) - // s.Equal("timetz", column.TypeName) - //} - //if column.Name == "timestamp" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a timestamp without time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "timestamp_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a timestamp with time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(2) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} - //if column.Name == "created_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "updated_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} + if column.Name == "time" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("time", column.Type) + } + if column.Name == "time_tz" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("time", column.Type) + } + if column.Name == "timestamp" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetime", column.Type) + } + if column.Name == "timestamp_tz" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetime", column.Type) + } + if column.Name == "timestamp_use_current" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Equal("CURRENT_TIMESTAMP", column.Default) + s.False(column.Nullable) + s.Equal("datetime", column.Type) + } + if column.Name == "timestamp_use_current_on_update" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Equal("CURRENT_TIMESTAMP", column.Default) + s.False(column.Nullable) + s.Equal("datetime", column.Type) + } + if column.Name == "updated_at" { + s.False(column.Autoincrement) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("datetime", column.Type) + } if column.Name == "unsigned_integer" { s.False(column.Autoincrement) s.Empty(column.Comment) @@ -576,6 +621,15 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Require().Nil(err) for _, column := range columns { + if column.Name == "another_deleted_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("timestamp", column.Type) + s.Equal("timestamp", column.TypeName) + } if column.Name == "big_integer" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -594,33 +648,42 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Equal("char(255)", column.Type) s.Equal("char", column.TypeName) } - //if column.Name == "date" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a date column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("date", column.Type) - // s.Equal("date", column.TypeName) - //} - //if column.Name == "date_time" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a date time column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(3) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "date_time_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a date time with time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(3) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} + if column.Name == "created_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("timestamp(2)", column.Type) + s.Equal("timestamp", column.TypeName) + } + if column.Name == "date" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a date column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("date", column.Type) + s.Equal("date", column.TypeName) + } + if column.Name == "date_time" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a date time column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetime(3)", column.Type) + s.Equal("datetime", column.TypeName) + } + if column.Name == "date_time_tz" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a date time with time zone column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetime(3)", column.Type) + s.Equal("datetime", column.TypeName) + } if column.Name == "decimal" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -630,6 +693,15 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Equal("decimal(4,1)", column.Type) s.Equal("decimal", column.TypeName) } + if column.Name == "deleted_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("timestamp", column.Type) + s.Equal("timestamp", column.TypeName) + } if column.Name == "double" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -675,32 +747,14 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Equal("int", column.Type) s.Equal("int", column.TypeName) } - //if column.Name == "deleted_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(0) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "another_deleted_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(0) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} - if column.Name == "string" { + if column.Name == "integer_default" { s.False(column.Autoincrement) - s.Equal("utf8mb4_0900_ai_ci", column.Collation) - s.Equal("This is a string column", column.Comment) - s.Empty(column.Default) + s.Empty(column.Collation) + s.Equal("This is a integer_default column", column.Comment) + s.Equal(1, cast.ToInt(column.Default)) s.False(column.Nullable) - s.Equal("varchar(255)", column.Type) - s.Equal("varchar", column.TypeName) + s.Equal("int", column.Type) + s.Equal("int", column.TypeName) } if column.Name == "json" { s.False(column.Autoincrement) @@ -720,15 +774,6 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Equal("json", column.Type) s.Equal("json", column.TypeName) } - if column.Name == "text" { - s.False(column.Autoincrement) - s.Equal("utf8mb4_0900_ai_ci", column.Collation) - s.Equal("This is a text column", column.Comment) - s.Empty(column.Default) - s.False(column.Nullable) - s.Equal("text", column.Type) - s.Equal("text", column.TypeName) - } if column.Name == "long_text" { s.False(column.Autoincrement) s.Equal("utf8mb4_0900_ai_ci", column.Collation) @@ -747,6 +792,87 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Equal("mediumtext", column.Type) s.Equal("mediumtext", column.TypeName) } + if column.Name == "string" { + s.False(column.Autoincrement) + s.Equal("utf8mb4_0900_ai_ci", column.Collation) + s.Equal("This is a string column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("varchar(255)", column.Type) + s.Equal("varchar", column.TypeName) + } + if column.Name == "string_default" { + s.False(column.Autoincrement) + s.Equal("utf8mb4_0900_ai_ci", column.Collation) + s.Equal("This is a string_default column", column.Comment) + s.Equal("goravel", column.Default) + s.False(column.Nullable) + s.Equal("varchar(255)", column.Type) + s.Equal("varchar", column.TypeName) + } + if column.Name == "text" { + s.False(column.Autoincrement) + s.Equal("utf8mb4_0900_ai_ci", column.Collation) + s.Equal("This is a text column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("text", column.Type) + s.Equal("text", column.TypeName) + } + if column.Name == "time" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a time column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("time(2)", column.Type) + s.Equal("time", column.TypeName) + } + if column.Name == "time_tz" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a time with time zone column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("time(2)", column.Type) + s.Equal("time", column.TypeName) + } + if column.Name == "timestamp" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a timestamp without time zone column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("timestamp(2)", column.Type) + s.Equal("timestamp", column.TypeName) + } + if column.Name == "timestamp_tz" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a timestamp with time zone column", column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("timestamp(2)", column.Type) + s.Equal("timestamp", column.TypeName) + } + if column.Name == "timestamp_use_current" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a timestamp_use_current column", column.Comment) + s.Equal("CURRENT_TIMESTAMP", column.Default) + s.False(column.Nullable) + s.Equal("timestamp", column.Type) + s.Equal("timestamp", column.TypeName) + } + if column.Name == "timestamp_use_current_on_update" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Equal("This is a timestamp_use_current_on_update column", column.Comment) + s.Equal("CURRENT_TIMESTAMP", column.Default) + s.False(column.Nullable) + s.Equal("timestamp", column.Type) + s.Equal("timestamp", column.TypeName) + } if column.Name == "tiny_text" { s.False(column.Autoincrement) s.Equal("utf8mb4_0900_ai_ci", column.Collation) @@ -756,60 +882,15 @@ func (s *SchemaSuite) TestColumnMethods_Mysql() { s.Equal("tinytext", column.Type) s.Equal("tinytext", column.TypeName) } - //if column.Name == "time" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a time column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("time(2) without time zone", column.Type) - // s.Equal("time", column.TypeName) - //} - //if column.Name == "time_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a time with time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("time(2) with time zone", column.Type) - // s.Equal("timetz", column.TypeName) - //} - //if column.Name == "timestamp" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a timestamp without time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "timestamp_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Equal("This is a timestamp with time zone column", column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(2) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} - //if column.Name == "created_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "updated_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} + if column.Name == "updated_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("timestamp(2)", column.Type) + s.Equal("timestamp", column.TypeName) + } if column.Name == "unsigned_integer" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -845,6 +926,15 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Require().Nil(err) for _, column := range columns { + if column.Name == "another_deleted_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("datetimeoffset(34)", column.Type) + s.Equal("datetimeoffset", column.TypeName) + } if column.Name == "big_integer" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -863,33 +953,42 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("nchar(510)", column.Type) s.Equal("nchar", column.TypeName) } - //if column.Name == "date" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("date", column.Type) - // s.Equal("date", column.TypeName) - //} - //if column.Name == "date_time" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(3) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "date_time_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(3) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} + if column.Name == "created_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("datetime2(22)", column.Type) + s.Equal("datetime2", column.TypeName) + } + if column.Name == "date" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("date", column.Type) + s.Equal("date", column.TypeName) + } + if column.Name == "date_time" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetime2(23)", column.Type) + s.Equal("datetime2", column.TypeName) + } + if column.Name == "date_time_tz" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetimeoffset(30)", column.Type) + s.Equal("datetimeoffset", column.TypeName) + } if column.Name == "decimal" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -899,6 +998,15 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("decimal(4,1)", column.Type) s.Equal("decimal", column.TypeName) } + if column.Name == "deleted_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("datetime", column.Type) + s.Equal("datetime", column.TypeName) + } if column.Name == "double" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -944,32 +1052,14 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("int", column.Type) s.Equal("int", column.TypeName) } - //if column.Name == "deleted_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(0) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "another_deleted_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(0) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} - if column.Name == "string" { + if column.Name == "integer_default" { s.False(column.Autoincrement) - s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Collation) s.Empty(column.Comment) - s.Empty(column.Default) + s.Equal("('1')", column.Default) s.False(column.Nullable) - s.Equal("nvarchar(510)", column.Type) - s.Equal("nvarchar", column.TypeName) + s.Equal("int", column.Type) + s.Equal("int", column.TypeName) } if column.Name == "json" { s.False(column.Autoincrement) @@ -989,7 +1079,7 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("nvarchar(max)", column.Type) s.Equal("nvarchar", column.TypeName) } - if column.Name == "text" { + if column.Name == "long_text" { s.False(column.Autoincrement) s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) s.Empty(column.Comment) @@ -998,7 +1088,7 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("nvarchar(max)", column.Type) s.Equal("nvarchar", column.TypeName) } - if column.Name == "long_text" { + if column.Name == "medium_text" { s.False(column.Autoincrement) s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) s.Empty(column.Comment) @@ -1007,7 +1097,25 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("nvarchar(max)", column.Type) s.Equal("nvarchar", column.TypeName) } - if column.Name == "medium_text" { + if column.Name == "string" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("nvarchar(510)", column.Type) + s.Equal("nvarchar", column.TypeName) + } + if column.Name == "string_default" { + s.False(column.Autoincrement) + s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) + s.Empty(column.Comment) + s.Equal("('goravel')", column.Default) + s.False(column.Nullable) + s.Equal("nvarchar(510)", column.Type) + s.Equal("nvarchar", column.TypeName) + } + if column.Name == "text" { s.False(column.Autoincrement) s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) s.Empty(column.Comment) @@ -1016,6 +1124,60 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("nvarchar(max)", column.Type) s.Equal("nvarchar", column.TypeName) } + if column.Name == "time" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("time(11)", column.Type) + s.Equal("time", column.TypeName) + } + if column.Name == "time_tz" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("time(11)", column.Type) + s.Equal("time", column.TypeName) + } + if column.Name == "timestamp" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetime2(22)", column.Type) + s.Equal("datetime2", column.TypeName) + } + if column.Name == "timestamp_tz" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.False(column.Nullable) + s.Equal("datetimeoffset(29)", column.Type) + s.Equal("datetimeoffset", column.TypeName) + } + if column.Name == "timestamp_use_current" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Equal("(getdate())", column.Default) + s.False(column.Nullable) + s.Equal("datetime", column.Type) + s.Equal("datetime", column.TypeName) + } + if column.Name == "timestamp_use_current_on_update" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Equal("(getdate())", column.Default) + s.False(column.Nullable) + s.Equal("datetime", column.Type) + s.Equal("datetime", column.TypeName) + } if column.Name == "tiny_text" { s.False(column.Autoincrement) s.Equal("SQL_Latin1_General_CP1_CI_AS", column.Collation) @@ -1025,60 +1187,15 @@ func (s *SchemaSuite) TestColumnMethods_Sqlserver() { s.Equal("nvarchar(510)", column.Type) s.Equal("nvarchar", column.TypeName) } - //if column.Name == "time" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("time(2) without time zone", column.Type) - // s.Equal("time", column.TypeName) - //} - //if column.Name == "time_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("time(2) with time zone", column.Type) - // s.Equal("timetz", column.TypeName) - //} - //if column.Name == "timestamp" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "timestamp_tz" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.False(column.Nullable) - // s.Equal("timestamp(2) with time zone", column.Type) - // s.Equal("timestamptz", column.TypeName) - //} - //if column.Name == "created_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} - //if column.Name == "updated_at" { - // s.False(column.Autoincrement) - // s.Empty(column.Collation) - // s.Empty(column.Comment) - // s.Empty(column.Default) - // s.True(column.Nullable) - // s.Equal("timestamp(2) without time zone", column.Type) - // s.Equal("timestamp", column.TypeName) - //} + if column.Name == "updated_at" { + s.False(column.Autoincrement) + s.Empty(column.Collation) + s.Empty(column.Comment) + s.Empty(column.Default) + s.True(column.Nullable) + s.Equal("datetime2(22)", column.Type) + s.Equal("datetime2", column.TypeName) + } if column.Name == "unsigned_integer" { s.False(column.Autoincrement) s.Empty(column.Collation) @@ -1117,6 +1234,77 @@ func (s *SchemaSuite) TestCreate_DropIfExists_HasTable() { } } +func (s *SchemaSuite) TestColumnExtraAttributes() { + for driver, testQuery := range s.driverToTestQuery { + s.Run(driver.String(), func() { + schema := GetTestSchema(testQuery, s.driverToTestQuery) + table := "column_extra_attribute" + + s.NoError(schema.Create(table, func(table contractsschema.Blueprint) { + table.ID() + table.String("name") + table.String("nullable").Nullable() + table.String("string_default").Default("goravel") + table.Integer("integer_default").Default(1) + table.Integer("bool_default").Default(true) + table.TimestampTz("use_current").UseCurrent() + table.TimestampTz("use_current_on_update").UseCurrent().UseCurrentOnUpdate() + })) + + type ColumnExtraAttribute struct { + ID uint `gorm:"primaryKey" json:"id"` + Name string `json:"name"` + Nullable *string `json:"nullable"` + StringDefault string `json:"string_default"` + IntegerDefault int `json:"integer_default"` + BoolDefault bool `json:"bool_default"` + UseCurrent carbon.DateTime `json:"use_current"` + UseCurrentOnUpdate carbon.DateTime `json:"use_current_on_update"` + } + + // SubSecond: Avoid milliseconds difference + carbon.SetTimezone(carbon.UTC) + now := carbon.Now().SubSecond() + + s.NoError(testQuery.Query().Model(&ColumnExtraAttribute{}).Create(map[string]any{ + "name": "hello", + })) + + interval := int64(1) + var columnExtraAttribute ColumnExtraAttribute + s.NoError(testQuery.Query().Where("name", "hello").First(&columnExtraAttribute)) + s.True(columnExtraAttribute.ID > 0) + s.Equal("hello", columnExtraAttribute.Name) + s.Nil(columnExtraAttribute.Nullable) + s.Equal("goravel", columnExtraAttribute.StringDefault) + s.Equal(1, columnExtraAttribute.IntegerDefault) + s.True(columnExtraAttribute.BoolDefault) + s.True(columnExtraAttribute.UseCurrent.Between(now, carbon.Now().AddSecond())) + s.True(columnExtraAttribute.UseCurrentOnUpdate.Between(now, carbon.Now().AddSecond())) + + time.Sleep(time.Duration(interval) * time.Second) + + now = carbon.Now().SubSecond() + result, err := testQuery.Query().Model(&ColumnExtraAttribute{}).Where("id", columnExtraAttribute.ID).Update(map[string]any{ + "name": "world", + }) + s.NoError(err) + s.Equal(int64(1), result.RowsAffected) + + var anotherColumnExtraAttribute ColumnExtraAttribute + s.NoError(testQuery.Query().Where("id", columnExtraAttribute.ID).First(&anotherColumnExtraAttribute)) + s.Equal("world", anotherColumnExtraAttribute.Name) + s.Equal(columnExtraAttribute.UseCurrent, anotherColumnExtraAttribute.UseCurrent) + if driver == database.DriverMysql { + s.NotEqual(columnExtraAttribute.UseCurrentOnUpdate, anotherColumnExtraAttribute.UseCurrentOnUpdate) + s.True(anotherColumnExtraAttribute.UseCurrentOnUpdate.Between(now, carbon.Now().AddSecond())) + } else { + s.Equal(columnExtraAttribute.UseCurrentOnUpdate, anotherColumnExtraAttribute.UseCurrentOnUpdate) + } + }) + } +} + func (s *SchemaSuite) TestDropAllTables() { for driver, testQuery := range s.driverToTestQuery { s.Run(driver.String(), func() { @@ -1631,29 +1819,33 @@ func (s *SchemaSuite) createTableAndAssertColumnsForColumnMethods(schema contrac err := schema.Create(table, func(table contractsschema.Blueprint) { table.BigInteger("big_integer").Comment("This is a big_integer column") table.Char("char").Comment("This is a char column") - //table.Date("date").Comment("This is a date column") - //table.DateTime("date_time", 3).Comment("This is a date time column") - //table.DateTimeTz("date_time_tz", 3).Comment("This is a date time with time zone column") + table.Date("date").Comment("This is a date column") + table.DateTime("date_time", 3).Comment("This is a date time column") + table.DateTimeTz("date_time_tz", 3).Comment("This is a date time with time zone column") table.Decimal("decimal").Places(1).Total(4).Comment("This is a decimal column") table.Double("double").Comment("This is a double column") table.Enum("enum", []string{"a", "b", "c"}).Comment("This is a enum column") table.Float("float", 2).Comment("This is a float column") + table.LongText("long_text").Comment("This is a long_text column") + table.MediumText("medium_text").Comment("This is a medium_text column") table.ID().Comment("This is a id column") table.Integer("integer").Comment("This is a integer column") - //table.SoftDeletes() - //table.SoftDeletesTz("another_deleted_at") - table.String("string").Comment("This is a string column") + table.Integer("integer_default").Default(1).Comment("This is a integer_default column") table.Json("json").Comment("This is a json column") table.Jsonb("jsonb").Comment("This is a jsonb column") + table.SoftDeletes() + table.SoftDeletesTz("another_deleted_at") + table.String("string").Comment("This is a string column") + table.String("string_default").Default("goravel").Comment("This is a string_default column") table.Text("text").Comment("This is a text column") - table.LongText("long_text").Comment("This is a long_text column") - table.MediumText("medium_text").Comment("This is a medium_text column") table.TinyText("tiny_text").Comment("This is a tiny_text column") - //table.Time("time", 2).Comment("This is a time column") - //table.TimeTz("time_tz", 2).Comment("This is a time with time zone column") - //table.Timestamp("timestamp", 2).Comment("This is a timestamp without time zone column") - //table.TimestampTz("timestamp_tz", 2).Comment("This is a timestamp with time zone column") - //table.Timestamps(2) + table.Time("time", 2).Comment("This is a time column") + table.TimeTz("time_tz", 2).Comment("This is a time with time zone column") + table.Timestamp("timestamp", 2).Comment("This is a timestamp without time zone column") + table.TimestampTz("timestamp_tz", 2).Comment("This is a timestamp with time zone column") + table.Timestamps(2) + table.Timestamp("timestamp_use_current").UseCurrent().Comment("This is a timestamp_use_current column") + table.Timestamp("timestamp_use_current_on_update").UseCurrent().UseCurrentOnUpdate().Comment("This is a timestamp_use_current_on_update column") table.UnsignedInteger("unsigned_integer").Comment("This is a unsigned_integer column") table.UnsignedBigInteger("unsigned_big_integer").Comment("This is a unsigned_big_integer column") }) @@ -1665,33 +1857,37 @@ func (s *SchemaSuite) createTableAndAssertColumnsForColumnMethods(schema contrac columnListing := schema.GetColumnListing(table) - s.Equal(17, len(columnListing)) + s.Equal(32, len(columnListing)) + s.Contains(columnListing, "another_deleted_at") s.Contains(columnListing, "big_integer") s.Contains(columnListing, "char") - //s.Contains(columnListing, "date") - //s.Contains(columnListing, "date_time") - //s.Contains(columnListing, "date_time_tz") + s.Contains(columnListing, "created_at") + s.Contains(columnListing, "date") + s.Contains(columnListing, "date_time") + s.Contains(columnListing, "date_time_tz") s.Contains(columnListing, "decimal") + s.Contains(columnListing, "deleted_at") s.Contains(columnListing, "double") s.Contains(columnListing, "enum") + s.Contains(columnListing, "float") s.Contains(columnListing, "id") s.Contains(columnListing, "integer") - //s.Contains(columnListing, "deleted_at") - //s.Contains(columnListing, "another_deleted_at") - s.Contains(columnListing, "string") + s.Contains(columnListing, "integer_default") s.Contains(columnListing, "json") s.Contains(columnListing, "jsonb") - s.Contains(columnListing, "text") s.Contains(columnListing, "long_text") s.Contains(columnListing, "medium_text") + s.Contains(columnListing, "string") + s.Contains(columnListing, "string_default") + s.Contains(columnListing, "text") s.Contains(columnListing, "tiny_text") - //s.Contains(columnListing, "time") - //s.Contains(columnListing, "time_tz") - //s.Contains(columnListing, "timestamp") - //s.Contains(columnListing, "timestamp_tz") - //s.Contains(columnListing, "created_at") - //s.Contains(columnListing, "updated_at") + s.Contains(columnListing, "time") + s.Contains(columnListing, "time_tz") + s.Contains(columnListing, "timestamp") + s.Contains(columnListing, "timestamp_tz") + s.Contains(columnListing, "timestamp_use_current") + s.Contains(columnListing, "timestamp_use_current_on_update") s.Contains(columnListing, "unsigned_integer") s.Contains(columnListing, "unsigned_big_integer") - + s.Contains(columnListing, "updated_at") } diff --git a/foundation/application.go b/foundation/application.go index e5f278f4e..963f1e6a3 100644 --- a/foundation/application.go +++ b/foundation/application.go @@ -258,7 +258,6 @@ func (app *Application) setTimezone() { } carbon.SetTimezone(configFacade.GetString("app.timezone", carbon.UTC)) - } func setEnv() { diff --git a/mocks/database/schema/Blueprint.go b/mocks/database/schema/Blueprint.go index 708221df7..550b74025 100644 --- a/mocks/database/schema/Blueprint.go +++ b/mocks/database/schema/Blueprint.go @@ -259,6 +259,180 @@ func (_c *Blueprint_Create_Call) RunAndReturn(run func()) *Blueprint_Create_Call return _c } +// Date provides a mock function with given fields: column +func (_m *Blueprint) Date(column string) schema.ColumnDefinition { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for Date") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string) schema.ColumnDefinition); ok { + r0 = rf(column) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_Date_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Date' +type Blueprint_Date_Call struct { + *mock.Call +} + +// Date is a helper method to define mock.On call +// - column string +func (_e *Blueprint_Expecter) Date(column interface{}) *Blueprint_Date_Call { + return &Blueprint_Date_Call{Call: _e.mock.On("Date", column)} +} + +func (_c *Blueprint_Date_Call) Run(run func(column string)) *Blueprint_Date_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Blueprint_Date_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_Date_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_Date_Call) RunAndReturn(run func(string) schema.ColumnDefinition) *Blueprint_Date_Call { + _c.Call.Return(run) + return _c +} + +// DateTime provides a mock function with given fields: column, precision +func (_m *Blueprint) DateTime(column string, precision ...int) schema.ColumnDefinition { + _va := make([]interface{}, len(precision)) + for _i := range precision { + _va[_i] = precision[_i] + } + var _ca []interface{} + _ca = append(_ca, column) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for DateTime") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string, ...int) schema.ColumnDefinition); ok { + r0 = rf(column, precision...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_DateTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DateTime' +type Blueprint_DateTime_Call struct { + *mock.Call +} + +// DateTime is a helper method to define mock.On call +// - column string +// - precision ...int +func (_e *Blueprint_Expecter) DateTime(column interface{}, precision ...interface{}) *Blueprint_DateTime_Call { + return &Blueprint_DateTime_Call{Call: _e.mock.On("DateTime", + append([]interface{}{column}, precision...)...)} +} + +func (_c *Blueprint_DateTime_Call) Run(run func(column string, precision ...int)) *Blueprint_DateTime_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_DateTime_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_DateTime_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_DateTime_Call) RunAndReturn(run func(string, ...int) schema.ColumnDefinition) *Blueprint_DateTime_Call { + _c.Call.Return(run) + return _c +} + +// DateTimeTz provides a mock function with given fields: column, precision +func (_m *Blueprint) DateTimeTz(column string, precision ...int) schema.ColumnDefinition { + _va := make([]interface{}, len(precision)) + for _i := range precision { + _va[_i] = precision[_i] + } + var _ca []interface{} + _ca = append(_ca, column) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for DateTimeTz") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string, ...int) schema.ColumnDefinition); ok { + r0 = rf(column, precision...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_DateTimeTz_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DateTimeTz' +type Blueprint_DateTimeTz_Call struct { + *mock.Call +} + +// DateTimeTz is a helper method to define mock.On call +// - column string +// - precision ...int +func (_e *Blueprint_Expecter) DateTimeTz(column interface{}, precision ...interface{}) *Blueprint_DateTimeTz_Call { + return &Blueprint_DateTimeTz_Call{Call: _e.mock.On("DateTimeTz", + append([]interface{}{column}, precision...)...)} +} + +func (_c *Blueprint_DateTimeTz_Call) Run(run func(column string, precision ...int)) *Blueprint_DateTimeTz_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_DateTimeTz_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_DateTimeTz_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_DateTimeTz_Call) RunAndReturn(run func(string, ...int) schema.ColumnDefinition) *Blueprint_DateTimeTz_Call { + _c.Call.Return(run) + return _c +} + // Decimal provides a mock function with given fields: column func (_m *Blueprint) Decimal(column string) schema.ColumnDefinition { ret := _m.Called(column) @@ -1474,6 +1648,128 @@ func (_c *Blueprint_SmallInteger_Call) RunAndReturn(run func(string) schema.Colu return _c } +// SoftDeletes provides a mock function with given fields: column +func (_m *Blueprint) SoftDeletes(column ...string) schema.ColumnDefinition { + _va := make([]interface{}, len(column)) + for _i := range column { + _va[_i] = column[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for SoftDeletes") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(...string) schema.ColumnDefinition); ok { + r0 = rf(column...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_SoftDeletes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SoftDeletes' +type Blueprint_SoftDeletes_Call struct { + *mock.Call +} + +// SoftDeletes is a helper method to define mock.On call +// - column ...string +func (_e *Blueprint_Expecter) SoftDeletes(column ...interface{}) *Blueprint_SoftDeletes_Call { + return &Blueprint_SoftDeletes_Call{Call: _e.mock.On("SoftDeletes", + append([]interface{}{}, column...)...)} +} + +func (_c *Blueprint_SoftDeletes_Call) Run(run func(column ...string)) *Blueprint_SoftDeletes_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]string, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(string) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_SoftDeletes_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_SoftDeletes_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_SoftDeletes_Call) RunAndReturn(run func(...string) schema.ColumnDefinition) *Blueprint_SoftDeletes_Call { + _c.Call.Return(run) + return _c +} + +// SoftDeletesTz provides a mock function with given fields: column +func (_m *Blueprint) SoftDeletesTz(column ...string) schema.ColumnDefinition { + _va := make([]interface{}, len(column)) + for _i := range column { + _va[_i] = column[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for SoftDeletesTz") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(...string) schema.ColumnDefinition); ok { + r0 = rf(column...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_SoftDeletesTz_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SoftDeletesTz' +type Blueprint_SoftDeletesTz_Call struct { + *mock.Call +} + +// SoftDeletesTz is a helper method to define mock.On call +// - column ...string +func (_e *Blueprint_Expecter) SoftDeletesTz(column ...interface{}) *Blueprint_SoftDeletesTz_Call { + return &Blueprint_SoftDeletesTz_Call{Call: _e.mock.On("SoftDeletesTz", + append([]interface{}{}, column...)...)} +} + +func (_c *Blueprint_SoftDeletesTz_Call) Run(run func(column ...string)) *Blueprint_SoftDeletesTz_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]string, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(string) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_SoftDeletesTz_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_SoftDeletesTz_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_SoftDeletesTz_Call) RunAndReturn(run func(...string) schema.ColumnDefinition) *Blueprint_SoftDeletesTz_Call { + _c.Call.Return(run) + return _c +} + // String provides a mock function with given fields: column, length func (_m *Blueprint) String(column string, length ...int) schema.ColumnDefinition { _va := make([]interface{}, len(length)) @@ -1585,6 +1881,350 @@ func (_c *Blueprint_Text_Call) RunAndReturn(run func(string) schema.ColumnDefini return _c } +// Time provides a mock function with given fields: column, precision +func (_m *Blueprint) Time(column string, precision ...int) schema.ColumnDefinition { + _va := make([]interface{}, len(precision)) + for _i := range precision { + _va[_i] = precision[_i] + } + var _ca []interface{} + _ca = append(_ca, column) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Time") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string, ...int) schema.ColumnDefinition); ok { + r0 = rf(column, precision...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_Time_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Time' +type Blueprint_Time_Call struct { + *mock.Call +} + +// Time is a helper method to define mock.On call +// - column string +// - precision ...int +func (_e *Blueprint_Expecter) Time(column interface{}, precision ...interface{}) *Blueprint_Time_Call { + return &Blueprint_Time_Call{Call: _e.mock.On("Time", + append([]interface{}{column}, precision...)...)} +} + +func (_c *Blueprint_Time_Call) Run(run func(column string, precision ...int)) *Blueprint_Time_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_Time_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_Time_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_Time_Call) RunAndReturn(run func(string, ...int) schema.ColumnDefinition) *Blueprint_Time_Call { + _c.Call.Return(run) + return _c +} + +// TimeTz provides a mock function with given fields: column, precision +func (_m *Blueprint) TimeTz(column string, precision ...int) schema.ColumnDefinition { + _va := make([]interface{}, len(precision)) + for _i := range precision { + _va[_i] = precision[_i] + } + var _ca []interface{} + _ca = append(_ca, column) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for TimeTz") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string, ...int) schema.ColumnDefinition); ok { + r0 = rf(column, precision...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_TimeTz_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TimeTz' +type Blueprint_TimeTz_Call struct { + *mock.Call +} + +// TimeTz is a helper method to define mock.On call +// - column string +// - precision ...int +func (_e *Blueprint_Expecter) TimeTz(column interface{}, precision ...interface{}) *Blueprint_TimeTz_Call { + return &Blueprint_TimeTz_Call{Call: _e.mock.On("TimeTz", + append([]interface{}{column}, precision...)...)} +} + +func (_c *Blueprint_TimeTz_Call) Run(run func(column string, precision ...int)) *Blueprint_TimeTz_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_TimeTz_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_TimeTz_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_TimeTz_Call) RunAndReturn(run func(string, ...int) schema.ColumnDefinition) *Blueprint_TimeTz_Call { + _c.Call.Return(run) + return _c +} + +// Timestamp provides a mock function with given fields: column, precision +func (_m *Blueprint) Timestamp(column string, precision ...int) schema.ColumnDefinition { + _va := make([]interface{}, len(precision)) + for _i := range precision { + _va[_i] = precision[_i] + } + var _ca []interface{} + _ca = append(_ca, column) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Timestamp") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string, ...int) schema.ColumnDefinition); ok { + r0 = rf(column, precision...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_Timestamp_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Timestamp' +type Blueprint_Timestamp_Call struct { + *mock.Call +} + +// Timestamp is a helper method to define mock.On call +// - column string +// - precision ...int +func (_e *Blueprint_Expecter) Timestamp(column interface{}, precision ...interface{}) *Blueprint_Timestamp_Call { + return &Blueprint_Timestamp_Call{Call: _e.mock.On("Timestamp", + append([]interface{}{column}, precision...)...)} +} + +func (_c *Blueprint_Timestamp_Call) Run(run func(column string, precision ...int)) *Blueprint_Timestamp_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_Timestamp_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_Timestamp_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_Timestamp_Call) RunAndReturn(run func(string, ...int) schema.ColumnDefinition) *Blueprint_Timestamp_Call { + _c.Call.Return(run) + return _c +} + +// TimestampTz provides a mock function with given fields: column, precision +func (_m *Blueprint) TimestampTz(column string, precision ...int) schema.ColumnDefinition { + _va := make([]interface{}, len(precision)) + for _i := range precision { + _va[_i] = precision[_i] + } + var _ca []interface{} + _ca = append(_ca, column) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for TimestampTz") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(string, ...int) schema.ColumnDefinition); ok { + r0 = rf(column, precision...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// Blueprint_TimestampTz_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TimestampTz' +type Blueprint_TimestampTz_Call struct { + *mock.Call +} + +// TimestampTz is a helper method to define mock.On call +// - column string +// - precision ...int +func (_e *Blueprint_Expecter) TimestampTz(column interface{}, precision ...interface{}) *Blueprint_TimestampTz_Call { + return &Blueprint_TimestampTz_Call{Call: _e.mock.On("TimestampTz", + append([]interface{}{column}, precision...)...)} +} + +func (_c *Blueprint_TimestampTz_Call) Run(run func(column string, precision ...int)) *Blueprint_TimestampTz_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_TimestampTz_Call) Return(_a0 schema.ColumnDefinition) *Blueprint_TimestampTz_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Blueprint_TimestampTz_Call) RunAndReturn(run func(string, ...int) schema.ColumnDefinition) *Blueprint_TimestampTz_Call { + _c.Call.Return(run) + return _c +} + +// Timestamps provides a mock function with given fields: precision +func (_m *Blueprint) Timestamps(precision ...int) { + _va := make([]interface{}, len(precision)) + for _i := range precision { + _va[_i] = precision[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + _m.Called(_ca...) +} + +// Blueprint_Timestamps_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Timestamps' +type Blueprint_Timestamps_Call struct { + *mock.Call +} + +// Timestamps is a helper method to define mock.On call +// - precision ...int +func (_e *Blueprint_Expecter) Timestamps(precision ...interface{}) *Blueprint_Timestamps_Call { + return &Blueprint_Timestamps_Call{Call: _e.mock.On("Timestamps", + append([]interface{}{}, precision...)...)} +} + +func (_c *Blueprint_Timestamps_Call) Run(run func(precision ...int)) *Blueprint_Timestamps_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_Timestamps_Call) Return() *Blueprint_Timestamps_Call { + _c.Call.Return() + return _c +} + +func (_c *Blueprint_Timestamps_Call) RunAndReturn(run func(...int)) *Blueprint_Timestamps_Call { + _c.Call.Return(run) + return _c +} + +// TimestampsTz provides a mock function with given fields: precision +func (_m *Blueprint) TimestampsTz(precision ...int) { + _va := make([]interface{}, len(precision)) + for _i := range precision { + _va[_i] = precision[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + _m.Called(_ca...) +} + +// Blueprint_TimestampsTz_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TimestampsTz' +type Blueprint_TimestampsTz_Call struct { + *mock.Call +} + +// TimestampsTz is a helper method to define mock.On call +// - precision ...int +func (_e *Blueprint_Expecter) TimestampsTz(precision ...interface{}) *Blueprint_TimestampsTz_Call { + return &Blueprint_TimestampsTz_Call{Call: _e.mock.On("TimestampsTz", + append([]interface{}{}, precision...)...)} +} + +func (_c *Blueprint_TimestampsTz_Call) Run(run func(precision ...int)) *Blueprint_TimestampsTz_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Blueprint_TimestampsTz_Call) Return() *Blueprint_TimestampsTz_Call { + _c.Call.Return() + return _c +} + +func (_c *Blueprint_TimestampsTz_Call) RunAndReturn(run func(...int)) *Blueprint_TimestampsTz_Call { + _c.Call.Return(run) + return _c +} + // TinyIncrements provides a mock function with given fields: column func (_m *Blueprint) TinyIncrements(column string) schema.ColumnDefinition { ret := _m.Called(column) diff --git a/mocks/database/schema/ColumnDefinition.go b/mocks/database/schema/ColumnDefinition.go index 653dc650c..c434babf7 100644 --- a/mocks/database/schema/ColumnDefinition.go +++ b/mocks/database/schema/ColumnDefinition.go @@ -115,6 +115,54 @@ func (_c *ColumnDefinition_Comment_Call) RunAndReturn(run func(string) schema.Co return _c } +// Default provides a mock function with given fields: def +func (_m *ColumnDefinition) Default(def any) schema.ColumnDefinition { + ret := _m.Called(def) + + if len(ret) == 0 { + panic("no return value specified for Default") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(any) schema.ColumnDefinition); ok { + r0 = rf(def) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// ColumnDefinition_Default_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Default' +type ColumnDefinition_Default_Call struct { + *mock.Call +} + +// Default is a helper method to define mock.On call +// - def any +func (_e *ColumnDefinition_Expecter) Default(def interface{}) *ColumnDefinition_Default_Call { + return &ColumnDefinition_Default_Call{Call: _e.mock.On("Default", def)} +} + +func (_c *ColumnDefinition_Default_Call) Run(run func(def any)) *ColumnDefinition_Default_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(any)) + }) + return _c +} + +func (_c *ColumnDefinition_Default_Call) Return(_a0 schema.ColumnDefinition) *ColumnDefinition_Default_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_Default_Call) RunAndReturn(run func(any) schema.ColumnDefinition) *ColumnDefinition_Default_Call { + _c.Call.Return(run) + return _c +} + // GetAllowed provides a mock function with given fields: func (_m *ColumnDefinition) GetAllowed() []string { ret := _m.Called() @@ -434,6 +482,53 @@ func (_c *ColumnDefinition_GetNullable_Call) RunAndReturn(run func() bool) *Colu return _c } +// GetOnUpdate provides a mock function with given fields: +func (_m *ColumnDefinition) GetOnUpdate() any { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetOnUpdate") + } + + var r0 any + if rf, ok := ret.Get(0).(func() any); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(any) + } + } + + return r0 +} + +// ColumnDefinition_GetOnUpdate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetOnUpdate' +type ColumnDefinition_GetOnUpdate_Call struct { + *mock.Call +} + +// GetOnUpdate is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) GetOnUpdate() *ColumnDefinition_GetOnUpdate_Call { + return &ColumnDefinition_GetOnUpdate_Call{Call: _e.mock.On("GetOnUpdate")} +} + +func (_c *ColumnDefinition_GetOnUpdate_Call) Run(run func()) *ColumnDefinition_GetOnUpdate_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_GetOnUpdate_Call) Return(_a0 any) *ColumnDefinition_GetOnUpdate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_GetOnUpdate_Call) RunAndReturn(run func() any) *ColumnDefinition_GetOnUpdate_Call { + _c.Call.Return(run) + return _c +} + // GetPlaces provides a mock function with given fields: func (_m *ColumnDefinition) GetPlaces() int { ret := _m.Called() @@ -614,6 +709,96 @@ func (_c *ColumnDefinition_GetType_Call) RunAndReturn(run func() string) *Column return _c } +// GetUseCurrent provides a mock function with given fields: +func (_m *ColumnDefinition) GetUseCurrent() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetUseCurrent") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// ColumnDefinition_GetUseCurrent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUseCurrent' +type ColumnDefinition_GetUseCurrent_Call struct { + *mock.Call +} + +// GetUseCurrent is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) GetUseCurrent() *ColumnDefinition_GetUseCurrent_Call { + return &ColumnDefinition_GetUseCurrent_Call{Call: _e.mock.On("GetUseCurrent")} +} + +func (_c *ColumnDefinition_GetUseCurrent_Call) Run(run func()) *ColumnDefinition_GetUseCurrent_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_GetUseCurrent_Call) Return(_a0 bool) *ColumnDefinition_GetUseCurrent_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_GetUseCurrent_Call) RunAndReturn(run func() bool) *ColumnDefinition_GetUseCurrent_Call { + _c.Call.Return(run) + return _c +} + +// GetUseCurrentOnUpdate provides a mock function with given fields: +func (_m *ColumnDefinition) GetUseCurrentOnUpdate() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetUseCurrentOnUpdate") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// ColumnDefinition_GetUseCurrentOnUpdate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUseCurrentOnUpdate' +type ColumnDefinition_GetUseCurrentOnUpdate_Call struct { + *mock.Call +} + +// GetUseCurrentOnUpdate is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) GetUseCurrentOnUpdate() *ColumnDefinition_GetUseCurrentOnUpdate_Call { + return &ColumnDefinition_GetUseCurrentOnUpdate_Call{Call: _e.mock.On("GetUseCurrentOnUpdate")} +} + +func (_c *ColumnDefinition_GetUseCurrentOnUpdate_Call) Run(run func()) *ColumnDefinition_GetUseCurrentOnUpdate_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_GetUseCurrentOnUpdate_Call) Return(_a0 bool) *ColumnDefinition_GetUseCurrentOnUpdate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_GetUseCurrentOnUpdate_Call) RunAndReturn(run func() bool) *ColumnDefinition_GetUseCurrentOnUpdate_Call { + _c.Call.Return(run) + return _c +} + // IsSetComment provides a mock function with given fields: func (_m *ColumnDefinition) IsSetComment() bool { ret := _m.Called() @@ -706,6 +891,54 @@ func (_c *ColumnDefinition_Nullable_Call) RunAndReturn(run func() schema.ColumnD return _c } +// OnUpdate provides a mock function with given fields: value +func (_m *ColumnDefinition) OnUpdate(value any) schema.ColumnDefinition { + ret := _m.Called(value) + + if len(ret) == 0 { + panic("no return value specified for OnUpdate") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func(any) schema.ColumnDefinition); ok { + r0 = rf(value) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// ColumnDefinition_OnUpdate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OnUpdate' +type ColumnDefinition_OnUpdate_Call struct { + *mock.Call +} + +// OnUpdate is a helper method to define mock.On call +// - value any +func (_e *ColumnDefinition_Expecter) OnUpdate(value interface{}) *ColumnDefinition_OnUpdate_Call { + return &ColumnDefinition_OnUpdate_Call{Call: _e.mock.On("OnUpdate", value)} +} + +func (_c *ColumnDefinition_OnUpdate_Call) Run(run func(value any)) *ColumnDefinition_OnUpdate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(any)) + }) + return _c +} + +func (_c *ColumnDefinition_OnUpdate_Call) Return(_a0 schema.ColumnDefinition) *ColumnDefinition_OnUpdate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_OnUpdate_Call) RunAndReturn(run func(any) schema.ColumnDefinition) *ColumnDefinition_OnUpdate_Call { + _c.Call.Return(run) + return _c +} + // Places provides a mock function with given fields: places func (_m *ColumnDefinition) Places(places int) schema.ColumnDefinition { ret := _m.Called(places) @@ -849,6 +1082,100 @@ func (_c *ColumnDefinition_Unsigned_Call) RunAndReturn(run func() schema.ColumnD return _c } +// UseCurrent provides a mock function with given fields: +func (_m *ColumnDefinition) UseCurrent() schema.ColumnDefinition { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for UseCurrent") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func() schema.ColumnDefinition); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// ColumnDefinition_UseCurrent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UseCurrent' +type ColumnDefinition_UseCurrent_Call struct { + *mock.Call +} + +// UseCurrent is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) UseCurrent() *ColumnDefinition_UseCurrent_Call { + return &ColumnDefinition_UseCurrent_Call{Call: _e.mock.On("UseCurrent")} +} + +func (_c *ColumnDefinition_UseCurrent_Call) Run(run func()) *ColumnDefinition_UseCurrent_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_UseCurrent_Call) Return(_a0 schema.ColumnDefinition) *ColumnDefinition_UseCurrent_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_UseCurrent_Call) RunAndReturn(run func() schema.ColumnDefinition) *ColumnDefinition_UseCurrent_Call { + _c.Call.Return(run) + return _c +} + +// UseCurrentOnUpdate provides a mock function with given fields: +func (_m *ColumnDefinition) UseCurrentOnUpdate() schema.ColumnDefinition { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for UseCurrentOnUpdate") + } + + var r0 schema.ColumnDefinition + if rf, ok := ret.Get(0).(func() schema.ColumnDefinition); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(schema.ColumnDefinition) + } + } + + return r0 +} + +// ColumnDefinition_UseCurrentOnUpdate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UseCurrentOnUpdate' +type ColumnDefinition_UseCurrentOnUpdate_Call struct { + *mock.Call +} + +// UseCurrentOnUpdate is a helper method to define mock.On call +func (_e *ColumnDefinition_Expecter) UseCurrentOnUpdate() *ColumnDefinition_UseCurrentOnUpdate_Call { + return &ColumnDefinition_UseCurrentOnUpdate_Call{Call: _e.mock.On("UseCurrentOnUpdate")} +} + +func (_c *ColumnDefinition_UseCurrentOnUpdate_Call) Run(run func()) *ColumnDefinition_UseCurrentOnUpdate_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ColumnDefinition_UseCurrentOnUpdate_Call) Return(_a0 schema.ColumnDefinition) *ColumnDefinition_UseCurrentOnUpdate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ColumnDefinition_UseCurrentOnUpdate_Call) RunAndReturn(run func() schema.ColumnDefinition) *ColumnDefinition_UseCurrentOnUpdate_Call { + _c.Call.Return(run) + return _c +} + // NewColumnDefinition creates a new instance of ColumnDefinition. 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 NewColumnDefinition(t interface { diff --git a/mocks/database/schema/Grammar.go b/mocks/database/schema/Grammar.go index 2bb626a7e..e51d79926 100644 --- a/mocks/database/schema/Grammar.go +++ b/mocks/database/schema/Grammar.go @@ -901,6 +901,144 @@ func (_c *Grammar_TypeChar_Call) RunAndReturn(run func(schema.ColumnDefinition) return _c } +// TypeDate provides a mock function with given fields: column +func (_m *Grammar) TypeDate(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeDate") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeDate' +type Grammar_TypeDate_Call struct { + *mock.Call +} + +// TypeDate is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeDate(column interface{}) *Grammar_TypeDate_Call { + return &Grammar_TypeDate_Call{Call: _e.mock.On("TypeDate", column)} +} + +func (_c *Grammar_TypeDate_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeDate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeDate_Call) Return(_a0 string) *Grammar_TypeDate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeDate_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeDate_Call { + _c.Call.Return(run) + return _c +} + +// TypeDateTime provides a mock function with given fields: column +func (_m *Grammar) TypeDateTime(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeDateTime") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeDateTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeDateTime' +type Grammar_TypeDateTime_Call struct { + *mock.Call +} + +// TypeDateTime is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeDateTime(column interface{}) *Grammar_TypeDateTime_Call { + return &Grammar_TypeDateTime_Call{Call: _e.mock.On("TypeDateTime", column)} +} + +func (_c *Grammar_TypeDateTime_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeDateTime_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeDateTime_Call) Return(_a0 string) *Grammar_TypeDateTime_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeDateTime_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeDateTime_Call { + _c.Call.Return(run) + return _c +} + +// TypeDateTimeTz provides a mock function with given fields: column +func (_m *Grammar) TypeDateTimeTz(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeDateTimeTz") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeDateTimeTz_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeDateTimeTz' +type Grammar_TypeDateTimeTz_Call struct { + *mock.Call +} + +// TypeDateTimeTz is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeDateTimeTz(column interface{}) *Grammar_TypeDateTimeTz_Call { + return &Grammar_TypeDateTimeTz_Call{Call: _e.mock.On("TypeDateTimeTz", column)} +} + +func (_c *Grammar_TypeDateTimeTz_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeDateTimeTz_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeDateTimeTz_Call) Return(_a0 string) *Grammar_TypeDateTimeTz_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeDateTimeTz_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeDateTimeTz_Call { + _c.Call.Return(run) + return _c +} + // TypeDecimal provides a mock function with given fields: column func (_m *Grammar) TypeDecimal(column schema.ColumnDefinition) string { ret := _m.Called(column) @@ -1499,6 +1637,190 @@ func (_c *Grammar_TypeText_Call) RunAndReturn(run func(schema.ColumnDefinition) return _c } +// TypeTime provides a mock function with given fields: column +func (_m *Grammar) TypeTime(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeTime") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeTime' +type Grammar_TypeTime_Call struct { + *mock.Call +} + +// TypeTime is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeTime(column interface{}) *Grammar_TypeTime_Call { + return &Grammar_TypeTime_Call{Call: _e.mock.On("TypeTime", column)} +} + +func (_c *Grammar_TypeTime_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeTime_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeTime_Call) Return(_a0 string) *Grammar_TypeTime_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeTime_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeTime_Call { + _c.Call.Return(run) + return _c +} + +// TypeTimeTz provides a mock function with given fields: column +func (_m *Grammar) TypeTimeTz(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeTimeTz") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeTimeTz_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeTimeTz' +type Grammar_TypeTimeTz_Call struct { + *mock.Call +} + +// TypeTimeTz is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeTimeTz(column interface{}) *Grammar_TypeTimeTz_Call { + return &Grammar_TypeTimeTz_Call{Call: _e.mock.On("TypeTimeTz", column)} +} + +func (_c *Grammar_TypeTimeTz_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeTimeTz_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeTimeTz_Call) Return(_a0 string) *Grammar_TypeTimeTz_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeTimeTz_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeTimeTz_Call { + _c.Call.Return(run) + return _c +} + +// TypeTimestamp provides a mock function with given fields: column +func (_m *Grammar) TypeTimestamp(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeTimestamp") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeTimestamp_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeTimestamp' +type Grammar_TypeTimestamp_Call struct { + *mock.Call +} + +// TypeTimestamp is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeTimestamp(column interface{}) *Grammar_TypeTimestamp_Call { + return &Grammar_TypeTimestamp_Call{Call: _e.mock.On("TypeTimestamp", column)} +} + +func (_c *Grammar_TypeTimestamp_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeTimestamp_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeTimestamp_Call) Return(_a0 string) *Grammar_TypeTimestamp_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeTimestamp_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeTimestamp_Call { + _c.Call.Return(run) + return _c +} + +// TypeTimestampTz provides a mock function with given fields: column +func (_m *Grammar) TypeTimestampTz(column schema.ColumnDefinition) string { + ret := _m.Called(column) + + if len(ret) == 0 { + panic("no return value specified for TypeTimestampTz") + } + + var r0 string + if rf, ok := ret.Get(0).(func(schema.ColumnDefinition) string); ok { + r0 = rf(column) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Grammar_TypeTimestampTz_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeTimestampTz' +type Grammar_TypeTimestampTz_Call struct { + *mock.Call +} + +// TypeTimestampTz is a helper method to define mock.On call +// - column schema.ColumnDefinition +func (_e *Grammar_Expecter) TypeTimestampTz(column interface{}) *Grammar_TypeTimestampTz_Call { + return &Grammar_TypeTimestampTz_Call{Call: _e.mock.On("TypeTimestampTz", column)} +} + +func (_c *Grammar_TypeTimestampTz_Call) Run(run func(column schema.ColumnDefinition)) *Grammar_TypeTimestampTz_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(schema.ColumnDefinition)) + }) + return _c +} + +func (_c *Grammar_TypeTimestampTz_Call) Return(_a0 string) *Grammar_TypeTimestampTz_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Grammar_TypeTimestampTz_Call) RunAndReturn(run func(schema.ColumnDefinition) string) *Grammar_TypeTimestampTz_Call { + _c.Call.Return(run) + return _c +} + // TypeTinyInteger provides a mock function with given fields: column func (_m *Grammar) TypeTinyInteger(column schema.ColumnDefinition) string { ret := _m.Called(column) diff --git a/support/carbon/carbon.go b/support/carbon/carbon.go index f51c2b58f..56f3428b6 100644 --- a/support/carbon/carbon.go +++ b/support/carbon/carbon.go @@ -33,6 +33,7 @@ func IsTestNow() bool { // 设置时区 func SetTimezone(timezone string) { clock.timezone = timezone + carbon.SetDefault(carbon.Default{Timezone: timezone}) } // Now return a Carbon object of now. @@ -141,7 +142,7 @@ func FromTimeNano(hour int, minute int, second int, nanosecond int, timezone ... // FromStdTime return a Carbon object of given time.Time object. func FromStdTime(time stdtime.Time) Carbon { - return carbon.CreateFromStdTime(time) + return carbon.CreateFromStdTime(time, getTimezone(nil)) } func getTimezone(timezone []string) string {