February 2, 2011, 1:35pm
Database migration is a very good tool. That is great, that we have it in yii
But I have a conceptual question about it.
Usually there are 2 types of DB schema needed:
one is an empty db (tables only, with no test data) with only some tables initially filled (which act like dictionaries)
the other is the schema with test data
Empty tables are needed for production server, but test data is needed for testing server and local development.
Can anyone explain how can this be organized with migration mechanism in yii?
Maybe we need to use 2 migrations directories? Who this can be organized better?
How do you guys handle this in your everyday projects?
February 2, 2011, 1:42pm
If testing server = unit tests then you can use fixtures. Else you can insert data using Yii::app()->db->createCommand or models as usual.
February 2, 2011, 3:25pm
Oh, I should have use another term. Under "testing server" I mean "demo server".
So we have 2 DB - one with demo data (to generate demo content on the site, for example, demo news, posts, etc) and another DB schema with no demo data.
And I am inerested how to handle 2 versions of DB with migrations mechanism.
February 2, 2011, 3:30pm
Well, then like this:
$post = new Post();
$post->id = 10;
$post->title = "test record";
I have also encountered the exact same problem.
public function up()
$top_menu = new \Menu;
$top_menu->name = "Top Menu";
$top_menu->internal = "top";
The print_r shows me that the db connection is [connectionString] => mysql:host=localhost;dbname=yii_test
yet the model is saved in the yii database, not in yii_test.
Now I have tested and this works properly
"name" => 'About Us',
"url" => '/about-us',
"template" => 'about-us',
"content" => null,
My problem is that the Menu model is more complicated and I cannot do a $this->insert, I have to calculate a lot of preorder stuff to put in the correct values. And if I want to change anything then I have to recalculate everything all over again. Is there a way to make the normal active record work?