nextras / migrations

Powerful database migrations focused on reliability
https://nextras.org/migrations
Other
101 stars 40 forks source link

error executing migration (create trigger, delimiter set), but SQL code runs in any SQL management tool #73

Closed dakorpar closed 7 years ago

dakorpar commented 7 years ago

so consider this code:

DROP TRIGGER IF EXISTS stock_products_BEFORE_INSERT;

DELIMITER |
CREATE TRIGGER stock_products_BEFORE_INSERT BEFORE INSERT ON stock_products
FOR EACH ROW
BEGIN
DECLARE msg VARCHAR(255);
    if new.purchase_price = 0 then
        SET msg = concat('Cannot INSERT row: purchase price cannot be 0 - stock_product_id:', new.id);

        SIGNAL SQLSTATE '45000'
        set MESSAGE_TEXT= msg;
    end if;
    if new.purchase_price is null AND new.is_approved=1 then
        SET msg = concat('Cannot INSERT row: purchase price cannot be NULL - stock_product_id:', new.id);
        SIGNAL SQLSTATE '45000'
         SET MESSAGE_TEXT = msg;
    end if;  
    if new.original_purchase_price = 0 then
        SET msg = concat('Cannot INSERT row: original purchase price cannot be 0 - stock_product_id:', new.id);
        SIGNAL SQLSTATE '45000'
        SET MESSAGE_TEXT = msg;
    end if;
END |

running it in any SQL management tool like mysql workbench works perfectly well. But it allways return error on migration and I couldn't be able to fix it. I use dibi driver and allways get:

fatal error: Uncaught Dibi\DriverException: You have an error in your SQL syntax; check the manual that corresponds t o your MariaDB server version for the right syntax to use near 'DELIMITER | CREATE TRIGGER stock_products_BEFOREINSERT BEFORE INSERT ON stock' at line 1

JanTvrdik commented 7 years ago

Version?

dakorpar commented 7 years ago

v3.1.0-rc3

dakorpar commented 7 years ago

@JanTvrdik thanks when can we expect new rc release or 3.1?

JanTvrdik commented 7 years ago

@dakorpar In few days.