2017 © Pedro Peláez
 

library runcli

RunCli - Command Line Interface. [migrate, seed, generate migrations and seeds from existing database, create database, generate resources and much more :)]

image

runcmf/runcli

RunCli - Command Line Interface. [migrate, seed, generate migrations and seeds from existing database, create database, generate resources and much more :)]

  • Sunday, January 8, 2017
  • by 1f7
  • Repository
  • 1 Watchers
  • 0 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Build Status Coverage Status Code Climate Latest Version on Packagist Total Downloads ![Software License][ico-license], (*1)

RunCli

Standalone command line interface.

migrate, seed, generate migrations, models and seeds from existing database, generate resources, create database, (*2)

supported driver mysql, pgsql, sqlite, (*3)

``` bash $ mysql -V mysql Ver 15.1 Distrib 10.1.16-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2, (*4)

$ psql --version psql (PostgreSQL) 9.4.9, (*5)

$ sqlite3 SQLite version 3.8.2 2013-12-06 14:53:30, (*6)


main objective was generate [Eloquent ORM](https://github.com/illuminate/database) migrations from existing database outside [Laravel](https://github.com/laravel/laravel) in my case [Eloquent ORM](https://github.com/illuminate/database) used with [Slim 3 Framework](https://github.com/slimphp/Slim) ## Install ``` bash $ composer require runcmf/runcli
  • copy or ln -s cli to scripts_root/bin

Config:

script looking config in paths:
app/Config/Settings.php runcmf/runcmf-skeleton
app/settings.php akrabat/slim3-skeleton, (*7)

config must contain ['settings']['db'] section. for example: ``` php defined('DS') || define('DS', DIRECTORY_SEPARATOR); define('DIR', realpath(DIR.'/../../') .DS);, (*8)

return [ 'settings' => [ 'displayErrorDetails' => true, 'determineRouteBeforeAppMiddleware' => true, 'addContentLengthHeader' => false, 'routerCacheFile' => DIR . 'var/cache/fastroute.cache', 'db' => [// database configuration 'default' => 'sqlite', 'connections' => [ 'sqlite' => [ 'driver' => 'sqlite', 'database' => DIR . 'var/database/database.sqlite', 'prefix' => 'mybb_', ], 'mysql' => [ 'driver' => 'mysql', // 'engine' => 'MyISAM', 'engine' => 'InnoDB', 'host' => '127.0.0.1', 'database' => 'run', 'username' => 'dbuser', 'password' => '123', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => 'mybb_', ], 'pgsql' => [ 'driver' => 'pgsql', 'host' => '127.0.0.1', 'database' => 'run', 'username' => 'dbuser', 'password' => '123', 'charset' => 'utf8', 'prefix' => 'mybb_', 'schema' => 'public', ], 'sqlsrv' => [ 'driver' => 'sqlsrv', 'host' => '127.0.0.1', 'database' => 'run', 'username' => 'dbuser', 'password' => '123', 'prefix' => '', ], ], ], ... ... ..., (*9)


# Usage: ## Seed & Migrate ``` bash php bin/cli migrate:fill

example ``` bash php bin/cli seed:fill, (*10)

![example](ss/ss2.png "seed fill")

## Generate migration from existing database:
> redone from [Xethron](https://github.com/Xethron/migrations-generator) with part of code doctrine/dbal but **without** Laravel, way/generators 

``` bash
php bin/cli migrate:generate

example, (*11)

Generator info:

Know problems:

`regip` varbinary(16) NOT NULL DEFAULT '',
`lastip` varbinary(16) NOT NULL DEFAULT '',

with keys
ADD KEY `regip` (`regip`),
ADD KEY `lastip` (`lastip`);

migrated to, (*12)

$table->binary('regip', 16)->default('')->index('regip');
$table->binary('lastip', 16)->default('')->index('lastip');

with migrate exception:, (*13)

[Illuminate\Database\QueryException]                                                                                                                                                        
  SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'regip' used in key specification without a key length (SQL: alter table `mybb_users` add index `regip`(`regip`))

solution 1: if you want use binary(16):, (*14)

comment index
$table->binary('regip', 16)->default('');//->index('regip');
$table->binary('lastip', 16)->default('');//->index('lastip');

and add in `up` section
DB::statement('CREATE INDEX regip_idx ON '.DB::getTablePrefix().'users (regip(16));');
DB::statement('CREATE INDEX lastip_idx ON '.DB::getTablePrefix().'users (lastip(16));');

and add in `down` section
DB::schema()->table('users', function($table) {
  $table->dropIndex('regip_idx');
});
DB::schema()->table('users', function($table) {
  $table->dropIndex('lastip_idx');
});

solution 2: refactor your code with ipAddress Eloquent ORM ipAddress, (*15)

$table->ipAddress('visitor');

solution 3: http://stackoverflow.com/questions/17795517/laravel-4-saving-ip-address-to-model, (*16)

Generate seeds from existing database:

redone from orangehill/iseed, (*17)

``` bash php bin/cli seed:generate, (*18)

![example](ss/ss4.png "seed generate")  


## Generate models from existing database:
> redone from [user11001/eloquent-model-generator](https://github.com/pepijnolivier/Eloquent-Model-Generator)

``` bash
php bin/cli model:generate --namespace='YourNameSpace\Models'

example, (*19)

Create database

``` bash php bin/cli make:db [schema] [charset] [collation], (*20)

schema - OPTIONAL, schema name from config or exception generated on empty config value;  
charset - OPTIONAL, default value [MySQL = **utf8**, PostgreSQL = **UTF8**];  
collation - OPTIONAL, default value [MySQL = **utf8_general_ci**, PostgreSQL = **en_US.UTF-8**];  


## Tests
```bash
$ cd vendor/runcmf/runtracy
$ composer update
$ vendor/bin/phpunit

Security

If you discover any security related issues, please email to 1f7.wizard( at )gmail.com instead of using the issue tracker., (*21)

Credits

  • https://github.com/1f7
  • http://runetcms.ru
  • http://runcmf.ru

License

Apache License Version 2.0, (*22)

The Versions

08/01 2017

dev-master

9999999-dev

RunCli - Command Line Interface. [migrate, seed, generate migrations and seeds from existing database, create database, generate resources and much more :)]

  Sources   Download

Apache 2

The Requires

 

The Development Requires

database migration cli slim 3 slim3 eloquent orm runcmf generate migrations

23/12 2016

0.1.1

0.1.1.0

RunCli - Command Line Interface. [migrate, seed, generate migrations and seeds from existing database, create database, generate resources and much more :)]

  Sources   Download

Apache 2

The Requires

 

The Development Requires

database migration cli slim 3 slim3 eloquent orm runcmf generate migrations

04/12 2016

0.1.0

0.1.0.0

RunCli - Command Line Interface. [migrate, seed, generate migrations and seeds from existing database, create database, generate resources and much more :)]

  Sources   Download

Apache 2

The Requires

 

database migration cli slim 3 slim3 eloquent orm runcmf