我可以从.sql创建初始CodeIgniter数据库迁移吗?

时间:2013-03-13 06:58:24

标签: mysql codeigniter migration

我有一个CodeIgniter应用程序,我刚刚了解了迁移。这听起来非常有用,我想开始使用它。但是我已经有了相当复杂的数据库设置。有人可以建议一种合理的方法从我的MYSQL .sql架构文件创建可靠的初始迁移吗?

使用dbforge手动重新创建整个数据库似乎过分,但也许这就是我应该做的。

3 个答案:

答案 0 :(得分:10)

迟到的回复,但我攻击了一个快速库,它应该从当前的数据库中为您生成基本迁移文件。它仍然是测试版,但可以在我的系统上运行40个表+

https://github.com/liaan/codeigniter_migration_base_generation

L:

答案 1 :(得分:0)

我手动搞乱了SQL文件,然后我发现了Jamie Rumbelow的模式库。它使得架构操作比DBForge更容易管理,但仍然需要手动输入。

https://github.com/jamierumbelow/codeigniter-schema

有人提出了他的基础模型和模式库的混搭,它使原型设计更快

https://github.com/williamknauss/schema_base_model_magic

这允许您自动化CRUD模型操作&模式

答案 2 :(得分:0)

访问https://github.com/fastworkx/ci_migrations_generator

您会得到类似以下的应用程序/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);
}
相关问题