Yii Framework Forum: Test data in db migration - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Test data in db migration Rate Topic: -----

#1 User is offline   dhampik 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 25-January 11
  • Location:Russia

Posted 02 February 2011 - 08:35 AM

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?
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,778
  • Joined: 17-January 09
  • Location:Russia

Posted 02 February 2011 - 08:42 AM

If testing server = unit tests then you can use fixtures. Else you can insert data using Yii::app()->db->createCommand or models as usual.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   dhampik 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 25-January 11
  • Location:Russia

Posted 02 February 2011 - 10:25 AM

View Postsamdark, on 02 February 2011 - 08:42 AM, said:

If testing server = unit tests then you can use fixtures. Else you can insert data using Yii::app()->db->createCommand or models as usual.

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.
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,778
  • Joined: 17-January 09
  • Location:Russia

Posted 02 February 2011 - 10:30 AM

Well, then like this:

function up(){
  $post = new Post();
  $post->id = 10;
  $post->title = "test record";
  $post->save();
}

Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   Mihai Petrescu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 25-June 12

  Posted 16 March 2014 - 12:48 AM

I have also encountered the exact same problem.

	public function up()
	{
		print_r($this->getDbConnection());
		$top_menu = new \Menu;
		$top_menu->name = "Top Menu";
		$top_menu->internal = "top";
		$top_menu->saveNode();
	}

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
	$this->insert('Page', array(
	        "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?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users