runcmf/runcli 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

runcmf/runcli

Composer 安装命令:

composer require runcmf/runcli

包简介

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

README 文档

README

Build Status Coverage Status Code Climate Latest Version on Packagist Total Downloads Software License

#RunCli ##Standalone command line interface.

migrate, seed, generate migrations, models and seeds from existing database, generate resources, create database

supported driver mysql, pgsql, sqlite

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

$ psql --version
psql (PostgreSQL) 9.4.9

$ sqlite3
SQLite version 3.8.2 2013-12-06 14:53:30

main objective was generate Eloquent ORM migrations from existing database outside Laravel in my case Eloquent ORM used with Slim 3 Framework

Install

$ 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

config must contain ['settings']['db'] section. for example:

defined('DS') || define('DS', DIRECTORY_SEPARATOR);
define('DIR', realpath(__DIR__.'/../../') .DS);

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'   => '',
        ],
      ],
    ],
    ...
    ...
    ...

Usage:

Seed & Migrate

php bin/cli migrate:fill

example

php bin/cli seed:fill

example

Generate migration from existing database:

redone from Xethron with part of code doctrine/dbal but without Laravel, way/generators

php bin/cli migrate:generate

example ###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

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

with migrate exception:

[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):

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

$table->ipAddress('visitor');

solution 3: http://stackoverflow.com/questions/17795517/laravel-4-saving-ip-address-to-model

Generate seeds from existing database:

redone from orangehill/iseed

php bin/cli seed:generate

example

Generate models from existing database:

redone from user11001/eloquent-model-generator

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

example

Create database

php bin/cli make:db [schema] [charset] [collation]

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

$ 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.

Credits

License

Apache License Version 2.0

runcmf/runcli 适用场景与选型建议

runcmf/runcli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 08 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「cli」 「migration」 「Eloquent ORM」 「slim3」 「slim 3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 runcmf/runcli 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 runcmf/runcli 我们能提供哪些服务?
定制开发 / 二次开发

基于 runcmf/runcli 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 36
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache
  • 更新时间: 2016-08-06