Reputation: 1707
I have a CodeIgniter application and I just learned about migrations. It sounds very useful and I would like to start using it. However I already have a rather complex database setup. Can someone suggest a reasonable way to create a reliable initial migration from my MYSQL .sql schema file?
It seems excessive to manually recreate the entire db with dbforge, but perhaps that's what I ought to do.
Upvotes: 8
Views: 5660
Reputation: 36
Visit https://github.com/fastworkx/ci_migrations_generator
You'll get something like this applications/migration/001_create_base.php.
public function up() {
## Create Table sis_customer
$this->dbforge->add_field(array(
'id' => array(
'type' => 'VARCHAR',
'constraint' => 40,
'null' => FALSE,
),
'ip_address' => array(
'type' => 'VARCHAR',
'constraint' => 45,
'null' => FALSE,
),
'timestamp' => array(
'type' => 'INT',
'unsigned' => TRUE,
'null' => FALSE,
'default' => '0',
),
'data' => array(
'type' => 'BLOB',
'null' => FALSE,
),
'`datetime_reg` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ',
));
$this->dbforge->create_table("sessions", TRUE);
$this->db->query('ALTER TABLE `sessions` ENGINE = InnoDB');
));
public function down() {
### Drop table sessions ##
$this->dbforge->drop_table("sessions", TRUE);
}
Upvotes: 1
Reputation: 531
Bit late reply, but I hacked a quick library that should generate the base migration file for you from your current DB. Its still beta, but works on my systems 40 tables+
https://github.com/liaan/codeigniter_migration_base_generation
L:
Upvotes: 11
Reputation: 1858
I was messing around with SQL files manually and then I discovered Jamie Rumbelow's schema library. It makes schema operation a little bit easier to manage then DBForge but still requires manual entry.
https://github.com/jamierumbelow/codeigniter-schema
Someone came up with a mashup of his base model and schema library and it makes prototyping much faster
https://github.com/williamknauss/schema_base_model_magic
this allows you to automate the CRUD model operations & schema
Upvotes: 0