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

90 lines
8.6 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_reward_account" resource="default" engine="innodb" comment="eSUN Reward Accounts">
<column xsi:type="int" name="account_id" unsigned="true" nullable="false" identity="true" comment="Account ID"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
<column xsi:type="smallint" name="website_id" unsigned="true" nullable="false" comment="Website ID"/>
<column xsi:type="int" name="balance" nullable="false" default="0" comment="Available Points"/>
<column xsi:type="int" name="pending_balance" nullable="false" default="0" comment="Pending Points"/>
<column xsi:type="int" name="lifetime_earned" unsigned="true" nullable="false" default="0" comment="Lifetime Earned Points"/>
<column xsi:type="decimal" name="lifetime_spend_base" scale="4" precision="20" nullable="false" default="0" comment="Lifetime Base Spend"/>
<column xsi:type="varchar" name="tier_code" nullable="false" length="32" default="bronze" comment="Tier Code"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" 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="account_id"/></constraint>
<constraint xsi:type="unique" referenceId="ESUN_REWARD_ACCOUNT_CUSTOMER_WEBSITE_UNQ">
<column name="customer_id"/><column name="website_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="ESUN_REWARD_ACCOUNT_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID"
table="esun_reward_account" column="customer_id" referenceTable="customer_entity"
referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
<table name="esun_reward_transaction" resource="default" engine="innodb" comment="eSUN Reward Transactions">
<column xsi:type="bigint" name="transaction_id" unsigned="true" nullable="false" identity="true" comment="Transaction ID"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
<column xsi:type="smallint" name="website_id" unsigned="true" nullable="false" comment="Website ID"/>
<column xsi:type="int" name="points_delta" nullable="false" comment="Points Delta"/>
<column xsi:type="int" name="balance_after" nullable="false" comment="Balance After"/>
<column xsi:type="varchar" name="type" nullable="false" length="64" comment="Transaction Type"/>
<column xsi:type="varchar" name="status" nullable="false" length="24" default="available" comment="Status"/>
<column xsi:type="varchar" name="reference_type" nullable="true" length="32" comment="Reference Type"/>
<column xsi:type="varchar" name="reference_id" nullable="true" length="64" comment="Reference ID"/>
<column xsi:type="varchar" name="unique_key" nullable="false" length="191" comment="Idempotency Key"/>
<column xsi:type="text" name="reason" nullable="true" comment="Reason"/>
<column xsi:type="int" name="admin_user_id" unsigned="true" nullable="true" comment="Admin User ID"/>
<column xsi:type="text" name="metadata" nullable="true" comment="JSON Metadata"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="transaction_id"/></constraint>
<constraint xsi:type="unique" referenceId="ESUN_REWARD_TRANSACTION_UNIQUE_KEY_UNQ"><column name="unique_key"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_REWARD_TRANSACTION_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID"
table="esun_reward_transaction" column="customer_id" referenceTable="customer_entity"
referenceColumn="entity_id" onDelete="CASCADE"/>
<index referenceId="ESUN_REWARD_TRANSACTION_CUSTOMER_CREATED" indexType="btree">
<column name="customer_id"/><column name="created_at"/>
</index>
</table>
<table name="esun_reward_reservation" resource="checkout" engine="innodb" comment="eSUN Reward Quote Reservations">
<column xsi:type="int" name="reservation_id" unsigned="true" nullable="false" identity="true" comment="Reservation ID"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
<column xsi:type="int" name="quote_id" unsigned="true" nullable="false" comment="Quote ID"/>
<column xsi:type="int" name="points" unsigned="true" nullable="false" comment="Reserved Points"/>
<column xsi:type="varchar" name="status" nullable="false" length="24" default="active" comment="Status"/>
<column xsi:type="timestamp" name="expires_at" nullable="true" comment="Expires At"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" 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="reservation_id"/></constraint>
<constraint xsi:type="unique" referenceId="ESUN_REWARD_RESERVATION_QUOTE_UNQ"><column name="quote_id"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_REWARD_RESERVATION_QUOTE_ID_QUOTE_ENTITY_ID"
table="esun_reward_reservation" column="quote_id" referenceTable="quote" referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
<table name="quote" resource="checkout" engine="innodb" comment="Sales Flat Quote">
<column xsi:type="int" name="reward_points_used" unsigned="true" nullable="false" default="0" comment="Reward Points Used"/>
<column xsi:type="decimal" name="reward_discount_amount" scale="4" precision="20" nullable="false" default="0" comment="Reward Discount"/>
<column xsi:type="decimal" name="base_reward_discount_amount" scale="4" precision="20" nullable="false" default="0" comment="Base Reward Discount"/>
<column xsi:type="int" name="reward_product_points" unsigned="true" nullable="false" default="0" comment="Reward Product Points"/>
</table>
<table name="quote_item" resource="checkout" engine="innodb" comment="Sales Flat Quote Item">
<column xsi:type="smallint" name="reward_redemption" unsigned="true" nullable="false" default="0" comment="Reward Redemption Item"/>
<column xsi:type="int" name="reward_points_cost" unsigned="true" nullable="false" default="0" comment="Reward Points Cost"/>
</table>
<table name="sales_order" resource="sales" engine="innodb" comment="Sales Flat Order">
<column xsi:type="int" name="reward_points_used" unsigned="true" nullable="false" default="0" comment="Reward Points Used"/>
<column xsi:type="int" name="reward_points_earned" unsigned="true" nullable="false" default="0" comment="Reward Points Earned"/>
<column xsi:type="decimal" name="reward_discount_amount" scale="4" precision="20" nullable="false" default="0" comment="Reward Discount"/>
<column xsi:type="decimal" name="base_reward_discount_amount" scale="4" precision="20" nullable="false" default="0" comment="Base Reward Discount"/>
<column xsi:type="varchar" name="reward_tier_code" nullable="true" length="32" comment="Reward Tier Snapshot"/>
<column xsi:type="decimal" name="reward_multiplier" scale="4" precision="12" nullable="false" default="1" comment="Reward Multiplier Snapshot"/>
<column xsi:type="int" name="reward_product_points" unsigned="true" nullable="false" default="0" comment="Reward Product Points"/>
<column xsi:type="int" name="reward_points_refunded" unsigned="true" nullable="false" default="0" comment="Reward Points Refunded"/>
<column xsi:type="int" name="reward_points_reversed" unsigned="true" nullable="false" default="0" comment="Earned Points Reversed"/>
</table>
<table name="sales_order_item" resource="sales" engine="innodb" comment="Sales Flat Order Item">
<column xsi:type="smallint" name="reward_redemption" unsigned="true" nullable="false" default="0" comment="Reward Redemption Item"/>
<column xsi:type="int" name="reward_points_cost" unsigned="true" nullable="false" default="0" comment="Reward Points Cost"/>
</table>
</schema>