<?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">
    <!-- one row per execution of a monitored job / sub-feed -->
    <table name="autogedal_feed_monitor_run" resource="default" engine="innodb" comment="Feed monitor - executions">
        <column xsi:type="int" name="run_id" unsigned="true" nullable="false" identity="true"/>
        <column xsi:type="varchar" name="job_code" length="100" nullable="false"/>
        <column xsi:type="varchar" name="feed_code" length="100" nullable="false" default="" comment="Sub-feed, empty for the whole job"/>
        <column xsi:type="varchar" name="status" length="16" nullable="false" default="running" comment="running / ok / error"/>
        <column xsi:type="varchar" name="problem" length="32" nullable="true" comment="fetch / invalid / empty / incomplete / exception / stuck"/>
        <column xsi:type="datetime" name="started_at" nullable="false"/>
        <column xsi:type="datetime" name="finished_at" nullable="true"/>
        <column xsi:type="int" name="items_read" unsigned="true" nullable="true"/>
        <column xsi:type="int" name="items_updated" unsigned="true" nullable="true"/>
        <column xsi:type="text" name="message" nullable="true"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="run_id"/>
        </constraint>
        <index referenceId="AUTOGEDAL_FEED_MONITOR_RUN_JOB_FEED_STARTED" indexType="btree">
            <column name="job_code"/>
            <column name="feed_code"/>
            <column name="started_at"/>
        </index>
        <index referenceId="AUTOGEDAL_FEED_MONITOR_RUN_STATUS_STARTED" indexType="btree">
            <column name="status"/>
            <column name="started_at"/>
        </index>
    </table>

    <!-- alert state per monitored key (job, job:sub-feed, magento_cron) -->
    <table name="autogedal_feed_monitor_state" resource="default" engine="innodb" comment="Feed monitor - alert state">
        <column xsi:type="varchar" name="monitor_key" length="210" nullable="false"/>
        <column xsi:type="smallint" name="alert_open" unsigned="true" nullable="false" default="0"/>
        <column xsi:type="varchar" name="problem" length="32" nullable="true"/>
        <column xsi:type="text" name="message" nullable="true"/>
        <column xsi:type="datetime" name="first_detected_at" nullable="true"/>
        <column xsi:type="datetime" name="last_notified_at" nullable="true"/>
        <column xsi:type="smallint" name="recovery_pending" unsigned="true" nullable="false" default="0" comment="1 = recovered, recovery email not sent yet"/>
        <column xsi:type="datetime" name="allow_incomplete_until" nullable="true" comment="Until when the next run may be smaller than usual"/>
        <column xsi:type="datetime" name="watched_since" nullable="true" comment="First time the checker saw this key"/>
        <column xsi:type="datetime" name="updated_at" nullable="true"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="monitor_key"/>
        </constraint>
    </table>
</schema>
