-1

Is it possible to configure Symfony/Doctrine in a way to write data into two different databases (mysql AND oracle) at the same time while reading data only from mysql ? The intention is to have an up to date copy in oracle all the time.

An alternative scenario would be to copy data from mysql to oracle with cron script using Doctrine using a cron script. Would this be possible without modifieing symfony php code ?

Nekudotayim
  • 173
  • 5
  • why use symfony/doctrine at all? just write a CRON and use straight php to create backups using MySQL – craigh Jan 05 '21 at 16:44

1 Answers1

0

You can write to two different DBs and read from just one of them if you want. For that you have to create a separate entity manager for each particular connection. Look at this answer.

Inject the ManagerRegistry to your services and/or controllers to avoid injecting both managers. Like this:

public function __construct(ManagerRegistry $managerRegistry)
{
    $mySqlEm  = $managerRegistry->getManager('default');
    $oracleEm = $managerRegistry->getManager('oracle');
}

Keep in mind what that are synchronous operations and your app will be slower. I suggest you to investigate the mysql/oracle replication for your purposes, maybe something like this.

UPD As Cerad mentioned this approach won't solve the issue because requires separate entities for each manager.

Snegirekk
  • 724
  • 7
  • 12
  • Just be aware that your approach will not work out of the box with Symfony. Symfony's multiple entity manager is seriously broke when trying to use the same entity in multiple managers. – Cerad Jan 05 '21 at 17:54
  • replication was the first approach, but it should be possible to change application db model without changing replication scripts every time. Goal is to keep mysql as a performant "working DB" and have a copy of all data available in oracle for extended reports using different oracle tables.
    So with two entity managers it would be possible to write to both databases without having duplicate calls in code for every persisting query ?
    – Nekudotayim Jan 05 '21 at 18:30
  • @Cerad you're right, this approach requires duplicated entities for each manager, my bad. – Snegirekk Jan 06 '21 at 06:04