Is there an easy way to manipulate existing data in migration scripts ?
I have a parameters column where parameters are separated by ";". I want to add a new parameter, so I want to update existing values (add ;0 at the end of the string).
Can I update using existing values in the column ?
You can simply create a loop in which you read the existing rows and write them back with the new values.
It can be written using DAO, or ActiveRecord if you prefer.
You mean using models ?
I think that migration scripts should not rely on PHP models. By definition, database may not be synchronized with models.
It is probably better to use directly a sql statement, but I wondered if there was a dedicated method to do such update.
Ah, yes. I just wrote a quick and dirty way that I usually do for me in the migrations. I don’t want to spend much time writing them and don’t care much about the performance.
Probably this may satisfy you.
update your-table set your-field = concat(your-field, ":0");
This should work for mysql. Wow, it’s far easier.
Yes, I was considering something like that. But as you said, I’m not sure it is compatible with all DB.
I think I’m going to fill a new feature request.