【发布时间】:2013-03-01 00:08:07
【问题描述】:
我有一个 CodeIgniter 应用程序,我刚刚了解了迁移。这听起来很有用,我想开始使用它。但是我已经有一个相当复杂的数据库设置。有人可以建议一种合理的方法来从我的 MYSQL .sql 架构文件创建可靠的初始迁移吗?
用 dbforge 手动重新创建整个数据库似乎有些过分,但也许这就是我应该做的。
【问题讨论】:
标签: mysql codeigniter migration
我有一个 CodeIgniter 应用程序,我刚刚了解了迁移。这听起来很有用,我想开始使用它。但是我已经有一个相当复杂的数据库设置。有人可以建议一种合理的方法来从我的 MYSQL .sql 架构文件创建可靠的初始迁移吗?
用 dbforge 手动重新创建整个数据库似乎有些过分,但也许这就是我应该做的。
【问题讨论】:
标签: mysql codeigniter migration
回复有点晚,但我破解了一个快速库,它应该从您当前的数据库中为您生成基本迁移文件。它仍然是测试版,但适用于我的系统 40 个表+
https://github.com/liaan/codeigniter_migration_base_generation
左:
【讨论】:
我手动处理 SQL 文件,然后我发现了 Jamie Rumbelow 的模式库。它使模式操作比 DBForge 更易于管理,但仍需要手动输入。
https://github.com/jamierumbelow/codeigniter-schema
有人想出了一个他的基础模型和模式库的混搭,它使原型设计更快
https://github.com/williamknauss/schema_base_model_magic
这允许您自动化 CRUD 模型操作和架构
【讨论】:
访问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);
}
【讨论】: