From e8208746ae49060204acd33a4ce626bde9160401 Mon Sep 17 00:00:00 2001 From: shi yuhang <52435083+shiyuhang0@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:27:54 +0800 Subject: [PATCH] Change import target_table schema to database (#59) * change import target_table schema to database --- docs/resources/import.md | 2 +- internal/provider/import_resource.go | 16 +++++++++++----- internal/provider/import_resource_test.go | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/resources/import.md b/docs/resources/import.md index 0883262..23ea8cc 100644 --- a/docs/resources/import.md +++ b/docs/resources/import.md @@ -110,7 +110,7 @@ Optional: Optional: -- `schema` (String) The schema of your cluster. +- `database` (String) The database of your cluster. - `table` (String) The table of your cluster. diff --git a/internal/provider/import_resource.go b/internal/provider/import_resource.go index f2d123d..8e3bdc7 100644 --- a/internal/provider/import_resource.go +++ b/internal/provider/import_resource.go @@ -91,8 +91,8 @@ type ImportCustomCSVFormat struct { } type ImportTargetTable struct { - // schema - Schema types.String `tfsdk:"schema"` + // database + Database types.String `tfsdk:"database"` // table Table types.String `tfsdk:"table"` } @@ -183,8 +183,8 @@ func (r *ImportResource) Schema(ctx context.Context, req resource.SchemaRequest, MarkdownDescription: "The target db and table to import data, used for importing from LOCAL", Optional: true, Attributes: map[string]schema.Attribute{ - "schema": schema.StringAttribute{ - MarkdownDescription: "The schema of your cluster.", + "database": schema.StringAttribute{ + MarkdownDescription: "The database of your cluster.", Optional: true, }, "table": schema.StringAttribute{ @@ -410,8 +410,14 @@ func buildCreateImportBody(data *ImportResourceModel) (*importService.CreateImpo if data.TargetTable == nil { return nil, errors.New("TargetTable can not be empty in Local type") } + if data.TargetTable.Database.IsNull() || data.TargetTable.Database.IsUnknown() { + return nil, errors.New("TargetTable's Database can not be empty in Local type") + } + if data.TargetTable.Table.IsNull() || data.TargetTable.Table.IsUnknown() { + return nil, errors.New("TargetTable's Table can not be empty in Local type") + } body.TargetTable = &importModel.OpenapiTable{ - Schema: data.TargetTable.Schema.ValueString(), + Schema: data.TargetTable.Database.ValueString(), Table: data.TargetTable.Table.ValueString(), } } else { diff --git a/internal/provider/import_resource_test.go b/internal/provider/import_resource_test.go index 1fbe74b..1ad77f8 100644 --- a/internal/provider/import_resource_test.go +++ b/internal/provider/import_resource_test.go @@ -119,7 +119,7 @@ func TestUTImportResourceLOCAL(t *testing.T) { "aws_role_arn": "", "file_name": "fake.csv", "target_table": { - "schema": "test", + "database": "test", "table": "r" } }}`, clusterId, importId, os.Getenv(TiDBCloudProjectID), clusterId))) @@ -155,7 +155,7 @@ func TestUTImportResourceLOCAL(t *testing.T) { type = "LOCAL" data_format = "CSV" target_table = { - schema = "test" + database = "test" table = "r" } file_name = "fake.csv"