Welcome Guest, Not a member yet? Register   Sign In
Add dummy content when running migrations
#2

(10-05-2015, 02:11 AM)Lykos22 Wrote: Hi all, I'd like some feedback please, if possible. I'm using CI v3 and I was wondering whether there's a way I could enter some dummy content on the tables I generate running through Migrations.

For instance when I run this migration


PHP Code:
class Migration_Add_blog extends CI_Migration {

 
       public function up()
 
       {
 
               $this->dbforge->add_field(array(
 
                       'blog_id' => array(
 
                               'type' => 'INT',
 
                               'constraint' => 5,
 
                               'unsigned' => TRUE,
 
                               'auto_increment' => TRUE
                        
),
 
                       'blog_title' => array(
 
                               'type' => 'VARCHAR',
 
                               'constraint' => '100',
 
                       ),
 
                       'blog_description' => array(
 
                               'type' => 'TEXT',
 
                               'null' => TRUE,
 
                       ),
 
               ));
 
               $this->dbforge->add_key('blog_id'TRUE);
 
               $this->dbforge->create_table('blog');
 
       }

 
       public function down()
 
       {
 
               $this->dbforge->drop_table('blog');
 
       }


Is there also a way I could enter a few dummy blog posts to see as an example ?

One additional question regarding the Migrations. If I have the migrations types set as
PHP Code:
$config['migration_type'] = 'timestamp'
when I run this command
PHP Code:
$this->migration->version(5); 
do I have to enter the full timestamp or just the number version and if so how can I get the timestamp ?

Thanks in advance

You can access the $this->db object so you can insert anything what you want with $this->db->insert() or $this->db->update(). Wink

About the timestamp: you have to find out a timestamp what follows the format (YYYYMMDDHHIISS -> 20121031100537) and append the name of the migration. But you should read the docs if you're not lazy... See http://www.codeigniter.com/user_guide/li...ation.html
Reply


Messages In This Thread
RE: Add dummy content when running migrations - by orionstar - 10-05-2015, 07:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB