Skip to content
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.

add support for custom delimiter in mysql migrations #39

Closed
wants to merge 1 commit into from
Closed

add support for custom delimiter in mysql migrations #39

wants to merge 1 commit into from

Conversation

phemmer
Copy link

@phemmer phemmer commented Mar 18, 2015

This implements a solution for #38

It basically adds support for the migration file including delimiter foo in the first line, and using foo as the delimiter for multiple statements.

Yes, this is a hack, but it solves the issue, and doesn't introduce new syntax (delimiter foo is valid for mysql CLI)

@mattes
Copy link
Owner

mattes commented Mar 18, 2015

Thanks for your PR. Not sure if I got it right. DELIMITER just changes the ; symbol to something else. Could you give an example how that would work with multiple statements?

@phemmer
Copy link
Author

phemmer commented Mar 18, 2015

This is one of our migrations which is using it:

delimiter "\n--\n"

CREATE TABLE session_event (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    type ENUM('insert','update') NOT NULL,
    session_id BIGINT UNSIGNED NOT NULL
) engine=InnoDB

--

CREATE TRIGGER session_insert AFTER INSERT ON session
FOR EACH ROW
BEGIN
    INSERT INTO session_event SET type='insert', session_id=NEW.id;
    SET @event_id = LAST_INSERT_ID();
    SET @event_id_min = GREATEST(@event_id, 1000) - 1000;
    DELETE FROM session_event WHERE id < @event_id_min;
END

--

CREATE TRIGGER sesion_update AFTER UPDATE ON session
FOR EACH ROW
BEGIN
    INSERT INTO session_event SET type='update', session_id=NEW.id;
    SET @event_id = LAST_INSERT_ID();
    SET @event_id_min = GREATEST(@event_id, 1000) - 1000;
    DELETE FROM session_event WHERE id < @event_id_min;
END

@mattes
Copy link
Owner

mattes commented Mar 23, 2015

@mattes mattes mentioned this pull request Mar 23, 2015
@phemmer
Copy link
Author

phemmer commented Mar 23, 2015

I don't see how that is relevant. The issue isn't executing multiple statements, the issue is executing statements with a semicolon in them.

@mattes
Copy link
Owner

mattes commented Mar 23, 2015

I think by implementing ziutek/mymysql we don't need any workarounds for delimiters.

@phemmer
Copy link
Author

phemmer commented Mar 23, 2015

I don't think it'll have any bearing on the issue. The package might have better support for multiple SQL statements, but I still see no way to change the delimiter.

@phemmer
Copy link
Author

phemmer commented Nov 18, 2015

Closing this since it seems to have gone stale. We've also switched to another migration tool which among other things, has support for custom statement delimiters.

@phemmer phemmer closed this Nov 18, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants