Skip to content

Commit

Permalink
Change import target_table schema to database (#59)
Browse files Browse the repository at this point in the history
* change import target_table schema to database
  • Loading branch information
shiyuhang0 authored Feb 16, 2023
1 parent babbe7a commit e820874
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/resources/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
16 changes: 11 additions & 5 deletions internal/provider/import_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/import_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit e820874

Please sign in to comment.