Description

In this article, we're going to take the following how examples and describe them using GenRocket's DDL JSON Schema. The first example (card_product) provides a good example because it utilizes most of the features of GenRocket's DDL JSON Schema. The second is a simple multi-table example where a Parent Domain (User) has two Child Domains (Address and Account).


Example 1 - Card Product Table

Below is an ER Diagram view of the card_product table that will be described in GenRocket's DDL JSON Schama.

GenRocket DDL JSON Schema for Card Product Table

[{
    "name": "card_product",
    "columns": [
        {
            "name": "id",
            "type": {
                "datatype": "bigint",
                "maxLength": "20",
                "nullable": false,
                "format": ""
            },
            "metadata": {
                "hint": "Card Product Id",
                "observedCharacters": "",
                "maxValue": "",
                "minValue": ""
            }
        },
        {
            "name": "pin",
            "type": {
                "datatype": "int",
                "maxLength": "10",
                "nullable": true
            },
            "metadata": {
                "observedCharacters": "",
                "maxValue": "",
                "minValue": ""
            }
        },
        {
            "name": "name_on_card",
            "type": {
                "name_on_card": "varchar",
                "maxLength": "50",
                "nullable": false,
                "format": ""
            },
            "metadata": {
                "hint": "Name On Card",
                "observedCharacters": "A..Z,a..z",
                "maxValue": "",
                "minValue": ""
            }
        },
        {
            "name": "card_number",
            "type": {
                "datatype": "varchar",
                "maxLength": "16",
                "nullable": false,
                "format": ""
            },
            "metadata": {
                "hint": "Card Number",
                "observedCharacters": "123456789",
                "maxValue": "",
                "minValue": ""
            }
        },
        {
            "name": "security_code",
            "type": {
                "datatype": "int",
                "maxLength": "10",
                "nullable": false,
                "format": ""
            },
            "metadata": {
                "hint": "Security Code",
                "observedCharacters": "",
                "maxValue": "8999999999",
                "minValue": "1000000000"
            }
        },
        {
            "name": "enable",
            "type": {
                "datatype": "tinyint",
                "maxLength": "1",
                "nullable": false,
                "format": ""
            },
            "metadata": {
                "hint": "",
                "observedCharacters": "",
                "maxValue": ""
            }
        },
        {
            "name": "date_issued",
            "type": {
                "datatype": "date",
                "maxLength": "",
                "nullable": false,
                "format": "yyyy-MM-dd HH:mm:ss"
            },
            "metadata": {
                "hint": "Issued",
                "observedCharacters": "",
                "maxValue": "",
                "minValue": ""
            }
        },
        {
            "name": "date_expired",
            "type": {
                "datatype": "date",
                "maxLength": "",
                "nullable": false,
                "format": "yyyy-MM-dd HH:mm:ss"
            },
            "metadata": {
                "hint": "Expired",
                "observedCharacters": "",
                "maxValue": "",
                "minValue": ""
            }
        },
        {
            "name": "date_activated",
            "type": {
                "datatype": "date",
                "maxLength": "",
                "nullable": true,
                "format": "yyyy-MM-dd HH:mm:ss"
            },
            "metadata": {
                "hint": "Activated",
                "observedCharacters": "",
                "maxValue": "",
                "minValue": ""
            }
        },
        {
            "name": "date_deactivated",
            "type": {
                "hint": "Deactivated",
                "maxLength": "",
                "nullable": true,
                "format": "yyyy-MM-dd HH:mm:ss"
            },
            "metadata": {
                "datatype": "int",
                "observedCharacters": "",
                "maxValue": "",
                "minValue": ""
            }
        }
    ]
}]



Example 2 - Multiple Tables with Relationships

User is the parent table of the Account and Address tables.



GenRocket DDL JSON Schema for Example 2


[
  {
    "name": "user",
    "columns": [
      {
        "name": "id",
        "type": {
          "datatype": "bigint",
          "maxLength": "11",
          "nullable": false
        },
        "metadata": {
          "hint": "user Id",
          "observedCharacters": "",
          "maxValue": "100000",
          "minValue": "100"
        }
      },
      {
        "name": "first_name",
        "type": {
          "datatype": "varchar",
          "maxLength": "255",
          "nullable": false
        },
        "metadata": {
          "hint": "First Name",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "last_name",
        "type": {
          "datatype": "varchar",
          "maxLength": "255",
          "nullable": false
        },
        "metadata": {
          "hint": "Last Name",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "middle_init",
        "type": {
          "datatype": "varchar",
          "maxLength": "1",
          "nullable": false
        },
        "metadata": {
          "hint": "Middle Initial",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "date_created",
        "type": {
          "datatype": "varchar",
          "maxLength": "",
          "nullable": false,
          "format": "yyyy-MM-dd"
        },
        "metadata": {
          "hint": "Date Created",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      }
    ],
    "primaryKey": [
      {
        "column": "id"
      }
    ]
  },
  {
    "name": "address",
    "columns": [
      {
        "name": "id",
        "type": {
          "datatype": "int",
          "maxLength": "11",
          "nullable": false
        },
        "metadata": {
          "hint": "Address Id",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "city",
        "type": {
          "datatype": "varchar",
          "maxLength": "35",
          "nullable": false
        },
        "metadata": {
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "state",
        "type": {
          "datatype": "varchar",
          "maxLength": "35",
          "nullable": false
        },
        "metadata": {
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "zip",
        "type": {
          "datatype": "varchar",
          "maxLength": "35",
          "nullable": false
        },
        "metadata": {
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "user_id",
        "type": {
          "datatype": "varchar",
          "maxLength": "35",
          "nullable": false
        },
        "metadata": {
          "hint": "Foreign Key of User",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      }
    ],
    "primaryKey": [
      {
        "column": "id"
      }
    ],
    "foreignKeys": [
      {
        "column": "user_id",
        "name": "user"
      }
    ]
  },
  {
    "name": "account",
    "columns": [
      {
        "name": "id",
        "type": {
          "datatype": "int",
          "maxLength": "11",
          "nullable": false
        },
        "metadata": {
          "hint": "Account Id",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "ssn",
        "type": {
          "datatype": "varchar",
          "maxLength": "12",
          "nullable": false
        },
        "metadata": {
          "hint": "ssn",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "username",
        "type": {
          "datatype": "varchar",
          "maxLength": "50",
          "nullable": false
        },
        "metadata": {
          "hint": "Username",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "password",
        "type": {
          "datatype": "varchar",
          "maxLength": "100",
          "nullable": false
        },
        "metadata": {
          "hint": "Password",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      },
      {
        "name": "user_id",
        "type": {
          "datatype": "varchar",
          "maxLength": "35",
          "nullable": false
        },
        "metadata": {
          "hint": "Foreign Key of User",
          "observedCharacters": "",
          "maxValue": "",
          "minValue": ""
        }
      }
    ],
    "primaryKey": [
      {
        "column": "id"
      }
    ],
    "foreignKeys": [
      {
        "column": "user_id",
        "name": "user"
      }
    ]
  }
]