3

I have often noticed that when database insert for a model fails, data loaded previously continue to stay in the database. So when you try to load the same fixture file again, it gives an error.

Is there any way the DATA:LOAD process can be made ATOMIC, i.e. GO or NO-GO for all data, so that data is never inserted half-way.

1
  • 2
    I also had the same problem. I think we should add a bug to symfony. any more agree on this?
    – llazzaro
    Jun 8, 2011 at 18:21

2 Answers 2

0

Hopefully that should work :

Write a task that do the same as data:load but wrap it in :

$databaseManager = new sfDatabaseManager($this->configuration);
$conn = $sf_database_managaer->getDatabase('doctrine')->getDoctrineConnection();
try{

...............


}catch(Exception $e){ //maybe you can be more specific about the exception thrown
    echo $e->getMessage();
    $conn->rollback();
}
-1

Fixtures are meant for loading initial data, which means that you should be able to build --all --and-load, or in other words, clear all data and re-load fixtures. It doesn't take any longer.

One option you have is to break your fixtures into multiple files and load them individually. This is also what I'd do if you first need to load large amounts of data via a script or from a CSV (i.e. something bigger than just a few fixtures). This way you don't need to redo it if you had a fixtures problem somewhere else.

3
  • You are not getting the point here. We need the task to rollback incase there is a SQL error at any point. Breaking into multiple files is not always an option due to dependencies across models.
    – Prasad
    Jul 19, 2011 at 6:40
  • @Prasad: And I'm telling you that there's no need for a rollback because you can re-build. Whatever you can do with one fixture file, you can also do with multiple fixture files.
    – Tom
    Jul 19, 2011 at 7:52
  • I would not like it to work that way. Fixtures should also allow you to load incremental data without disturbing existing data. And if there is a problem in the loading, you expect it to rollback, and not create a partial mess.
    – Prasad
    Aug 25, 2011 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.