dsaru/goya 问题修复 & 功能扩展

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

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

dsaru/goya

Composer 安装命令:

composer require dsaru/goya

包简介

Database Schema Diff Tool for Laravel

README 文档

README

Goya is a simple database schema management tool for Laravel. Goya output diffs between schema definition files and database schemas, apply them to the database.

To make diff of a schema, Goya uses Doctrine DBAL. Schema definition files are described in DBAL Schema Representation.

Using Goya

Create schema definition files (Recipes).
For how to describe schemas, see DBAL Docmentations.

$ cat app/database/recipes/UserTable.php
<?php

use Dsaru\Goya\Recipe;
use Doctrine\DBAL\Schema\Schema;

class UserTable extends Recipe
{

	public function schema() {
		$table = $this->schema->createTable('user');

		$table->addColumn( 'id',             'integer',  ['autoincrement' => true, 'unsigned' => true] );
		$table->addColumn( 'name',           'string',   ['length' => 32] );
		$table->addColumn( 'created_at',     'datetime', [] );
		$table->addColumn( 'updated_at',     'datetime', [] );
		$table->addColumn( 'deleted_at',     'datetime', ['notnull' => false, 'default' => null] );

		$table->setPrimaryKey(['id']);
	}

}

There has been no definitions yet in the actual database.

$ mysql -uroot yourdb 
mysql> show tables;
Empty set (0.00 sec)

If you run goya command, a SQL is generated from the schema definition files.

$ php artisan goya
CREATE TABLE user (id INT UNSIGNED AUTO_INCREMENT NOT NULL, name VARCHAR(32) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

you may apply it to the actual database with goya:cook command.

$ php artisan goya:cook

$ mysql -uroot yourdb 
mysql> desc user;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name       | varchar(32)      | NO   |     | NULL    |                |
| created_at | datetime         | NO   |     | NULL    |                |
| updated_at | datetime         | NO   |     | NULL    |                |
| deleted_at | datetime         | YES  |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

Now, add profile column definition to the schema definition file.

$table->addColumn( 'profile',        'string',   ['length' => 1000] );

Run goya command again.

$ php artisan goya
ALTER TABLE user ADD profile VARCHAR(1000) NOT NULL

Installation

Add this package name to composer.json.

"require": {
    ...,
    "dsaru/goya": "dev-master"
}

Run composer update.

Open app/config/app.php, and add the Service Provider.

'providers' => array(
 	..
	'Dsaru\Goya\GoyaServiceProvider', 
),

Writing Recipes

Schema definition files (Recipes) are put in app/database/recipes.
You may describe multiple table definitions in a single file. Or, it may be split into multiple files.

Recipe files are need to be named like [ClassName].php. Create a class which extends \Dsaru\Goya\Recipe in the file, and describe database table schemas in schema method.

class MyTables extends \Dsaru\Goya\Recipe
{
	public function schema() {
		// write database definitions here
	}
}

When you use multiple recipe files, you may need to control the order of the loading files.
Because recipes are loaded in alphabetical order, it will work well if they are named like 001_[ClassName]].php002_[ClassName].php.

Author

daisaru11 <daisaru11@gmail.com>

dsaru/goya 适用场景与选型建议

dsaru/goya 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 2, 最近一次更新时间为 2014 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-11-23