-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL Migration with variable #63
Comments
|
I was use Kdyby/Doctrine connection in migration. If i switch to Nette/BD it works well. Funny is they both share PDOConnection from Doctrine. If I call manually: /** @var Kdyby\Doctrine\Connection $connection */
$connection = $em->getConnection();
$connection->exec('SELECT @adminRoleId := id
FROM `user_role`
WHERE `name` = \'administrator\';
INSERT INTO `user_role` (`parent_id`, `name`)
VALUES (@adminRoleId, \'faq\');'); It is OK $connection = $em->getConnection();
$connection->exec('SELECT @adminRoleId := id
FROM `user_role`
WHERE `name` = \'administrator\';');
$connection->exec('INSERT INTO `user_role` (`parent_id`, `name`)
VALUES (@adminRoleId, \'faq\');'); This will fail Is it possible introduce some mechanism in |
Partially related is #52 |
But IMHO solution to your problem is to set session-level variable. |
Maybe https://dev.mysql.com/doc/refman/5.7/en/user-variables.html will help. |
Thanks! Rewrite migration into SET @adminRoleId = (SELECT id
FROM `user_role`
WHERE `name` = 'administrator');
INSERT INTO `user_role` (`parent_id`, `name`)
VALUES (@adminRoleId, 'faq'); Work as expected => done without fail |
Hi, is it possible execute SQL migration with variable?
For example:
It will fail, because N/Migrations exec single queries from file.
Is there some workaround or solution?
The text was updated successfully, but these errors were encountered: