承接 codengine/laravel-custom-migrations 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

codengine/laravel-custom-migrations

最新稳定版本:v1.3.0

Composer 安装命令:

composer require codengine/laravel-custom-migrations

包简介

Custom Migrations for Laravel

README 文档

README

Build Status Coverage Status Latest Stable Version Scrutinizer Code Quality Documentation Status Total Downloads Dependency Status

Run separate Laravel migrations on multiple databases

This package provides a simple way of including different types of migrations over multiple databases. A common use case would be that you are running a main database and separate databases for each customer.

It is a bit painful to run each migration independently for each database connection. You are also not able to differ which migration is responsible for which type of migration.

Custom Migrations to the Aid!

Compatibility

Laravel Version Version
4.x 1.0.*
5.0 1.1.*
5.1 1.2.*
5.2 1.3.*

Installation

To install this package, simply put the following into your composer.json

{
    "require": {
        "codengine/laravel-custom-migrations": "1.3.*"
    }
}

or for Laravel 4.x:

{
    "require": {
        "codengine/laravel-custom-migrations": "1.0.*"
    }
}

After updating composer, replace the default Laravel Migration Service Provider

'Illuminate\Database\MigrationServiceProvider',

with

'Codengine\CustomMigrations\CustomMigrationsServiceProvider',

You should then update the laravel autoload files with

php artisan dump-autoload

Configuration

In your database.php file, you have to specify the type of the database which will later be used to decide which migrations apply for them. Here is an example:

'my_customer' => array(
	'driver'    => 'mysql',
	'host'      => 'localhost',
	'database'  => 'customer',
	'username'  => 'customer',
	'password'  => '',
	'charset'   => 'utf8',
	'collation' => 'utf8_unicode_ci',
	'prefix'    => '',
	'migration_type' => 'customer'
)		

The important part is "migration_type". It does not have to be unique.

Usage

Each migration file needs to be type-hinted as we need to differ between default migrations and custom ones.

You have to specify the type of the migration in your migration class like this:

class MyMigration {
    public $type = "customer";
    
    public function up(){
    ....
}

It has to be public and should be the same as in your database configuration. If a $type is not specified, the migration will only be used for the default database.

Running Custom Migrations

As this package only extends the Laravel commands, every command like "migrate", "rollback", "reset" and "refresh" works like it did before.

There is just one difference: Each command got a new option: --type=xyz. So, in order to run the "customer" migrations for each customer-related database you just have to execute the command like this:

php artisan migrate --type=customer
php artisan migrate:rollback --type=customer
php artisan migrate:refresh --type=customer
php artisan migrate:reset --type=customer

It will iterate over each customer database connection and run the applicable migrations.

You can also limit the migration to just one database using the --database option like this

php artisan migrate --type=customer --database=mySpecialCustomer

License

The Laravel Custom Migrations Package is open-sourced software licensed under the MIT license

统计信息

  • 总下载量: 1.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 6
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-16