

# RDBMS table schema and mapping
<a name="rdbms-schema"></a>

The following diagram shows the tables and relationships in the source RDBMS schema.

 ![RDMS schema](http://docs.aws.amazon.com/prescriptive-guidance/latest/modernization-rdbms-dynamodb/images/rdbms-table.png) 

As shown in the previous diagram, the `production_apps` table has `id` and `version` columns, which have a one-to-many relationship with the `production_app_properties` and `production_app_configs` tables. Therefore, in the DynamoDB design, the `production_app_properties` and `production_app_configs` tables are embedded within the `production_app item`, as shown in the following JSON code. Because `production_app_properties` and `production_app_configs` can have multiple values, these tables are added as arrays in the JSON code. The `changed_apps` and `test_apps` tables are mapped similarly.

 ![Mapping from RDMS schema to DynamoDB](http://docs.aws.amazon.com/prescriptive-guidance/latest/modernization-rdbms-dynamodb/images/table-mapping.png) 

## Single table design
<a name="single-tables"></a>

DynamoDB doesn’t maintain relationships; it supports a fixed table schema. As a result, you can store different types of items (such as SQL tables) in a single DynamoDB table, with an attribute (`ItemType`) that identifies the type of item.

In DynamoDB, the combination of partition keys (PK) and sort keys (SK) must be unique, so these keys vary based on the item type. 

 ![Single table design in DynamoDB](http://docs.aws.amazon.com/prescriptive-guidance/latest/modernization-rdbms-dynamodb/images/single-table-design.png) 

## Global secondary indexes
<a name="gsi"></a>

Indexes help retrieve data faster and improve application performance. For the sample application, the following indexes were created. The PKs and SKs were chosen based on how distinct items could be identified.


****  

| **Index name** | **Description** | **Partition key (PK)** | **Sort key (SK)** | **Projected\_Attributes** | 
| --- | --- | --- | --- | --- | 
| Version-index | Gets all production applications for a given version. | version |  | id, name | 
| Release-index | Gets all test applications for a given release-id.  | release-id |  | id, name | 
| Change-index | Gets all (changed) applications associated with a change-id. | change-id |  | id, modified-by, date | 