From da3cc8d07c3027dd78eee0048852bddb1a940d43 Mon Sep 17 00:00:00 2001 From: nakatsu-kouki Date: Wed, 12 Jun 2024 17:04:15 +0000 Subject: [PATCH] =?UTF-8?q?update=20inte=5Ftest/=E4=B8=80=E3=81=A4?= =?UTF-8?q?=E3=81=AE=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=AB=E8=A4=87?= =?UTF-8?q?=E6=95=B0=E3=81=AE=E3=83=A2=E3=83=87=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- integration_test/expected_output.md | 12 ++++++++ integration_test/helper_test.go | 5 +++- integration_test/integration_test.go | 44 ++++++++++++++++++++++++++++ integration_test/test_data/users.go | 11 +++++++ 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/integration_test/expected_output.md b/integration_test/expected_output.md index ce04834..4cf69e6 100644 --- a/integration_test/expected_output.md +++ b/integration_test/expected_output.md @@ -11,6 +11,18 @@ Stores basic information about orders | user_id | int | YES | FOREIGN KEY | [users](#users) | | | | | quantity | int | YES | | | 1 | | Quantity of the product being ordered, defaults to 1 | +## user_details + +Stores basic information about users details + +| Name | Type | Nullable | Constraints | Referenced | Default | Extra | Comment | +| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | +| user_detail_id | varchar(30) | NO | PRIMARY KEY | | | | | +| user_id | int | YES | FOREIGN KEY | [users](#users) | | | | +| name | varchar(255) | NO | | | | | | +| created_at | datetime(3) | YES | | | | | | +| updated_at | datetime(3) | YES | | | | | | + ## users Stores basic information about users diff --git a/integration_test/helper_test.go b/integration_test/helper_test.go index 2d028fd..4e5881f 100644 --- a/integration_test/helper_test.go +++ b/integration_test/helper_test.go @@ -24,11 +24,14 @@ func init() { log.Fatal(err) } - // テーブルを自動的に作成または更新する err = db.Set("gorm:table_options", "COMMENT='Stores basic information about users'").AutoMigrate(&testdata.Users{}) if err != nil { log.Fatal(err) } + err = db.Set("gorm:table_options", "COMMENT='Stores basic information about users details'").AutoMigrate(&testdata.UserDetail{}) + if err != nil { + log.Fatal(err) + } err = db.Set("gorm:table_options", "COMMENT='Stores basic information about orders'").AutoMigrate(&another_testdata.Orders{}) if err != nil { log.Fatal(err) diff --git a/integration_test/integration_test.go b/integration_test/integration_test.go index 4735ae7..e4bffd4 100644 --- a/integration_test/integration_test.go +++ b/integration_test/integration_test.go @@ -74,6 +74,28 @@ func TestIntegration(t *testing.T) { }, }, }, + { + TableName: "user_details", + Comment: "Stores basic information about users details", + Columns: []pipe.Column{ + {ColumnName: "created_at", IsNullable: "YES", ColumnType: "datetime(3)"}, + {ColumnName: "name", IsNullable: "NO", ColumnType: "varchar(255)"}, + {ColumnName: "updated_at", IsNullable: "YES", ColumnType: "datetime(3)"}, + { + ColumnName: "user_detail_id", + IsNullable: "NO", + ColumnType: "varchar(30)", + ConstraintTypes: "PRIMARY KEY", + }, + { + ColumnName: "user_id", + IsNullable: "YES", + ColumnType: "int", + ReferencedTableName: "users", + ConstraintTypes: "FOREIGN KEY", + }, + }, + }, { TableName: "users", Comment: "Stores basic information about users", @@ -158,6 +180,28 @@ func TestIntegration(t *testing.T) { }, }, }, + { + TableName: "user_details", + Comment: "Stores basic information about users details", + Columns: []pipe.Column{ + { + ColumnName: "user_detail_id", + IsNullable: "NO", + ColumnType: "varchar(30)", + ConstraintTypes: "PRIMARY KEY", + }, + { + ColumnName: "user_id", + IsNullable: "YES", + ColumnType: "int", + ReferencedTableName: "users", + ConstraintTypes: "FOREIGN KEY", + }, + {ColumnName: "name", IsNullable: "NO", ColumnType: "varchar(255)"}, + {ColumnName: "created_at", IsNullable: "YES", ColumnType: "datetime(3)"}, + {ColumnName: "updated_at", IsNullable: "YES", ColumnType: "datetime(3)"}, + }, + }, { TableName: "users", Comment: "Stores basic information about users", diff --git a/integration_test/test_data/users.go b/integration_test/test_data/users.go index 3f418d7..7481e11 100644 --- a/integration_test/test_data/users.go +++ b/integration_test/test_data/users.go @@ -1,7 +1,18 @@ package testdata +import "time" + type Users struct { ID int32 `gorm:"primaryKey;autoIncrement;"` Name string `gorm:"size:255;not null;"` Email string `gorm:"size:255;not null;unique;"` } + +type UserDetail struct { + UserDetailID string `gorm:"primaryKey;size:30;not null"` + UserID int32 // 外部キー + User Users `gorm:"foreignKey:UserID"` // Usersとの関連 + Name string `gorm:"size:255;not null"` + CreatedAt time.Time + UpdatedAt time.Time +}