# ER図（Entity-Relationship Diagram）

本ドキュメントは、Shopware 6のデータベース構造をER図形式で表現したものです。

## 全体構成図

以下のER図は、主要なエンティティ間の関係を示しています。

```mermaid
erDiagram
    %% Core System Entities
    USER ||--o{ MEDIA : uploads
    USER ||--o{ ORDER : creates
    USER ||--o| USER_RECOVERY : has
    USER }o--|| LOCALE : uses

    %% Sales Channel Relations
    SALES_CHANNEL ||--o{ ORDER : receives
    SALES_CHANNEL ||--o{ CUSTOMER : has
    SALES_CHANNEL }o--|| LANGUAGE : "default"
    SALES_CHANNEL }o--|| CURRENCY : "default"
    SALES_CHANNEL }o--|| COUNTRY : "default"
    SALES_CHANNEL }o--|| PAYMENT_METHOD : "default"
    SALES_CHANNEL }o--|| SHIPPING_METHOD : "default"
    SALES_CHANNEL }o--|| CUSTOMER_GROUP : "default"
    SALES_CHANNEL }o--|| CATEGORY : "navigation"
    SALES_CHANNEL ||--o{ SALES_CHANNEL_DOMAIN : has

    %% Product Relations
    PRODUCT ||--o{ PRODUCT : "parent-child"
    PRODUCT }o--|| TAX : uses
    PRODUCT }o--o| PRODUCT_MANUFACTURER : "made by"
    PRODUCT }o--o| UNIT : "measured in"
    PRODUCT }o--o| DELIVERY_TIME : "delivered in"
    PRODUCT ||--o{ PRODUCT_MEDIA : has
    PRODUCT ||--o{ PRODUCT_PRICE : has
    PRODUCT ||--o{ PRODUCT_REVIEW : receives
    PRODUCT }o--o{ CATEGORY : "belongs to"
    PRODUCT }o--o{ TAG : tagged
    PRODUCT }o--o{ PROPERTY_GROUP_OPTION : "has options"
    PRODUCT }o--o{ PROPERTY_GROUP_OPTION : "has properties"

    %% Category Relations
    CATEGORY ||--o{ CATEGORY : "parent-child"
    CATEGORY }o--o| MEDIA : displays
    CATEGORY }o--o| CMS_PAGE : uses
    CATEGORY }o--o{ TAG : tagged

    %% Customer Relations
    CUSTOMER ||--o{ CUSTOMER_ADDRESS : has
    CUSTOMER ||--o{ ORDER : places
    CUSTOMER }o--|| CUSTOMER_GROUP : "belongs to"
    CUSTOMER }o--|| SALES_CHANNEL : "registered in"
    CUSTOMER }o--|| LANGUAGE : uses
    CUSTOMER }o--o| SALUTATION : uses
    CUSTOMER ||--o{ PRODUCT_REVIEW : writes
    CUSTOMER ||--o{ CUSTOMER_WISHLIST : has
    CUSTOMER }o--o{ TAG : tagged

    %% Order Relations
    ORDER ||--|{ ORDER_LINE_ITEM : contains
    ORDER ||--o{ ORDER_DELIVERY : "delivered via"
    ORDER ||--o{ ORDER_TRANSACTION : "paid via"
    ORDER ||--|| ORDER_CUSTOMER : "placed by"
    ORDER ||--o{ ORDER_ADDRESS : has
    ORDER }o--|| CURRENCY : uses
    ORDER }o--|| LANGUAGE : uses
    ORDER }o--|| STATE_MACHINE_STATE : "has state"
    ORDER }o--o{ TAG : tagged

    %% Order Line Item Relations
    ORDER_LINE_ITEM }o--o| PRODUCT : references
    ORDER_LINE_ITEM }o--o| MEDIA : "has cover"

    %% Order Delivery Relations
    ORDER_DELIVERY }o--|| SHIPPING_METHOD : uses
    ORDER_DELIVERY }o--|| ORDER_ADDRESS : "ships to"
    ORDER_DELIVERY ||--o{ ORDER_DELIVERY_POSITION : contains
    ORDER_DELIVERY }o--|| STATE_MACHINE_STATE : "has state"

    %% Order Transaction Relations
    ORDER_TRANSACTION }o--|| PAYMENT_METHOD : uses
    ORDER_TRANSACTION }o--|| STATE_MACHINE_STATE : "has state"
    ORDER_TRANSACTION ||--o{ ORDER_TRANSACTION_CAPTURE : has

    %% Media Relations
    MEDIA ||--o{ MEDIA_THUMBNAIL : has
    MEDIA }o--o| MEDIA_FOLDER : "stored in"
    MEDIA }o--o{ TAG : tagged

    %% Property Relations
    PROPERTY_GROUP ||--o{ PROPERTY_GROUP_OPTION : contains

    %% Plugin System
    PLUGIN ||--o{ PAYMENT_METHOD : provides
```

## 商品ドメイン詳細図

```mermaid
erDiagram
    PRODUCT {
        binary id PK
        binary version_id PK
        binary parent_id FK
        binary tax_id FK
        binary product_manufacturer_id FK
        binary unit_id FK
        binary product_media_id FK
        binary delivery_time_id FK
        binary cms_page_id FK
        varchar product_number UK
        json price
        int stock
        boolean active
        boolean available
        float weight
        float width
        float height
        float length
        datetime created_at
        datetime updated_at
    }

    PRODUCT_TRANSLATION {
        binary product_id PK,FK
        binary product_version_id PK
        binary language_id PK,FK
        varchar name
        longtext description
        varchar meta_title
        varchar meta_description
        varchar keywords
        json custom_fields
    }

    PRODUCT_MEDIA {
        binary id PK
        binary version_id PK
        binary product_id FK
        binary product_version_id FK
        binary media_id FK
        int position
        json custom_fields
    }

    PRODUCT_PRICE {
        binary id PK
        binary version_id PK
        binary product_id FK
        binary product_version_id FK
        binary rule_id FK
        json price
        int quantity_start
        int quantity_end
    }

    PRODUCT_CATEGORY {
        binary product_id PK,FK
        binary product_version_id PK
        binary category_id PK,FK
        binary category_version_id PK
    }

    PRODUCT_TAG {
        binary product_id PK,FK
        binary product_version_id PK
        binary tag_id PK,FK
    }

    PRODUCT_PROPERTY {
        binary product_id PK,FK
        binary product_version_id PK
        binary property_group_option_id PK,FK
    }

    PRODUCT_OPTION {
        binary product_id PK,FK
        binary product_version_id PK
        binary property_group_option_id PK,FK
    }

    PRODUCT_MANUFACTURER {
        binary id PK
        binary version_id PK
        binary media_id FK
        varchar name
        longtext description
        varchar link
    }

    PRODUCT_REVIEW {
        binary id PK
        binary product_id FK
        binary product_version_id FK
        binary customer_id FK
        binary sales_channel_id FK
        binary language_id FK
        varchar title
        longtext content
        float points
        boolean status
    }

    PRODUCT ||--|{ PRODUCT_TRANSLATION : has
    PRODUCT ||--o{ PRODUCT_MEDIA : has
    PRODUCT ||--o{ PRODUCT_PRICE : has
    PRODUCT }o--o{ PRODUCT_CATEGORY : "belongs to"
    PRODUCT }o--o{ PRODUCT_TAG : tagged
    PRODUCT }o--o{ PRODUCT_PROPERTY : "has properties"
    PRODUCT }o--o{ PRODUCT_OPTION : "has options"
    PRODUCT }o--o| PRODUCT_MANUFACTURER : "made by"
    PRODUCT ||--o{ PRODUCT_REVIEW : receives
```

## 注文ドメイン詳細図

