tags:

views:

607

answers:

2

i have to work with an existing database (not managed with doctrine) and i want to use doctrine only for new tables in this db.

is there a way to tell doctrine to not drop the entire db on reload but only the models defined in the yaml file ?

A: 

Yes, surely you can use doctrine only for some tables(not all). And it won't drop all the other tables., unless you manually run

$manager->dropDatabases();

This is how you can start using Doctine for your new tables:

  1. Setup DB Connection

  2. Setup Doctrine's files/directory structure

  3. Use Command Line Interface in order to automatically generate all Doctrine models(and schema) based on DB tables(you can delete unncessesary models manually).

Fedyashev Nikita
the problem is that there's no command line option to build all (re)load without dropping existing database
gpilotino
@gpilotino: Don't Do That Then! Just build-schema, build-model etc. Or write a task to do what you need to do.
dland
ok but still you cannot do this with command line (dropping all tables). finally i had to write some code to cycle on them.
gpilotino
A: 

@ gpilotino Yes, I'm having a similar problem. There seems to be NO WAY to drop and rebuild the database from within PHPUnit, (The future of Symfony testing).

Maybe it's possible in 'lime',I don't know.

So, I am having to write a reverse ->save() function that backs all the data out of the database, and then resets all the sequences so that I can do automated testing.

For those who don't want to follow in my frustration I tried both:

1) using a Task from inside of symfony:

  $optionsArray=array();

$argumentsArray=array();

$optionsArray[]="--all"; $optionsArray[]="--and-load"; $optionsArray[]="--no-confirmation";

$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter()); $task->run($argumentsArray, $optionsArray);

2)Executing it from outside of symfony while inside of PHP:

  Doctrine_Manager::getInstance()->getCurrentConnection()->close();

exec('./symfony doctrine:build --all --and-load --no-confirmation');

The reason that I closed the connection is that Postgres, MDBOC (my db of choice) will not drop a database that has a connection. Probably is STILL some kind of problem. I tell ya, it's NEVER as easy as the simple tutorials show. And it's even WORSE with microslop products.