Database Design Document

{{config | get(key="title", default="") }}

{% if group_list | length == 1 -%} {% if config.groups | length > 1 -%}

{{group_list.0.group_def.title}}

{% endif -%} {% endif -%}

{{date | date(format="%x", locale=locale)}}

{% if history | length > 0 -%}
{% for row in history -%} {% set description = row.description | history_description( AddTable='Add a table: {T}', DropTable='Drop a table: {T}', AddColumn='Add a column: {T} ({C})', AddColumn_Plural='Add columns: {T} ({C})', ChangeColumn='Change a column: {T} ({C})', ChangeColumn_Plural='Change columns: {T} ({C})', DropColumn='Drop a column: {T} ({C})', DropColumn_Plural='Drop columns: {T} ({C})', ChangePrimary='Change the primary key: {T}', DropPrimary='Drop the primary key: {T}', AddIndex='Add an index: {T} ({C})', AddIndex_Plural='Add indexes: {T} ({C})', ChangeIndex='Change an index: {T} ({C})', ChangeIndex_Plural='Change indexes: {T} ({C})', DropIndex='Drop an index: {T} ({C})', DropIndex_Plural='Drop indexes: {T} ({C})', AddForeign='Add a foreign key: {T} ({C})', AddForeign_Plural='Add foreign keys: {T} ({C})', ChangeForeign='Change a foreign key: {T} ({C})', ChangeForeign_Plural='Change foreign keys: {T} ({C})', DropForeign='Drop a foreign key: {T} ({C})', DropForeign_Plural='Drop foreign keys: {T} ({C})', ) -%} {% if description | length == 0 %}{% continue %}{% endif -%} {% endfor -%}

Revision History

Date Description
{{row.date | date(format="%x", locale=locale)}}
{{description | safe}}
{% endif -%} {% if group_list | length > 1 -%}
{% for group in group_list -%} {% endfor -%}

Model Group List

No. Name
{{loop.index}} {{group.group_def.title}}
{%- endif -%} {% for group in group_list -%}
{% if group_list | length > 1 -%}

{{group.group_def.title}}

{% endif -%} {% if group.models -%}
{% for model_name, model in group.models -%} {% endfor -%}

Table List

No. Name
{{loop.index}} {{model_name}} {%- if model.title %} ({{model.title}}){% endif %}
{% if group.er -%}

ER diagram

{{group.er | safe}}
{% endif -%}
{% endif -%} {% if group.enums -%}
{% for name, enum in group.enums -%} {% endfor -%}

Enum List

No. Name
{{loop.index}} {{name}} {%- if enum.title %} ({{enum.title}}){% endif %}
{% endif -%}
{% if group.models -%} {% for model_name, model in group.models -%}

{{loop.index}}. {{model_name}}{% if model.title %} ({{model.title}}){% endif %}

Real Table Name: {{model.table_name}}

{% if model.comment -%}
{{model.comment}}
{% endif -%}
{% for name, column in model.columns -%} {% endfor -%}
No. Name Type Null Length Key Comment
{{loop.index}} {{column | get(key="rename", default=name)}} {% if column.signed %}signed {% endif %}{{column.type}} {% if not column.not_null %}Y{% endif %} {%- if column.length %}{{column.length}}{% endif %} {%- if column.precision %}{{column.precision}}{% endif %} {%- if column.scale %},{{column.scale}}{% endif %} {% if column.primary %}P{% endif %} {%- if column.title %}

{{column.title}}

{% endif %} {%- if column.enum_values -%}

{% for enum in column.enum_values -%} {{enum.value}}:{{enum | get(key="title", default=enum.name) }} {%- if enum.comment %} ({{enum.comment}}){% endif %} {%- if not loop.last %}
{% endif %} {%- endfor %}

{%- endif -%} {%- if column.db_enum_values %}

{% for enum in column.db_enum_values -%}{{enum.name}} {%- if enum.title %}:{{enum.title}}{% endif %} {%- if enum.comment %} ({{enum.comment}}){% endif %} {%- if not loop.last %}
{% endif %} {%- endfor %}

{%- endif -%} {%- if column.enum_class %}{{column.enum_class}} {%- endif -%} {%- if column.comment %}
{{column.comment}}
{% endif -%}

All numeric types including double, decimal, etc. are unsigned unless signed is specified for the data type.

{% if model.indexes -%}
{% for name, index in model.indexes -%} {% endfor -%}

Index List

No. Type Column Name
{{loop.index}} {%- if index %}{{ index | get(key="type", default="INDEX") | upper}} {%- else %}INDEX{% endif %} {%- if index and index.fields %}{% for name, field in index.fields -%}{{name}} {%- if field and field.length %}({{field.length}}){% endif %} {%- if not loop.last %}, {% endif %} {%- endfor %}{% else %}{{name}}{% endif %}
{% endif -%} {% if model.relations -%}
{% for name, relation in model.relations -%} {% set type = relation | get(key="type", default="one") %} {% endfor -%}

Relation List

No. Name Data Type Local Column Foreign Table Foreign Column On Delete
{{loop.index}} {{relation | get(key="title", default=name)}} {% if type == "one_to_one" %}ONE{% else %}{{type | upper}}{% endif %} {%- if relation.local %}{{relation.local}}{% else %} {%- if type == "many" or type == "one_to_one" %}-{% else %}{{name}}_id{% endif %} {%- endif %} {{- relation.model | split(pat="::") | last}} {%- if relation.foreign %}{{relation.foreign}}{% else %} {%- if type == "many" %}{{model_name}}_id{% else %}-{% endif %} {% endif %} {{relation | get(key="on_delete", default="")}}

"-" in column indicates primary key. {%- if config.ignore_foreign_key %} No foreign key constraint is actually set.{% endif -%}

{% endif -%}
{% endfor -%} {% endif -%} {% if group.enums -%}
{% for name, enum in group.enums -%}

{{loop.index}}. {{name}}{% if enum.title %} ({{enum.title}}){% endif %}

{% if enum.comment -%}
{{enum.comment}}
{% endif -%} {% for value in enum.enum_values -%} {% endfor -%}
Value Name Comment
{{value.value}} {{value | get(key="title", default=value.name) }} {%- if value.comment %}
{{value.comment}}
{% endif -%}
{% endfor -%}
{% endif -%} {% endfor -%}