8

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.

3 Answers 3

11

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:

Sign up to request clarification or add additional context in comments.

1 Comment

It is great, but has one big issue, and that is it considers only the PK from keys, not (composite) unique nor FK.
1

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);
}

Comments

0

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

1 Comment

github.com/williamknauss/schema_base_model_magic It is broken, can anyone suggests the updated one?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.