Last active
August 29, 2015 14:16
-
-
Save ftassi/804dded435ead9d67ab7 to your computer and use it in GitHub Desktop.
Database sharding with doctrine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function onConsoleCommand(ConsoleCommandEvent $event) | |
{ | |
$shardManager = new PoolingShardManager($connection); | |
$shard = $input->getParameterOption(['--shard', '-s']); | |
if ('global' === $shard) { | |
} else { | |
$shardManager->selectGlobal(); | |
$shardManager->selectShard($shard); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctrine: | |
dbal: | |
default_connection: default | |
connections: | |
default: | |
driver: "%database_driver%" | |
host: "%database_host%" | |
port: "%database_port%" | |
dbname: "%database_name%" | |
user: "%database_user%" | |
password: "%database_password%" | |
charset: UTF8 | |
shards: | |
foo: | |
id: 1 | |
host: '%database_host%' | |
user: '%database_user%' | |
password: '%database_password%' | |
dbname: nuvolamc12345678 | |
charset: UTF8 | |
bar: | |
id: 2 | |
host: '%database_host%' | |
user: '%database_user%' | |
password: '%database_password%' | |
dbname: mcps015006 | |
charset: UTF8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$shardManager = new PoolingShardManager($conn); ! | |
$currentCustomerId = 1234; | |
// all queries after this call hit the shard | |
// where customer with id 1234 is on. | |
$shardManager->selectShard($currentCustomerId); | |
// select the global database | |
$shardManager->selectGlobal(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment