<?xml version="1.0" encoding="utf-8"?>

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
     <changeSet author="suhuiguang" id="1587367889717-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_point" columnName="last_check_id"/>
            </not>
        </preConditions>
        <comment>p_point ADD COLUMN last_check_id</comment>
        <sql>
             ALTER TABLE p_point ADD COLUMN `last_check_id` varchar(32) DEFAULT NULL COMMENT '最近检查记录（漏检不算）' AFTER `original_id`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-1" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="check_type"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN check_type</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `check_type` varchar(32) DEFAULT NULL COMMENT '检查类别' AFTER `test_requirement`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-2" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_parent"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_parent</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_parent` varchar(50) DEFAULT NULL COMMENT '父类检查项id' AFTER `check_type`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-3" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_classify"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_classify</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_classify` varchar(50) DEFAULT NULL COMMENT '检查项分类' AFTER `item_parent`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-4" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_type_classify"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_type_classify</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_type_classify` varchar(50) DEFAULT NULL COMMENT '适用检查类别' AFTER `item_classify`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-5" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_level"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_level</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_level` varchar(50) DEFAULT NULL COMMENT '检查项等级' AFTER `item_type_classify`;修改列
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-6" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_start"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_start</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_start` bit(1) DEFAULT b'0' COMMENT '检查项状态' AFTER `item_level`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-1">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_plan_task_detail" columnName="executor_id"/>
        </preConditions>
        <comment>p_plan_task_detail modify column executor_id</comment>
        <sql>
            alter table `p_plan_task_detail` modify column `executor_id` text COMMENT '执行人id' after `status`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="executor_name"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN executor_name</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `executor_name` text DEFAULT null COMMENT '执行人名称' AFTER `executor_id`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="item_num"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN item_num</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `item_num` int(11) DEFAULT 0 COMMENT '检查项个数' AFTER `executor_name`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-4">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="executed_num"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN executed_num</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `executed_num` int(11) DEFAULT 0 COMMENT '已执行个数' AFTER `item_num`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-5">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="safety_danger_num"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN safety_danger_num</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `safety_danger_num` int(11) DEFAULT 0 COMMENT '安全隐患个数' AFTER `executed_num`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-6">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="major_danger_num"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN major_danger_num</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `major_danger_num` int(11) DEFAULT 0 COMMENT '重大隐患个数' AFTER `safety_danger_num`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629863569-1">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_plan_task_detail" columnName="is_finish"/>
        </preConditions>
        <comment>p_plan_task_detail modify column is_finish</comment>
        <sql>
            alter table `p_plan_task_detail` modify column `is_finish` int(11) COMMENT '0-未开始，1-执行中，2-已完成，3-超时漏检(有一个检查项漏检则为漏检)' after `create_date`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629886127-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check" columnName="company_id"/>
            </not>
        </preConditions>
        <comment>p_check ADD COLUMN company_id</comment>
        <sql>
            ALTER TABLE `p_check` ADD COLUMN `company_id` varchar(32) DEFAULT NULL COMMENT '责任单位id' AFTER `dep_name`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629886127-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check" columnName="company_name"/>
            </not>
        </preConditions>
        <comment>p_check ADD COLUMN company_name</comment>
        <sql>
            ALTER TABLE `p_check` ADD COLUMN `company_name` varchar(255) DEFAULT NULL COMMENT '责任单位名称' AFTER `company_id`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629886127-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check_input" columnName="safety_danger_num"/>
            </not>
        </preConditions>
        <comment>p_check_input ADD COLUMN safety_danger_num</comment>
        <sql>
            ALTER TABLE `p_check_input` ADD COLUMN `safety_danger_num` int(11) DEFAULT NULL COMMENT '安全隐患个数' AFTER `danger_handle_state`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629886127-4">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check_input" columnName="major_danger_num"/>
            </not>
        </preConditions>
        <comment>p_check_input ADD COLUMN major_danger_num</comment>
        <sql>
            ALTER TABLE `p_check_input` ADD COLUMN `major_danger_num` int(11) DEFAULT NULL COMMENT '重大隐患个数' AFTER `safety_danger_num`;
        </sql>
    </changeSet>
</databaseChangeLog>