Files
2026-09-15 10:35:56 +08:00

72 lines
8.4 KiB
XML

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="esun_customer_message" resource="default" engine="innodb" comment="Customer Messages">
<column xsi:type="int" name="message_id" unsigned="true" nullable="false" identity="true" comment="Message ID"/>
<column xsi:type="varchar" name="title" nullable="false" length="255" comment="Title"/>
<column xsi:type="text" name="content" nullable="false" comment="Content"/>
<column xsi:type="varchar" name="message_type" nullable="false" length="32" default="notice" comment="Message Type"/>
<column xsi:type="smallint" name="store_id" unsigned="true" nullable="false" default="0" comment="Store ID"/>
<column xsi:type="smallint" name="is_active" unsigned="true" nullable="false" default="1" comment="Is Active"/>
<column xsi:type="timestamp" name="expires_at" nullable="true" on_update="false" comment="Expires At"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="false" comment="Created At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="message_id"/></constraint>
<index referenceId="ESUN_CUSTOMER_MESSAGE_ACTIVE_STORE" indexType="btree"><column name="is_active"/><column name="store_id"/><column name="created_at"/></index>
</table>
<table name="esun_customer_message_recipient" resource="default" engine="innodb" comment="Customer Message Recipients">
<column xsi:type="int" name="recipient_id" unsigned="true" nullable="false" identity="true" comment="Recipient ID"/>
<column xsi:type="int" name="message_id" unsigned="true" nullable="false" comment="Message ID"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
<column xsi:type="smallint" name="is_read" unsigned="true" nullable="false" default="0" comment="Is Read"/>
<column xsi:type="timestamp" name="read_at" nullable="true" on_update="false" comment="Read At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="recipient_id"/></constraint>
<constraint xsi:type="unique" referenceId="ESUN_CUSTOMER_MESSAGE_RECIPIENT_UNQ"><column name="message_id"/><column name="customer_id"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_CUSTOMER_MESSAGE_RECIPIENT_MESSAGE_FK" table="esun_customer_message_recipient" column="message_id" referenceTable="esun_customer_message" referenceColumn="message_id" onDelete="CASCADE"/>
<constraint xsi:type="foreign" referenceId="ESUN_CUSTOMER_MESSAGE_RECIPIENT_CUSTOMER_FK" table="esun_customer_message_recipient" column="customer_id" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
<index referenceId="ESUN_CUSTOMER_MESSAGE_RECIPIENT_CUSTOMER_READ" indexType="btree"><column name="customer_id"/><column name="is_read"/></index>
</table>
<table name="esun_customer_message_thread" resource="default" engine="innodb" comment="Customer Message Conversations">
<column xsi:type="int" name="thread_id" unsigned="true" nullable="false" identity="true" comment="Thread ID"/>
<column xsi:type="varchar" name="thread_type" nullable="false" length="16" default="general" comment="Thread Type"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
<column xsi:type="int" name="order_id" unsigned="true" nullable="true" comment="Order ID"/>
<column xsi:type="smallint" name="store_id" unsigned="true" nullable="false" default="0" comment="Store ID"/>
<column xsi:type="varchar" name="subject" nullable="false" length="255" comment="Subject"/>
<column xsi:type="varchar" name="status" nullable="false" length="24" default="awaiting_admin" comment="Conversation Status"/>
<column xsi:type="int" name="last_message_id" unsigned="true" nullable="true" comment="Last Message ID"/>
<column xsi:type="int" name="customer_unread_count" unsigned="true" nullable="false" default="0" comment="Customer Unread Count"/>
<column xsi:type="int" name="admin_unread_count" unsigned="true" nullable="false" default="0" comment="Admin Unread Count"/>
<column xsi:type="timestamp" name="last_message_at" nullable="true" on_update="false" comment="Last Message At"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="false" comment="Created At"/>
<column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="true" comment="Updated At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="thread_id"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_CUSTOMER_MESSAGE_THREAD_CUSTOMER_FK" table="esun_customer_message_thread" column="customer_id" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
<constraint xsi:type="foreign" referenceId="ESUN_CUSTOMER_MESSAGE_THREAD_ORDER_FK" table="esun_customer_message_thread" column="order_id" referenceTable="sales_order" referenceColumn="entity_id" onDelete="CASCADE"/>
<constraint xsi:type="unique" referenceId="ESUN_CUSTOMER_MESSAGE_THREAD_ORDER_UNQ"><column name="order_id"/></constraint>
<index referenceId="ESUN_CUSTOMER_MESSAGE_THREAD_CUSTOMER_ACTIVITY" indexType="btree"><column name="customer_id"/><column name="last_message_at"/></index>
<index referenceId="ESUN_CUSTOMER_MESSAGE_THREAD_ADMIN_QUEUE" indexType="btree"><column name="admin_unread_count"/><column name="last_message_at"/></index>
</table>
<table name="esun_customer_message_entry" resource="default" engine="innodb" comment="Customer Conversation Messages">
<column xsi:type="int" name="entry_id" unsigned="true" nullable="false" identity="true" comment="Entry ID"/>
<column xsi:type="int" name="thread_id" unsigned="true" nullable="false" comment="Thread ID"/>
<column xsi:type="varchar" name="sender_type" nullable="false" length="16" comment="Sender Type"/>
<column xsi:type="int" name="sender_id" unsigned="true" nullable="false" default="0" comment="Sender ID"/>
<column xsi:type="text" name="content" nullable="false" comment="Message Content"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="false" comment="Created At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="entry_id"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_CUSTOMER_MESSAGE_ENTRY_THREAD_FK" table="esun_customer_message_entry" column="thread_id" referenceTable="esun_customer_message_thread" referenceColumn="thread_id" onDelete="CASCADE"/>
<index referenceId="ESUN_CUSTOMER_MESSAGE_ENTRY_THREAD_CREATED" indexType="btree"><column name="thread_id"/><column name="created_at"/></index>
</table>
<table name="esun_customer_message_attachment" resource="default" engine="innodb" comment="Customer Message Attachments">
<column xsi:type="int" name="attachment_id" unsigned="true" nullable="false" identity="true" comment="Attachment ID"/>
<column xsi:type="int" name="entry_id" unsigned="true" nullable="false" comment="Entry ID"/>
<column xsi:type="varchar" name="original_name" nullable="false" length="255" comment="Original File Name"/>
<column xsi:type="varchar" name="storage_path" nullable="false" length="512" comment="Private Storage Path"/>
<column xsi:type="varchar" name="mime_type" nullable="false" length="64" comment="MIME Type"/>
<column xsi:type="int" name="file_size" unsigned="true" nullable="false" comment="File Size"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="false" comment="Created At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="attachment_id"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_CUSTOMER_MESSAGE_ATTACHMENT_ENTRY_FK" table="esun_customer_message_attachment" column="entry_id" referenceTable="esun_customer_message_entry" referenceColumn="entry_id" onDelete="CASCADE"/>
<index referenceId="ESUN_CUSTOMER_MESSAGE_ATTACHMENT_ENTRY" indexType="btree"><column name="entry_id"/></index>
</table>
</schema>