Updated on 2024-08-02 GMT+08:00

Creating a Schema

Function

This API is used to create a schema.

Constraints

Before creating a schema, ensure that you have associated RDS instances with your DDM instance and that the RDS instances are not associated with other DDM instances.

URI

POST /v1/{project_id}/instances/{instance_id}/databases

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID of a tenant in a region

To obtain this value, see Obtaining a Project ID.

instance_id

Yes

String

DDM instance ID

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token

You can obtain the token by calling the IAM API used to obtain a user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

databases

Yes

Array of CreateDatabaseDetail objects

Schema information

Table 4 CreateDatabaseDetail

Parameter

Mandatory

Type

Description

name

Yes

String

Schema name, which:

  • Can include 2 to 48 characters.
  • Must start with a letter.
  • Contains only lowercase letters, digits, and underscores (_).
  • Cannot contain keywords information_schema, mysql, performance_schema, or sys.

Minimum length: 2 characters

Maximum length: 48 characters

shard_mode

Yes

String

Sharding mode of the schema. The value can be:

  • cluster: indicates that the schema is in sharded mode.
  • single: indicates that the schema is in unsharded mode.

Enumerated values:

  • cluster
  • single

shard_number

Yes

Integer

Number of shards in the same working mode

  • If shard_unit is not empty, the value is the product of shard_unit multiplied by the associated RDS instances.
  • If shard_unit is left blank, the value must be greater than the number of associated RDS instances and less than or equal to the product of the associated RDS instances multiplied by 64.

shard_unit

No

Integer

Number of shards per RDS instance This parameter is optional.

  • The value is 1 if the schema is unsharded.
  • The value ranges from 1 to 64 if the schema is sharded.

Minimum value: 1

Maximum value: 64

used_rds

Yes

Array of DatabaseInstabcesParam objects

RDS instances associated with the schema

Table 5 DatabaseInstabcesParam

Parameter

Mandatory

Type

Description

id

Yes

String

ID of the RDS instance associated with the schema

adminUser

Yes

String

Username for logging in to the associated RDS instance

adminPassword

Yes

String

Password for logging in to the associated RDS instance

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

databases

Array of CreateDatabaseDetailResponses objects

Schema information

Table 7 CreateDatabaseDetailResponses

Parameter

Type

Description

name

String

Schema name

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

errCode

String

Service error code

externalMessage

String

Error message

Status code: 500

Table 9 Response body parameters

Parameter

Type

Description

errCode

String

Service error code

externalMessage

String

Error message

Example Request

Creating a schema and associating it with an existing DDM account

POST https://{endpoint}/v1/{project_id}/instances/{instance_id}/databases

{
  "databases" : [ {
    "name" : "mytestdb",
    "shard_mode" : "cluster",
    "shard_number" : 8,
    "shard_unit" : 8,
    "used_rds" : [ {
      "id" : "f296c394f13f48449d715bf99af07e59in01",
      "adminUser" : "root",
      "adminPassword" : "xxxxxx"
    } ]
  } ]
}

Example Response

Status code: 200

OK

{
  "databases" : [ {
    "name" : "mytestdb"
  } ]
}

Status code: 400

bad request

{
  "externalMessage" : "Parameter error.",
  "errCode" : "DBS.280001"
}

Status code: 500

server error

{
  "externalMessage" : "Server failure.",
  "errCode" : "DBS.200412"
}

Status Codes

Status Code

Description

200

OK

400

bad request

500

server error

Error Codes

For details, see Error Codes.