-- +goose Up
DECLARE
    v_count NUMBER;
BEGIN
    SELECT COUNT(*) INTO v_count
      FROM USER_TRIGGERS
     WHERE TRIGGER_NAME = 'TRG_FLASH_VENDAS_BI';

    IF v_count = 0 THEN
        EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER TRG_FLASH_VENDAS_BI
            BEFORE INSERT ON TB_FLASH_VENDAS
            FOR EACH ROW
        BEGIN
            IF :NEW.ID IS NULL THEN
                :NEW.ID := SEQ_FLASH_VENDAS.NEXTVAL;
            END IF;
        END;';
    END IF;
END;

-- +goose Down
DECLARE
    v_count NUMBER;
BEGIN
    SELECT COUNT(*) INTO v_count
      FROM USER_TRIGGERS
     WHERE TRIGGER_NAME = 'TRG_FLASH_VENDAS_BI';

    IF v_count > 0 THEN
        EXECUTE IMMEDIATE 'DROP TRIGGER TRG_FLASH_VENDAS_BI';
    END IF;
END;
