rubenv / rubenv/sql-migrate

Could not create trigger on MySQL

Open
#71 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
3.4k
Forks
292
PR merge metrics
No merged PRs in 30d

Description

`
-- +migrate Up

CREATE TABLE device_groups ...
CREATE TABLE devices ...

-- +migrate StatementBegin
delimiter |

CREATE TRIGGER update_devicegroup_devices_on_insert AFTER INSERT ON devices
FOR EACH ROW
BEGIN
UPDATE device_groups SET devices = (SELECT COUNT(*) FROM devices WHERE device_group_id = NEW.device_group_id) WHERE id = NEW.device_group_id;
END
|

delimiter ;
-- +migrate StatementEnd

-- +migrate Down
DROP TABLE IF EXISTS devices CASCADE;
DROP TABLE IF EXISTS device_groups CASCADE;
`

Using bindata

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delimiter |

CREATE TRIGGER update_devicegroup_devices_on_insert AFTER INSERT ON' at line 2 handling 003_reinit.sql

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with 003_reinit.sql and reproduce the bindata migration against MySQL. Inspect how sql-migrate processes the delimiter and StatementBegin/StatementEnd sections around the trigger. Done means the migration runs without MySQL error 1064 and creates the trigger successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, mysql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.