constantly changing DB schema - recommended methodology?

Hi all,

I’ve yet to have the experience to draw a method or procedures to use Yii when your schema is changing across time.

My boss says that the schema will evolve with time rather often so I need to either reproduce the Model files code on each schema changes (using Gii), or, do something else.

Manual editing of Model classes to match the changes in the DB is the least desired option since its time consuming and mostly - error prone.

OTOH, automatic code generation is also not suitable since… mind my inexperience, according to tutorials/documentation I’m supposed to have lots of (biz logic) code in the model files and regeneration of Model classes will drop that to the trash bin.

So, what would be your recommendations on working in such environment?

Don’t tell me to tell the DBA to fixate the DB schema. As much as we all want this - it won’t happen, even if strongly desired (and it is).



Use giix. It will place generated code in the base model file and you will write your code to the model that extends the base model. Painless.

I thought about extending inheritance here.

I guess I’ll need to research a bit about Giix to learn why I cannot do this double level of inheritance by myself, and… well I’ve seen enough links to giix to justify short acquittance with it in any case.

Any other recommendation?

Yes, I know ;)

giix just does that automatically. Nothing that you can’t do by yourself with gii with manual adjustments.

Automation is a very good justification. Don’t underestimate it!

And forgot earlier - thanks for the input!

Thanks for the tip - I always forget that I can use Giix.

I am seriously wondering if I should convert to using that. I tend to forget to update my models accordingly.

Would be nice if that process could be automated when running the migrate command. :)

I wonder if that’s possible?

Yes, I love the level of automation that giix gives me. I don’t have to worry with a lot of things.

And you’re welcome!

Yes. Maybe with a behavior.

Lets talk about it. Open an issue at Google Code.

This is my personal opinion:

The only reason i can see, why someone would like to recreate their models after a schema change are the validation rules (maybe also relations). I would never trust any machine that creates these rules for me. So to me this is always a matter of manual interaction.

Hi Mike,

Regarding the trust in the generated code, I agree with you.

I always review the generated code.

But I keep generating it, since reviewing it is faster than writing it.

And the model rules and relations generated by gii are very good, adjustments are usually not needed.

True… it’s easier to just check the generated code… but that regards only the first time you create the table when there are many fields…

if you just add one or two fields to the table… IMO is much faster to just add the necessary code for those fields manually… rules, label names, and form inputs…