fishingboy / codeigniter-migration
Codeigniter Migration
Installs: 545
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/fishingboy/codeigniter-migration
README
Language
Installation
composer require fishingboy/codeigniter-migration
Usage
-
Create file:
application/controller/Migration.php<?php use fishingboy\ci_migration\CI_Migration_Controller; class Migration extends CI_Migration_Controller { }
-
Create file:
application/libraries/Migration.php<?php use fishingboy\ci_migration\CI_Migration_Library; class CI_Migration extends CI_Migration_Library { }
-
Modify file:
application/config/Migration.php$config['migration_enabled'] = true;
-
Create folder:
application/migrations -
Create migration file : application/migrations/20001010101000_create_sample_tables.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Migration_Create_sample_tables extends CI_Migration { public function up() { $sql = "CREATE TABLE `users` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(20) COMMENT 'name', `created_at` DATETIME NOT NULL , `updated_at` DATETIME NOT NULL , PRIMARY KEY (`id`) ) COMMENT = 'user';"; $this->db->query($sql); } public function down() { $sql = "DROP TABLE `users`"; $this->db->query($sql); } }
-
Migration help:
php index.php migration$ php index.php migration migration php index.php migration -- help php index.php migration migrate -- execute migrations php index.php migration rollback -- rollback to prev migration php index.php migration ls -- check migrations list -
List of migrations
$ php index.php migration ls Version Status File --- -------------- ------ ------------------------------------ 1. 20190815002100 -- application/migrations/20190815002100_create_logs_tables.php --- -------------- ------ ------------------------------------ 0 Migration not execute. -
Execute migration
$ php index.php migration migrate Migration Run : Migration_Create_sample_tables::up() ............. OK !
-
Execute migration rollback
$ php index.php migration rollback Migration Run : Migration_Create_sample_tables::down() ............. OK !