Transaction handling
Closed this issue · 1 comments
prolic commented
create a db and table first:
CREATE DATABASE test;
use test;
CREATE TABLE `event_streams` (
`real_stream_name` VARCHAR(150) COLLATE utf8_bin NOT NULL,
`stream_name` CHAR(41) COLLATE utf8_bin NOT NULL,
`metadata` JSON,
UNIQUE KEY `ix_rsn` (`real_stream_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
then this:
START TRANSACTION;
INSERT INTO `event_streams` (real_stream_name, stream_name, metadata)
VALUES ("Prooph\\Model\\User", "_878c0b7e51ecaab95c511fc816ad2a70c9418208", "[]");
CREATE TABLE `_878c0b7e51ecaab95c511fc816ad2a70c9418208` (
`no` INT(11) NOT NULL AUTO_INCREMENT,
`event_id` CHAR(36) COLLATE utf8_bin NOT NULL,
`event_name` VARCHAR(100) COLLATE utf8_bin NOT NULL,
`payload` JSON NOT NULL,
`metadata` JSON NOT NULL,
`created_at` CHAR(26) COLLATE utf8_bin NOT NULL,
`version` INT(11) GENERATED ALWAYS AS (JSON_EXTRACT(metadata, '$._aggregate_version')) STORED NOT NULL UNIQUE KEY,
`aggregate_id` char(38) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS (JSON_EXTRACT(metadata, '$._aggregate_id')) STORED NOT NULL UNIQUE KEY,
`aggregate_type` varchar(150) GENERATED ALWAYS AS (JSON_EXTRACT(metadata, '$._aggregate_type')) STORED NOT NULL,
PRIMARY KEY (`no`),
UNIQUE KEY `ix_unique_event` (`version`, `aggregate_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
INSERT INTO _878c0b7e51ecaab95c511fc816ad2a70c9418208 (event_id, event_name, payload, metadata, created_at) VALUES ("c6d34fc7-25ef-41ad-a9f5-441a9c368466", "ProophTest\EventStore\Mock\UserCreated", "{\"firstName\":\"Fritz\",\"lastName\":\"Heinz\"}", "{\"_aggregate_version\":1}", "2016-11-09T12:30:13.666800"), ("9305a022-c535-45a6-be01-d02b678edc92", "ProophTest\EventStore\Mock\UsernameChanged", "{\"firstName\":\"582316d5a2e0c\",\"lastName\":\"582316d5a2e44\"}", "{\"_aggregate_version\":2}", "2016-11-09T12:30:13.667200"), ("502303ac-ee92-4c94-92b5-e86b06bd0df9", "ProophTest\EventStore\Mock\UsernameChanged", "{\"firstName\":\"582316d5a2ebb\",\"lastName\":\"582316d5a2ef1\"}", "{\"_aggregate_version\":3}", "2016-11-09T12:30:13.667400"), ("4039a7fb-5d70-4c5c-a1e2-fa3412ca0e4d", "ProophTest\EventStore\Mock\UserCreated", "{\"firstName\":\"Fritz\",\"lastName\":\"Heinz\"}", "{\"_aggregate_version\":4}", "2016-11-09T12:30:13.667400");
COMMIT;
Problem: create table makes implicit commit in MySQL !!!
This means transactions are broken with MySQL!
see also: http://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html
One possible solution would be to remove $adapter->beginTransaction()
, $adapter->commit()
and $adapter->rollback()
methods and make transaction handling implicit instead of explicit, so that I can catch this and remove the newly created table.
Multiple $adapter->create()
calls within a single transaction is still possible with postgres, but impossible with MySQL.
prolic commented
ping @codeliner