```mermaid
erDiagram
    ORDER {
        binary id PK
        binary version_id PK
        binary billing_address_id FK
        binary currency_id FK
        binary language_id FK
        binary sales_channel_id FK
        binary state_id FK
        varchar order_number UK
        datetime order_date_time
        json price
        float amount_total
        float amount_net
        float shipping_total
        float currency_factor
        varchar deep_link_code
        json custom_fields
    }

    ORDER_CUSTOMER {
        binary id PK
        binary version_id PK
        binary order_id FK,UK
        binary order_version_id UK
        binary customer_id FK
        varchar email
        varchar first_name
        varchar last_name
        varchar company
        varchar customer_number
        json custom_fields
    }

    ORDER_ADDRESS {
        binary id PK
        binary version_id PK
        binary order_id FK
        binary order_version_id FK
        binary country_id FK
        binary country_state_id FK
        binary salutation_id FK
        varchar first_name
        varchar last_name
        varchar company
        varchar street
        varchar zipcode
        varchar city
        varchar phone_number
        varchar additional_address_line1
        varchar additional_address_line2
        json custom_fields
    }

    ORDER_LINE_ITEM {
        binary id PK
        binary version_id PK
        binary order_id FK
        binary order_version_id FK
        binary product_id FK
        binary product_version_id FK
        binary parent_id FK
        binary cover_id FK
        varchar identifier
        varchar referenced_id
        int quantity
        varchar label
        json payload
        json price
        float unit_price
        float total_price
        int position
        varchar type
    }

    ORDER_DELIVERY {
        binary id PK
        binary version_id PK
        binary order_id FK
        binary order_version_id FK
        binary shipping_order_address_id FK
        binary shipping_method_id FK
        binary state_id FK
        json tracking_codes
        json shipping_costs
        datetime shipping_date_earliest
        datetime shipping_date_latest
    }

    ORDER_DELIVERY_POSITION {
        binary id PK
        binary version_id PK
        binary order_delivery_id FK
        binary order_delivery_version_id FK
        binary order_line_item_id FK
        binary order_line_item_version_id FK
        json price
        float unit_price
        float total_price
        int quantity
    }

    ORDER_TRANSACTION {
        binary id PK
        binary version_id PK
        binary order_id FK
        binary order_version_id FK
        binary payment_method_id FK
        binary state_id FK
        json amount
        json custom_fields
    }

    ORDER ||--|| ORDER_CUSTOMER : "placed by"
    ORDER ||--o{ ORDER_ADDRESS : has
    ORDER ||--|{ ORDER_LINE_ITEM : contains
    ORDER ||--o{ ORDER_DELIVERY : "delivered via"
    ORDER ||--o{ ORDER_TRANSACTION : "paid via"
    ORDER_DELIVERY ||--o{ ORDER_DELIVERY_POSITION : contains
```

## 顧客ドメイン詳細図

```mermaid
erDiagram
    CUSTOMER {
        binary id PK
        binary customer_group_id FK
        binary sales_channel_id FK
        binary language_id FK
        binary default_billing_address_id FK
        binary default_shipping_address_id FK
        binary salutation_id FK
        varchar customer_number UK
        varchar first_name
        varchar last_name
        varchar email
        varchar company
        varchar password
        varchar title
        json vat_ids
        boolean active
        boolean guest
        datetime first_login
        datetime last_login
        date birthday
        int order_count
        float order_total_amount
        varchar account_type
    }

    CUSTOMER_ADDRESS {
        binary id PK
        binary customer_id FK
        binary country_id FK
        binary country_state_id FK
        binary salutation_id FK
        varchar first_name
        varchar last_name
        varchar company
        varchar department
        varchar street
        varchar zipcode
        varchar city
        varchar title
        json vat_id
        varchar phone_number
        varchar additional_address_line1
        varchar additional_address_line2
        json custom_fields
    }

    CUSTOMER_GROUP {
        binary id PK
        varchar name
        boolean display_gross
        boolean registration_active
        varchar registration_title
        longtext registration_introduction
        boolean registration_only_company_registration
        longtext registration_seo_meta_description
        json custom_fields
    }

    CUSTOMER_TAG {
        binary customer_id PK,FK
        binary tag_id PK,FK
    }

    CUSTOMER_RECOVERY {
        binary id PK
        binary customer_id FK,UK
        varchar hash
        datetime created_at
    }

    CUSTOMER_WISHLIST {
        binary id PK
        binary customer_id FK
        binary sales_channel_id FK
        json custom_fields
    }

    CUSTOMER_WISHLIST_PRODUCT {
        binary id PK
        binary customer_wishlist_id FK
        binary product_id FK
        binary product_version_id FK
    }

    CUSTOMER ||--o{ CUSTOMER_ADDRESS : has
    CUSTOMER }o--|| CUSTOMER_GROUP : "belongs to"
    CUSTOMER }o--o{ CUSTOMER_TAG : tagged
    CUSTOMER ||--o| CUSTOMER_RECOVERY : has
    CUSTOMER ||--o{ CUSTOMER_WISHLIST : has
    CUSTOMER_WISHLIST ||--o{ CUSTOMER_WISHLIST_PRODUCT : contains
```

## システム設定ドメイン詳細図

```mermaid
erDiagram
    SALES_CHANNEL {
        binary id PK
        binary type_id FK
        binary language_id FK
        binary customer_group_id FK
        binary currency_id FK
        binary payment_method_id FK
        binary shipping_method_id FK
        binary country_id FK
        binary navigation_category_id FK
        binary footer_category_id FK
        binary service_category_id FK
        varchar short_name
        varchar access_key
        boolean active
        boolean maintenance
        json configuration
    }

    SALES_CHANNEL_DOMAIN {
        binary id PK
        binary sales_channel_id FK
        binary language_id FK
        binary currency_id FK
        binary snippet_set_id FK
        varchar url
        boolean hreflang_use_only_locale
        json custom_fields
    }

    SALES_CHANNEL_LANGUAGE {
        binary sales_channel_id PK,FK
        binary language_id PK,FK
    }

    SALES_CHANNEL_CURRENCY {
        binary sales_channel_id PK,FK
        binary currency_id PK,FK
    }

    SALES_CHANNEL_COUNTRY {
        binary sales_channel_id PK,FK
        binary country_id PK,FK
    }

    SALES_CHANNEL_PAYMENT_METHOD {
        binary sales_channel_id PK,FK
        binary payment_method_id PK,FK
    }

    SALES_CHANNEL_SHIPPING_METHOD {
        binary sales_channel_id PK,FK
        binary shipping_method_id PK,FK
    }

    LANGUAGE {
        binary id PK
        binary parent_id FK
        binary locale_id FK
        binary translation_code_id FK
        varchar name
        json custom_fields
    }

    CURRENCY {
        binary id PK
        varchar iso_code UK
        float factor
        varchar symbol
        varchar short_name
        varchar name
        int position
        int decimal_precision
        boolean is_system_default
        json custom_fields
    }

    COUNTRY {
        binary id PK
        varchar iso UK
        varchar iso3 UK
        varchar name
        int position
        boolean active
        boolean shipping_available
        boolean force_state_in_registration
        json custom_fields
    }

    SALES_CHANNEL ||--o{ SALES_CHANNEL_DOMAIN : has
    SALES_CHANNEL }o--o{ SALES_CHANNEL_LANGUAGE : "supports"
    SALES_CHANNEL }o--o{ SALES_CHANNEL_CURRENCY : "accepts"
    SALES_CHANNEL }o--o{ SALES_CHANNEL_COUNTRY : "ships to"
    SALES_CHANNEL }o--o{ SALES_CHANNEL_PAYMENT_METHOD : "accepts"
    SALES_CHANNEL }o--o{ SALES_CHANNEL_SHIPPING_METHOD : "ships via"
```

## メディア管理ドメイン詳細図

```mermaid
erDiagram
    MEDIA {
        binary id PK
        binary user_id FK
        binary media_folder_id FK
        varchar mime_type
        varchar file_extension
        datetime uploaded_at
        longtext file_name
        int file_size
        blob media_type
        json meta_data
        json config
        varchar path
        boolean private
    }

    MEDIA_TRANSLATION {
        binary media_id PK,FK
        binary language_id PK,FK
        varchar alt
        varchar title
        json custom_fields
    }

    MEDIA_FOLDER {
        binary id PK
        binary parent_id FK
        binary media_folder_configuration_id FK
        binary default_folder_id FK
        varchar name
        boolean use_parent_configuration
        int child_count
    }

    MEDIA_THUMBNAIL {
        binary id PK
        binary media_id FK
        int width
        int height
        varchar path
    }

    MEDIA_TAG {
        binary media_id PK,FK
        binary tag_id PK,FK
    }

    TAG {
        binary id PK
        varchar name UK
    }

    MEDIA ||--|{ MEDIA_TRANSLATION : has
    MEDIA ||--o{ MEDIA_THUMBNAIL : has
    MEDIA }o--o| MEDIA_FOLDER : "stored in"
    MEDIA }o--o{ MEDIA_TAG : tagged
    MEDIA_FOLDER ||--o{ MEDIA_FOLDER : "parent-child"
```

## 凡例

```mermaid
erDiagram
    ENTITY_A ||--|| ENTITY_B : "1対1"
    ENTITY_C ||--o| ENTITY_D : "1対0..1"
    ENTITY_E ||--|{ ENTITY_F : "1対多"
    ENTITY_G ||--o{ ENTITY_H : "1対0..多"
    ENTITY_I }o--o{ ENTITY_J : "多対多"
```

| 記号 | 説明 |
| --- | --- |
| `||` | 必須（1） |
| `o|` | オプショナル（0または1） |
| `|{` | 1以上の多 |
| `o{` | 0以上の多 |
| `PK` | 主キー |
| `FK` | 外部キー |
| `UK` | 一意キー |
