Add dummy content when running migrations |
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 { 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'; PHP Code: $this->migration->version(5); Thanks in advance (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. You can access the $this->db object so you can insert anything what you want with $this->db->insert() or $this->db->update(). 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 (10-05-2015, 07:09 AM)orionstar Wrote: You can access the $this->db object so you can insert anything what you want with $this->db->insert() or $this->db->update(). Thank you for your reply. About the timestamps, I'm afraid you didn't understood me.. The documentation says: Quote:Each Migration is run in numeric order forward or backwards depending on the method taken. If I set the migration type to Timestamp, do I have to run Code: $this->migration->version(5); with the timestamp or just the number of the migration ? Also if I have set timestamps to migrations, do I have to generate somehow a timestamp in order to apply in to the name of the file etc? do something like this for instance PHP Code: echo date('YmdHis'); (10-05-2015, 07:30 AM)Lykos22 Wrote:(10-05-2015, 07:09 AM)orionstar Wrote: You can access the $this->db object so you can insert anything what you want with $this->db->insert() or $this->db->update(). If you are using sequential based migrations then you specify a number, if you use timestamp based migrations you have to use the full timestamp. Quote:Then in application/config/migration.php set $config['migration_version'] = 20121031100537;. You can auto generate the timestamp or you can create it manually, for example I have a CLI tool for autogenerating migrations with properly formatted filename, CI not support this from out of box. |
Welcome Guest, Not a member yet? Register Sign In |