<?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="mst_feed_custom_attribute" resource="default" engine="innodb" comment="mst_feed_custom_attribute">
        <column xsi:type="int" name="attribute_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Attribute Id"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Name"/>
        <column xsi:type="varchar" name="code" nullable="false" length="255" comment="Code"/>
        <column xsi:type="text" name="conditions_serialized" nullable="false" comment="Conditions Serialized"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="attribute_id"/>
        </constraint>
    </table>
    <table name="mst_feed_feed" resource="default" engine="innodb" comment="mst_feed_feed">
        <column xsi:type="int" name="feed_id" padding="11" unsigned="false" nullable="false" identity="true" comment="Feed Id"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Name"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false" comment="Store Id"/>
        <column xsi:type="varchar" name="filename" nullable="false" length="255" comment="Filename"/>
        <column xsi:type="varchar" name="generated_filename" nullable="true" length="255" comment="Generated Filename"/>
        <column xsi:type="varchar" name="type" nullable="false" length="255" comment="Type"/>
        <column xsi:type="varchar" name="marketplace" nullable="true" length="32" comment="Marketplace (e.g. google). Drives marketplace-specific UI such as the Google Merchant Center tab."/>
        <column xsi:type="varchar" name="logo" nullable="true" length="255" comment="Logo"/>
        <column xsi:type="varchar" name="guide_link" nullable="true" length="255" comment="Link to documentation"/>
        <column xsi:type="text" name="description" nullable="true" comment="Description"/>
        <column xsi:type="int" name="is_json" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Is JSON"/>
        <column xsi:type="int" name="is_compressed" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Compress output (gzip)"/>
        <column xsi:type="int" name="extract_level" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="JSON extract level"/>
        <column xsi:type="varchar" name="json_framing" nullable="false" length="16" default="document" comment="JSON framing: document (one JSON document) or lines (one object per line)"/>
        <column xsi:type="longtext" name="format_serialized" nullable="true" comment="Format"/>
        <column xsi:type="longtext" name="validation_rules" nullable="true" comment="Validation Rules"/>
        <column xsi:type="int" name="is_active" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Is Active"/>
        <column xsi:type="datetime" name="generated_at" on_update="false" nullable="true" comment="Generated At"/>
        <column xsi:type="int" name="generated_cnt" padding="11" unsigned="false" nullable="true" identity="false" comment="Generated Cnt"/>
        <column xsi:type="int" name="generated_time" padding="11" unsigned="false" nullable="true" identity="false" comment="Generated Time"/>
        <column xsi:type="datetime" name="validated_at" on_update="false" nullable="true" comment="Validated At"/>
        <column xsi:type="int" name="cron" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Cron"/>
        <column xsi:type="varchar" name="cron_day" nullable="true" length="255" comment="Cron Day"/>
        <column xsi:type="varchar" name="cron_time" nullable="true" length="255" comment="Cron Time"/>
        <column xsi:type="varchar" name="cron_mode" nullable="false" length="16" default="fixed" comment="Schedule mode: fixed (days and times) or expression (cron expression)"/>
        <column xsi:type="varchar" name="cron_expression" nullable="true" length="255" comment="Cron expression, used in expression schedule mode"/>
        <column xsi:type="datetime" name="cron_started_at" on_update="false" nullable="true" comment="When the cron last started generating the feed, whether or not that run completed"/>
        <column xsi:type="int" name="ftp" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Ftp"/>
        <column xsi:type="varchar" name="ftp_protocol" nullable="true" length="255" comment="Ftp Protocol"/>
        <column xsi:type="varchar" name="ftp_host" nullable="true" length="255" comment="Ftp Host"/>
        <column xsi:type="varchar" name="ftp_user" nullable="true" length="255" comment="Ftp User"/>
        <column xsi:type="varchar" name="ftp_password" nullable="true" length="255" comment="Ftp Password"/>
        <column xsi:type="int" name="ftp_use_private_key" nullable="true" default="0" comment="Ftp use private key"/>
        <column xsi:type="varchar" name="ftp_private_key_file" nullable="true" length="255" comment="Ftp private key filename"/>
        <column xsi:type="varchar" name="ftp_path" nullable="true" length="255" comment="Ftp Path"/>
        <column xsi:type="int" name="ftp_passive_mode" padding="11" unsigned="false" nullable="true" identity="false" comment="Ftp Passive Mode"/>
        <column xsi:type="int" name="ftp_ssl" padding="11" unsigned="false" nullable="true" identity="false" comment="SSL"/>
        <column xsi:type="datetime" name="uploaded_at" on_update="false" nullable="true" comment="Uploaded At"/>
        <column xsi:type="int" name="gmc_enabled" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="GMC Enabled"/>
        <column xsi:type="varchar" name="gmc_content_type" nullable="false" length="32" default="products" comment="GMC Content Type"/>
        <column xsi:type="varchar" name="gmc_feed_label" nullable="true" length="255" comment="GMC Feed Label"/>
        <column xsi:type="varchar" name="gmc_target_countries" nullable="true" length="255" comment="GMC Target Countries"/>
        <column xsi:type="varchar" name="gmc_language" nullable="true" length="10" comment="GMC Language"/>
        <column xsi:type="varchar" name="gmc_data_source_name" nullable="true" length="255" comment="GMC Data Source Name"/>
        <column xsi:type="int" name="gmc_upload_trigger" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="GMC Upload Trigger"/>
        <column xsi:type="int" name="gmc_fetch_frequency" padding="11" unsigned="false" nullable="false" identity="false" default="1" comment="GMC Fetch Frequency"/>
        <column xsi:type="datetime" name="gmc_uploaded_at" on_update="false" nullable="true" comment="GMC Uploaded At"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" comment="Created At"/>
        <column xsi:type="datetime" name="updated_at" on_update="false" nullable="false" comment="Updated At"/>
        <column xsi:type="varchar" name="ga_source" nullable="true" length="255" comment="Ga Source"/>
        <column xsi:type="varchar" name="ga_medium" nullable="true" length="255" comment="Ga Medium"/>
        <column xsi:type="varchar" name="ga_name" nullable="true" length="255" comment="Ga Name"/>
        <column xsi:type="varchar" name="ga_term" nullable="true" length="255" comment="Ga Term"/>
        <column xsi:type="varchar" name="ga_content" nullable="true" length="255" comment="Ga Content"/>
        <column xsi:type="varchar" name="notification_emails" nullable="true" length="255" comment="Notification Emails"/>
        <column xsi:type="varchar" name="notification_events" nullable="true" length="255" comment="Notifications Events"/>
        <column xsi:type="int" name="export_only_new" padding="11" unsigned="false" nullable="true" identity="false" comment="Export only new"/>
        <column xsi:type="int" name="report_enabled" padding="11" unsigned="false" nullable="true" identity="false" comment="Report Enabled?"/>
        <column xsi:type="varchar" name="allowed_chars" nullable="true" length="255" comment="Allowed Chars"/>
        <column xsi:type="varchar" name="ignored_chars" nullable="true" length="255" comment="Ignored Chars"/>
        <column xsi:type="varchar" name="archivation" nullable="true" length="255" comment="Archivation"/>
        <column xsi:type="boolean" name="fb_metadata_enabled" nullable="true" default="true" comment="Enable FB Metadata"/>
        <column xsi:type="boolean" name="filter_fastmode_enabled" nullable="true" default="true" comment="Enable fast filtering mode"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="feed_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_FEED_STORE_ID_STORE_STORE_ID" table="mst_feed_feed" column="store_id" referenceTable="store" referenceColumn="store_id"
                    onDelete="CASCADE"/>
        <index referenceId="MST_FEED_FEED_STORE_ID" indexType="btree">
            <column name="store_id"/>
        </index>
    </table>
    <table name="mst_feed_feed_history" resource="default" engine="innodb" comment="mst_feed_feed_history">
        <column xsi:type="int" name="history_id" padding="11" unsigned="false" nullable="false" identity="true" comment="History Id"/>
        <column xsi:type="int" name="feed_id" padding="11" unsigned="false" nullable="false" identity="false" comment="Feed Id"/>
        <column xsi:type="varchar" name="type" nullable="true" length="255" comment="Type"/>
        <column xsi:type="varchar" name="title" nullable="false" length="255" comment="Title"/>
        <column xsi:type="text" name="message" nullable="true" comment="Message"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" comment="Created At"/>
        <column xsi:type="datetime" name="updated_at" on_update="false" nullable="false" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="history_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_FEED_HISTORY_FEED_ID_MST_FEED_FEED_FEED_ID" table="mst_feed_feed_history" column="feed_id" referenceTable="mst_feed_feed"
                    referenceColumn="feed_id" onDelete="CASCADE"/>
        <index referenceId="MST_FEED_FEED_HISTORY_FEED_ID" indexType="btree">
            <column name="feed_id"/>
        </index>
        <index referenceId="MST_FEED_FEED_HISTORY_TITLE_MESSAGE_TYPE" indexType="fulltext">
            <column name="title"/>
            <column name="message"/>
            <column name="type"/>
        </index>
    </table>
    <table name="mst_feed_feed_product" resource="default" engine="innodb" comment="mst_feed_feed_product">
        <column xsi:type="int" name="id" padding="10" unsigned="true" nullable="false" identity="true" comment="Id"/>
        <column xsi:type="int" name="feed_id" padding="11" unsigned="false" nullable="false" identity="false" comment="Feed Id"/>
        <column xsi:type="int" name="product_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Product Id"/>
        <column xsi:type="int" name="is_new" padding="10" unsigned="true" nullable="false" identity="false" comment="Is New"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_FEED_PRODUCT_FEED_ID_MST_FEED_FEED_FEED_ID" table="mst_feed_feed_product" column="feed_id" referenceTable="mst_feed_feed"
                    referenceColumn="feed_id" onDelete="CASCADE"/>
        <!-- @orphan-ok: product_id — no foreign key on product_id, deliberately. This table is derived data: every export
             deletes the feed's rows and re-inserts them. A foreign key to catalog_product_entity made
             InnoDB take a shared lock on every referenced product row while that insert runs (5-9k rows
             on a typical feed), so any concurrent transaction holding an X lock on a single product -
             an ERP writing products, a stuck product save - stalled the insert until
             innodb_lock_wait_timeout and killed the export with a 1205, discarding the whole filtration
             run. Orphan rows left by product deletion are swept by Mirasvit\Feed\Cron\CleanupCron
             instead. The feed_id key above stays: few parent rows, no contention, and it is what
             cascades the table clean when a feed is removed. -->
        <constraint xsi:type="unique" referenceId="MST_FEED_FEED_PRODUCT_FEED_ID_PRODUCT_ID">
            <column name="feed_id"/>
            <column name="product_id"/>
        </constraint>
        <index referenceId="MST_FEED_FEED_PRODUCT_PRODUCT_ID" indexType="btree">
            <column name="product_id"/>
        </index>
    </table>
    <table name="mst_feed_mapping_category" resource="default" engine="innodb" comment="mst_feed_mapping_category">
        <column xsi:type="int" name="mapping_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Mapping Id"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Name"/>
        <column xsi:type="varchar" name="type" nullable="false" length="255" comment="Type"/>
        <column xsi:type="longtext" name="mapping_serialized" nullable="false" onCreate="migrateDataFrom(mapping_serialized)"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="mapping_id"/>
        </constraint>
    </table>
    <table name="mst_feed_rule" resource="default" engine="innodb" comment="mst_feed_rule">
        <column xsi:type="int" name="rule_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Rule Id"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Name"/>
        <column xsi:type="text" name="conditions_serialized" nullable="false" comment="Conditions Serialized"/>
        <column xsi:type="text" name="actions_serialized" nullable="true" comment="Actions Serialized" disabled="true"/>
        <column xsi:type="int" name="is_active" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Is Active"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" comment="Created At" disabled="true"/>
        <column xsi:type="datetime" name="updated_at" on_update="false" nullable="false" comment="Updated At" disabled="true"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="rule_id"/>
        </constraint>
    </table>
    <table name="mst_feed_rule_feed" resource="default" engine="innodb" comment="mst_feed_rule_feed">
        <column xsi:type="int" name="id" padding="11" unsigned="false" nullable="false" identity="true" comment="Id"/>
        <column xsi:type="int" name="rule_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Rule Id"/>
        <column xsi:type="int" name="feed_id" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Feed Id"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_RULE_FEED_FEED_ID_MST_FEED_FEED_FEED_ID" table="mst_feed_rule_feed" column="feed_id" referenceTable="mst_feed_feed"
                    referenceColumn="feed_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="MST_FEED_RULE_FEED_RULE_ID_MST_FEED_RULE_RULE_ID" table="mst_feed_rule_feed" column="rule_id" referenceTable="mst_feed_rule"
                    referenceColumn="rule_id" onDelete="CASCADE"/>
        <constraint xsi:type="unique" referenceId="MST_FEED_RULE_FEED_RULE_ID_FEED_ID">
            <column name="rule_id"/>
            <column name="feed_id"/>
        </constraint>
        <index referenceId="MST_FEED_RULE_FEED_FEED_ID" indexType="btree">
            <column name="feed_id"/>
        </index>
    </table>
    <table name="mst_feed_rule_product" resource="default" engine="innodb" comment="mst_feed_rule_product">
        <column xsi:type="int" name="id" padding="10" unsigned="true" nullable="false" identity="true" comment="Id"/>
        <column xsi:type="int" name="rule_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Rule Id"/>
        <!-- @orphan-ok: product_id — derived data, replaced per (rule, store view) whenever the rule
             is evaluated. Export/Step/Filtration/Rule.php is the only caller: it runs
             RuleRepository::clearProductIds() for the rule and the store view being generated, then
             addProductIds() re-inserts the set that still matches, so a deleted product drops out the
             next time a feed exports with that rule for that store view.
             That is the only thing which replaces them, so say what it does not cover: a rule attached
             to no feed, or only to a disabled one, keeps its rows for as long as the rule exists, and
             the scoping is per store view, so an export for store A leaves store B's rows alone. Both
             ends of the row are covered by a cascade - deleting the rule or the store view removes it -
             and there is deliberately no nightly sweep for this table the way there is for
             mst_feed_feed_product.
             Leaving those rows is safe. The export drives off the catalog product collection and joins
             this data to it (Export/Resolver/GeneralResolver.php:188-192), so an id whose product is
             gone can never render an item; Filtration copies it into mst_feed_feed_product, where the
             nightly sweep does remove it; and the unique key on (rule_id, product_id, store_id) bounds
             what can accumulate to one row per deleted product per rule per store view.
             No foreign key here for the same InnoDB locking reason spelled out on mst_feed_feed_product
             above: the insert is bulk and a constraint would take a shared lock on every referenced
             product row. -->
        <column xsi:type="int" name="product_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Product Id"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false" default="0" comment="Store Id"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_RULE_PRODUCT_RULE_ID_MST_FEED_RULE_RULE_ID" table="mst_feed_rule_product" column="rule_id" referenceTable="mst_feed_rule"
                    referenceColumn="rule_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="MST_FEED_RULE_PRODUCT_STORE_ID_STORE_STORE_ID" table="mst_feed_rule_product" column="store_id" referenceTable="store" referenceColumn="store_id"
                    onDelete="CASCADE"/>
        <constraint xsi:type="unique" referenceId="MST_FEED_RULE_PRODUCT_RULE_ID_PRODUCT_ID_STORE_ID">
            <column name="rule_id"/>
            <column name="product_id"/>
            <column name="store_id"/>
        </constraint>
        <index referenceId="MST_FEED_RULE_PRODUCT_STORE_ID" indexType="btree">
            <column name="store_id"/>
        </index>
        <index referenceId="MST_FEED_RULE_PRODUCT_PRODUCT_ID" indexType="btree">
            <column name="product_id"/>
        </index>
    </table>
    <table name="mst_feed_template" resource="default" engine="innodb" comment="mst_feed_template">
        <column xsi:type="int" name="template_id" padding="11" unsigned="false" nullable="false" identity="true" comment="Template Id"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Name"/>
        <column xsi:type="varchar" name="type" nullable="false" length="255" comment="Type"/>
        <column xsi:type="varchar" name="logo" nullable="true" length="255" comment="Logo"/>
        <column xsi:type="varchar" name="guide_link" nullable="true" length="255" comment="Link to documentation"/>
        <column xsi:type="text" name="description" nullable="true" comment="Description"/>
        <column xsi:type="longtext" name="format_serialized" nullable="true" comment="Format"/>
        <column xsi:type="longtext" name="validation_rules" nullable="true" comment="Validation Rules"/>
        <column xsi:type="smallint" name="is_user_defined" unsigned="true" nullable="false" identity="false" default="1" comment="Defines is template user defined"/>
        <column xsi:type="smallint" name="is_popular" unsigned="true" nullable="false" identity="false" default="0" comment="Defines is template popular"/>
        <column xsi:type="varchar" name="marketplace" nullable="true" length="32" comment="Marketplace pre-fill for feeds created from this template (e.g. google)"/>
        <column xsi:type="varchar" name="gmc_content_type" nullable="true" length="32" comment="GMC Content Type pre-fill for feeds created from this template"/>
        <column xsi:type="varchar" name="json_framing" nullable="false" length="16" default="document" comment="JSON framing: document (one JSON document) or lines (one object per line)"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" comment="Created At"/>
        <column xsi:type="datetime" name="updated_at" on_update="false" nullable="false" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="template_id"/>
        </constraint>
    </table>
    <table name="mst_feed_report" resource="default" engine="innodb" comment="Feed Report">
        <!-- @orphan-ok: product_id — append-only analytics log; a row must outlive its product.
             One row is one event: a click on a product in a feed, or a product line of an order
             that a feed click converted, and in the second case the row carries the revenue
             attributed to that feed. Everything the admin reads here is a feed-scoped aggregate
             over the whole history of the table - SUM(is_click), COUNT(DISTINCT order_id) and
             SUM(subtotal) in ResourceModel/Feed/Grid.php, in Service/Feed/StatisticsAggregator.php
             (which rebuilds mst_feed_report_daily from these rows in full, twice an hour, so there
             is no frozen copy of yesterday's numbers anywhere), and in the Advanced Reports feed
             report. Removing a row, or nulling the id it is grouped by, would therefore rewrite
             closed periods every time a merchant tidies up the catalog - which is the one thing a
             revenue report may not do.
             The orphan is inert. The module only ever WRITES these rows (FrontControllerPlugin for
             a click, OrderPlaceAfterObserver for an order) and reads them as sums; nothing loads a
             product by this id. The single product-scoped read is the report's optional
             catalog_product_entity|sku dimension (etc/mst_report.xml), where a deleted product
             yields no SKU - exactly what it should.
             Nor is growth an argument: nothing prunes this table by design (CleanupCron sweeps
             mst_feed_feed_product and the generation history only), so rows of deleted products are
             a rounding error against the click log itself.
             The one way a stale id could be misread is id reuse, and that takes a TRUNCATE of
             catalog_product_entity - or, before MySQL 8.0 persisted the counter, a restart right
             after deleting the newest products. Both mean a catalog rebuilt from scratch, against
             which this history is meaningless regardless. -->
        <!-- @orphan-ok: order_id — the same log and the same reason. This is the column
             COUNT(DISTINCT order_id) counts, and an order that was placed stays placed: dropping it
             from the count because the record was later removed would understate what the channel
             actually produced. Magento ships no way to delete an order from the admin, so this is a
             deliberate act on the merchant's side, not routine housekeeping. Reuse of the id has
             the same shape as for product_id above and the same answer. -->
        <column xsi:type="int" name="row_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Row Id"/>
        <column xsi:type="varchar" name="session" nullable="false" length="255" comment="Session"/>
        <column xsi:type="int" name="feed_id" padding="11" unsigned="false" nullable="false" identity="false" comment="Feed Id"/>
        <column xsi:type="int" name="product_id" padding="11" unsigned="false" nullable="true" identity="false" comment="Product Id"/>
        <column xsi:type="int" name="order_id" padding="11" unsigned="false" nullable="true" identity="false" comment="Order Id"/>
        <column xsi:type="int" name="is_click" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Is Click?"/>
        <column xsi:type="decimal" name="subtotal" scale="4" precision="12" unsigned="false" nullable="true" comment="Order subtotal (for product)"/>
        <column xsi:type="int" name="store_id" padding="11" unsigned="false" nullable="false" identity="false" comment="Store Id"/>
        <column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="row_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_REPORT_FEED_ID_MST_FEED_FEED_FEED_ID" table="mst_feed_report" column="feed_id" referenceTable="mst_feed_feed" referenceColumn="feed_id"
                    onDelete="CASCADE"/>
        <index referenceId="MST_FEED_REPORT_PRODUCT_ID" indexType="btree">
            <column name="product_id"/>
        </index>
        <index referenceId="MST_FEED_REPORT_FEED_ID" indexType="btree">
            <column name="feed_id"/>
        </index>
        <index referenceId="MST_FEED_REPORT_SESSION" indexType="btree">
            <column name="session"/>
        </index>
        <index referenceId="MST_FEED_REPORT_STORE_ID" indexType="btree">
            <column name="store_id"/>
        </index>
    </table>
    <table name="mst_feed_report_daily" resource="default" engine="innodb" comment="Feed Report Daily Aggregation">
        <column xsi:type="int" name="feed_id" padding="11" unsigned="false" nullable="false" identity="false" comment="Feed Id"/>
        <column xsi:type="int" name="clicks" padding="11" unsigned="true" nullable="false" default="0" comment="Clicks"/>
        <column xsi:type="int" name="orders" padding="11" unsigned="true" nullable="false" default="0" comment="Orders"/>
        <column xsi:type="decimal" name="revenue" scale="4" precision="12" unsigned="false" nullable="false" default="0.0000" comment="Revenue"/>
        <column xsi:type="date" name="date" nullable="false" comment="Aggregation Date"/>
        <column xsi:type="datetime" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>
        <index referenceId="MST_FEED_REPORT_DAILY_DATE" indexType="btree">
            <column name="date"/>
        </index>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="feed_id"/>
            <column name="date"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_REPORT_DAILY_FEED_ID_MST_FEED_FEED_FEED_ID"
                    table="mst_feed_report_daily" column="feed_id"
                    referenceTable="mst_feed_feed" referenceColumn="feed_id"
                    onDelete="CASCADE"/>
    </table>
    <table name="mst_feed_dynamic_attribute" resource="default" engine="innodb" comment="Dynamic Attributes">
        <column xsi:type="int" name="attribute_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Attribute Id"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Name"/>
        <column xsi:type="varchar" name="code" nullable="false" length="255" comment="Code"/>
        <column xsi:type="text" name="conditions_serialized" nullable="true" comment="Conditions"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="attribute_id"/>
        </constraint>
    </table>
    <table name="mst_feed_dynamic_variable" resource="default" engine="innodb" comment="Dynamic Variables">
        <column xsi:type="int" name="variable_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Variable Id"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Name"/>
        <column xsi:type="varchar" name="code" nullable="false" length="255" comment="Code"/>
        <column xsi:type="longtext" name="php_code" nullable="true" onCreate="migrateDataFrom(php_code)"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="variable_id"/>
        </constraint>
    </table>
    <table name="mst_feed_generation_queue" resource="default" engine="innodb" comment="mst_feed_generation_queue">
        <column xsi:type="int" name="queue_id" padding="11" unsigned="false" nullable="false" identity="true" comment="Queue Id"/>
        <column xsi:type="int" name="feed_id" padding="11" unsigned="false" nullable="false" identity="false" comment="Feed Id"/>
        <column xsi:type="varchar" name="status" nullable="false" length="50" default="pending" comment="Status"/>
        <column xsi:type="datetime" name="started_at" on_update="false" nullable="true" comment="Started At"/>
        <column xsi:type="datetime" name="finished_at" on_update="false" nullable="true" comment="Finished At"/>
        <column xsi:type="text" name="message" nullable="true" comment="Message"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" comment="Created At"/>
        <column xsi:type="datetime" name="updated_at" on_update="false" nullable="false" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="queue_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_GENERATION_QUEUE_FEED_ID_MST_FEED_FEED_FEED_ID" table="mst_feed_generation_queue" column="feed_id" referenceTable="mst_feed_feed"
                    referenceColumn="feed_id" onDelete="CASCADE"/>
        <index referenceId="MST_FEED_GENERATION_QUEUE_FEED_ID" indexType="btree">
            <column name="feed_id"/>
        </index>
    </table>
    <table name="mst_feed_validation" resource="default" engine="innodb" comment="mst_feed_validation">
        <column xsi:type="int" name="validation_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Validation Id"/>
        <column xsi:type="int" name="feed_id" padding="11" unsigned="false" nullable="false" identity="false" comment="Feed ID"/>
        <column xsi:type="int" name="line_num" padding="11" unsigned="false" nullable="false" identity="false" comment="Line Number"/>
        <column xsi:type="int" name="entity_id" padding="11" unsigned="false" nullable="true" identity="false" comment="Abstract Entity ID (for calculating the number of invalid entities)"/>
        <column xsi:type="varchar" name="validator" nullable="false" length="255" comment="Validator"/>
        <column xsi:type="varchar" name="attribute" nullable="false" length="255" comment="Attribute"/>
        <column xsi:type="text" name="value" nullable="true" comment="Value"/>
        <column xsi:type="varchar" name="severity" nullable="true" length="255" comment="Severty"/>
        <column xsi:type="text" name="message" nullable="true" comment="Message"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="validation_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_VALIDATION_FEED_ID_MST_FEED_FEED_FEED_ID" table="mst_feed_validation" column="feed_id" referenceTable="mst_feed_feed"
                    referenceColumn="feed_id" onDelete="CASCADE"/>
        <index referenceId="MST_FEED_VALIDATION_LINE_NUM" indexType="btree">
            <column name="line_num"/>
        </index>
        <index referenceId="MST_FEED_VALIDATION_ENTITY_ID" indexType="btree">
            <column name="entity_id"/>
        </index>
        <index referenceId="MST_FEED_VALIDATION_ATTRIBUTE" indexType="btree">
            <column name="attribute"/>
        </index>
        <index referenceId="MST_FEED_VALIDATION_VALIDATOR" indexType="btree">
            <column name="validator"/>
        </index>
        <index referenceId="MST_FEED_VALIDATION_SEVERITY" indexType="btree">
            <column name="severity"/>
        </index>
    </table>
    <!-- AI-assisted feed optimization (PROP-0218 / pm#837). No FK from mst_feed_ai_value to
         catalog_product_entity: the entity reference is polymorphic (entity_type + entity_id). -->
    <table name="mst_feed_ai_profile" resource="default" engine="innodb" comment="mst_feed_ai_profile">
        <column xsi:type="int" name="profile_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Profile Id"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Name"/>
        <column xsi:type="varchar" name="code" nullable="false" length="64" comment="Output code; feeds reference it as ai:&lt;code&gt;"/>
        <column xsi:type="varchar" name="entity_type" nullable="false" length="32" default="product" comment="Entity Type (product/category/review)"/>
        <column xsi:type="varchar" name="attribute_code" nullable="false" length="255" comment="Target attribute/field"/>
        <column xsi:type="varchar" name="kind" nullable="false" length="32" comment="text_rewrite/category_mapping/attribute_enrichment"/>
        <column xsi:type="text" name="prompt" nullable="true" comment="Prompt instruction; may interpolate product attributes"/>
        <column xsi:type="varchar" name="provider" nullable="true" length="64" comment="Core AI provider (null = default)"/>
        <column xsi:type="varchar" name="model" nullable="true" length="128" comment="Model (null = provider default)"/>
        <column xsi:type="longtext" name="settings_serialized" nullable="true" comment="Kind-specific and run options"/>
        <column xsi:type="smallint" name="is_active" padding="5" unsigned="true" nullable="false" identity="false" default="1" comment="Is Active"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
        <column xsi:type="datetime" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="profile_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="MST_FEED_AI_PROFILE_CODE">
            <column name="code"/>
        </constraint>
        <index referenceId="MST_FEED_AI_PROFILE_ATTRIBUTE_CODE" indexType="btree">
            <column name="attribute_code"/>
        </index>
    </table>
    <table name="mst_feed_ai_profile_feed" resource="default" engine="innodb" comment="mst_feed_ai_profile_feed">
        <column xsi:type="int" name="id" padding="10" unsigned="true" nullable="false" identity="true" comment="Id"/>
        <column xsi:type="int" name="profile_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Profile Id"/>
        <column xsi:type="int" name="feed_id" padding="11" unsigned="false" nullable="false" identity="false" default="0" comment="Feed Id"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="id"/>
        </constraint>
        <!-- Abbreviated: the full <table>_<col>_<ref_table>_<ref_col> name is 66 chars,
             above MySQL's 64-char identifier limit. -->
        <constraint xsi:type="foreign" referenceId="MST_FEED_AI_PRF_FEED_PROFILE_ID_MST_FEED_AI_PRF_PROFILE_ID" table="mst_feed_ai_profile_feed" column="profile_id"
                    referenceTable="mst_feed_ai_profile" referenceColumn="profile_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="MST_FEED_AI_PROFILE_FEED_FEED_ID_MST_FEED_FEED_FEED_ID" table="mst_feed_ai_profile_feed" column="feed_id"
                    referenceTable="mst_feed_feed" referenceColumn="feed_id" onDelete="CASCADE"/>
        <constraint xsi:type="unique" referenceId="MST_FEED_AI_PROFILE_FEED_PROFILE_ID_FEED_ID">
            <column name="profile_id"/>
            <column name="feed_id"/>
        </constraint>
        <index referenceId="MST_FEED_AI_PROFILE_FEED_FEED_ID" indexType="btree">
            <column name="feed_id"/>
        </index>
    </table>
    <table name="mst_feed_ai_value" resource="default" engine="innodb" comment="mst_feed_ai_value">
        <column xsi:type="int" name="value_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Value Id"/>
        <column xsi:type="int" name="profile_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Profile Id"/>
        <column xsi:type="varchar" name="entity_type" nullable="false" length="32" default="product" comment="Entity Type (polymorphic)"/>
        <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Entity Id (no FK; pruned by runs)"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false" default="0" comment="Store Id"/>
        <column xsi:type="varchar" name="attribute_code" nullable="false" length="255" comment="Output attribute"/>
        <column xsi:type="varchar" name="source_hash" nullable="false" length="64" comment="Hash of full model input"/>
        <column xsi:type="varchar" name="profile_hash" nullable="false" length="64" comment="Hash of profile settings"/>
        <column xsi:type="mediumtext" name="original_value" nullable="true" comment="Raw source value at generation time"/>
        <column xsi:type="mediumtext" name="value" nullable="true" comment="Optimized output — what feeds read"/>
        <column xsi:type="mediumtext" name="pending_value" nullable="true" comment="Manual approve mode: awaiting approval"/>
        <column xsi:type="varchar" name="status" nullable="false" length="16" default="ok" comment="ok/failed"/>
        <column xsi:type="text" name="error" nullable="true" comment="Failure message"/>
        <column xsi:type="int" name="tokens" padding="10" unsigned="true" nullable="true" identity="false" comment="Approx per-item share of batch tokens"/>
        <column xsi:type="smallint" name="is_overridden" padding="5" unsigned="true" nullable="false" identity="false" default="0" comment="1 = merchant override"/>
        <!-- Snapshot of the source entity's updated_at when this value was produced. Recomputing
             source_hash means rendering the prompt, which cannot be expressed in SQL, so finding
             stale work over a large catalog would mean rendering every candidate on every cron
             launch. This column is the cheap SQL gate: only rows whose entity changed since are
             candidates, and only those get a hash recomputed. -->
        <column xsi:type="datetime" name="source_updated_at" on_update="false" nullable="true" comment="Source entity updated_at when the value was produced"/>
        <!-- When the orphan sweep last compared this row's entity against the catalog. The sweep is a
             bounded drip, so it needs a cursor that survives a process: ordering by it (NULLs first)
             and stamping what was examined is what makes successive launches rotate through the whole
             table instead of re-diffing the same head forever. Deliberately NOT `updated_at`, which the
             results grid shows to the merchant as when the VALUE last changed. -->
        <column xsi:type="datetime" name="swept_at" on_update="false" nullable="true" comment="Orphan sweep last examined this row's entity"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
        <column xsi:type="datetime" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="value_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_AI_VALUE_PROFILE_ID_MST_FEED_AI_PROFILE_PROFILE_ID" table="mst_feed_ai_value" column="profile_id"
                    referenceTable="mst_feed_ai_profile" referenceColumn="profile_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="MST_FEED_AI_VALUE_STORE_ID_STORE_STORE_ID" table="mst_feed_ai_value" column="store_id"
                    referenceTable="store" referenceColumn="store_id" onDelete="CASCADE"/>
        <constraint xsi:type="unique" referenceId="MST_FEED_AI_VALUE_PROFILE_ID_ENTITY_ID_STORE_ID_ATTRIBUTE_CODE">
            <column name="profile_id"/>
            <column name="entity_id"/>
            <column name="store_id"/>
            <column name="attribute_code"/>
        </constraint>
        <index referenceId="MST_FEED_AI_VALUE_ENTITY_TYPE_ENTITY_ID" indexType="btree">
            <column name="entity_type"/>
            <column name="entity_id"/>
        </index>
        <index referenceId="MST_FEED_AI_VALUE_PROFILE_ID_SOURCE_HASH" indexType="btree">
            <column name="profile_id"/>
            <column name="source_hash"/>
        </index>
        <!-- Drives the portion query and the coverage counters: every work category is selected
             per (profile, store) and discriminated by status. -->
        <index referenceId="MST_FEED_AI_VALUE_PROFILE_ID_STORE_ID_STATUS" indexType="btree">
            <column name="profile_id"/>
            <column name="store_id"/>
            <column name="status"/>
        </index>
        <!-- The sweep's cursor: read the least-recently-examined rows of one (profile, store) in order. -->
        <index referenceId="MST_FEED_AI_VALUE_PROFILE_ID_STORE_ID_SWEPT_AT" indexType="btree">
            <column name="profile_id"/>
            <column name="store_id"/>
            <column name="swept_at"/>
        </index>
    </table>
    <table name="mst_feed_ai_run" resource="default" engine="innodb" comment="mst_feed_ai_run">
        <column xsi:type="int" name="run_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Run Id"/>
        <column xsi:type="int" name="profile_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Profile Id"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="true" identity="false" comment="Store Id (null = all applicable store views)"/>
        <column xsi:type="varchar" name="status" nullable="false" length="50" default="running" comment="running/done/failed"/>
        <column xsi:type="int" name="total" padding="10" unsigned="true" nullable="true" identity="false" comment="Pending work at launch start"/>
        <column xsi:type="int" name="processed" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Processed"/>
        <column xsi:type="int" name="failed" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Failed"/>
        <!-- Items the launch resolved without a model call: the fill mode left their own value alone, or
             their stored answer was still current. Recorded because throughput and the token average are
             per item RESOLVED, not per item generated — without it a profile that skips 100 items a minute
             for free looked like it was making no progress, and its ETA ran to hours. -->
        <column xsi:type="int" name="skipped" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Needed no AI call"/>
        <column xsi:type="int" name="tokens" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Run total tokens"/>
        <!-- Tokens are the only spend figure reported. Mirasvit Core AI exposes token usage but no
             pricing — there is no $/token table anywhere — so a monetary column could only ever hold
             a number this module invented and would silently rot as provider prices change. -->
        <column xsi:type="text" name="message" nullable="true" comment="Last status/error line"/>
        <column xsi:type="datetime" name="started_at" on_update="false" nullable="true" comment="Started At"/>
        <column xsi:type="datetime" name="finished_at" on_update="false" nullable="true" comment="Finished At"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
        <column xsi:type="datetime" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="run_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="MST_FEED_AI_RUN_PROFILE_ID_MST_FEED_AI_PROFILE_PROFILE_ID" table="mst_feed_ai_run" column="profile_id"
                    referenceTable="mst_feed_ai_profile" referenceColumn="profile_id" onDelete="CASCADE"/>
        <index referenceId="MST_FEED_AI_RUN_PROFILE_ID_CREATED_AT" indexType="btree">
            <column name="profile_id"/>
            <column name="created_at"/>
        </index>
        <index referenceId="MST_FEED_AI_RUN_STATUS" indexType="btree">
            <column name="status"/>
        </index>
    </table>
    <table name="mst_feed_ai_phrase" resource="default" engine="innodb" comment="mst_feed_ai_phrase">
        <column xsi:type="int" name="phrase_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Phrase Id"/>
        <column xsi:type="varchar" name="kind" nullable="false" length="32" comment="category_mapping (v1)"/>
        <column xsi:type="varchar" name="phrase_hash" nullable="false" length="64" comment="Hash of normalized phrase (incl. output language)"/>
        <column xsi:type="text" name="phrase" nullable="false" comment="Source phrase (for admin inspection)"/>
        <column xsi:type="text" name="result" nullable="true" comment="Validated taxonomy path, or NO_FITS"/>
        <column xsi:type="int" name="tokens" padding="10" unsigned="true" nullable="true" identity="false" comment="Tokens"/>
        <column xsi:type="datetime" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
        <column xsi:type="datetime" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="phrase_id"/>
        </constraint>
        <constraint xsi:type="unique" referenceId="MST_FEED_AI_PHRASE_KIND_PHRASE_HASH">
            <column name="kind"/>
            <column name="phrase_hash"/>
        </constraint>
    </table>
</schema>
