【问题标题】:Can I create an initial CodeIgniter db migration from .sql?我可以从 .sql 创建初始 CodeIgniter 数据库迁移吗?
【发布时间】:2013-03-01 00:08:07
【问题描述】:

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

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

【问题讨论】:

    标签: mysql codeigniter migration


    【解决方案1】:

    回复有点晚,但我破解了一个快速库,它应该从您当前的数据库中为您生成基本迁移文件。它仍然是测试版,但适用于我的系统 40 个表+

    https://github.com/liaan/codeigniter_migration_base_generation

    左:

    【讨论】:

    • 这很好,但有一个大问题,那就是它只考虑键中的 PK,而不是(复合)唯一或 FK。
    【解决方案2】:

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

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

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

    https://github.com/williamknauss/schema_base_model_magic

    这允许您自动化 CRUD 模型操作和架构

    【讨论】:

    【解决方案3】:

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

    你会得到类似 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);
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多