PHP code example of fishingboy / codeigniter-migration
1. Go to this page and download the library: Download fishingboy/codeigniter-migration library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fishingboy / codeigniter-migration example snippets
use fishingboy\ci_migration\CI_Migration_Controller;
class Migration extends CI_Migration_Controller {
}
use fishingboy\ci_migration\CI_Migration_Library;
class CI_Migration extends CI_Migration_Library {
}
$config['migration_enabled'] = true;
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);
}
}
shell
$ 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
shell
$ php index.php migration ls
Version Status File
--- -------------- ------ ------------------------------------
1. 20190815002100 -- application/migrations/20190815002100_create_logs_tables.php
--- -------------- ------ ------------------------------------
0 Migration not execute.
shell
$ php index.php migration migrate
Migration Run : Migration_Create_sample_tables::up() ............. OK !
shell
$ php index.php migration rollback
Migration Run : Migration_Create_sample_tables::down() ............. OK !
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.