elao/command-migration 问题修复 & 功能扩展

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

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

elao/command-migration

Composer 安装命令:

composer require elao/command-migration

包简介

PHP lib to run commands, for example on deployment.

README 文档

README

PHP library to run commands, for example on deployment.

Why

Sometimes, on deployment or when switching to a branch, we need to run some migration commands, for example reindex a database, calculate aggregation, remove whatever uploaded files...

Do not do it manually anymore by connecting to your server in ssh! This library allow you to declare in your feature git branch what command(s) need to be run once deployed.

Install

$ composer require elao/command-migration

Enable the bundle on Symfony <= 3.4 (app/AppKernel.php)

public function registerBundles()
{
    $bundles = array(
        // ...
        new Elao\CommandMigration\Bridge\Symfony\Bundle\CommandMigrationBundle(),
        // ...
    );
}

Enable the bundle on Symfony 4 (config/bundles.php)

return [
    // ...
    Elao\CommandMigration\Bridge\Symfony\Bundle\CommandMigrationBundle::class => ['all' => true],
    // ...
];

Add a elao_command_migration.yaml file (in a not public directory of course!):

elao_command_migration:
    storage:
        type: dbal
        dsn: '%env(DATABASE_DSN)%'
        table_name: 'command_migrations'
    migrations: []

Usage

Declare what command(s) need to be run in the migrations entry in your elao_command_migration.yaml file:

elao_command_migration:
    # ...
    migrations:
        whateverUniqueIdentifier:
            - php bin/console app:posts:reindex
        20180510173033:
            - php bin/console app:posts:reindex
            - php bin/console doctrine:migrations:migrate
        20180622110900:
            - php bin/console app:posts:reindex
            - node hello-world.js
            - php bin/console doctrine:schema:update --force
            - rm -rf public/uploads/lolcats
            - php bin/console app:recalculate:turnover

Entries in migrations could have whatever identifier, but we recommend to use a date + time format: YYYYMMDDHHMMSS

Run php bin/elao-command-migration path/to/elao_command_migration.yaml to test it.

Integration

Add php bin/elao-command-migration path/to/elao_command_migration.yaml to your deployment process.

Capifony

Set in deploy.rb:

    after :deploy, 'app_tasks:elao_command_migration'

    namespace :app_tasks do
      task :elao_command_migration do
        capifony_pretty_print "--> Run command migrations"
        invoke_command "php bin/elao-command-migration path/to/elao_command_migration.yaml", :via => run_method
        capifony_puts_ok
      end
    end

Ansible

With Manala/ansible-role-deploy, add in ansible/group_vars/deploy.yml:

    manala_deploy_tasks:
      - command: php bin/elao-command-migration path/to/elao_command_migration.yaml

or

    manala_deploy_post_tasks:
      - command: php bin/elao-command-migration path/to/elao_command_migration.yaml

How it works

CommandMigration is very inspired by Doctrine Migrations but for running commands.

The elao:command-migration:run command :

  • Fetch all migrations already ran from command_migrations database table
  • Get only migrations not already ran from elao_command_migration.migrations
  • Store migration identifier in command_migrations database table.

Clean old migrations

When the commands have been deployed and ran on production environment, you can (manually) delete the entries in elao_command_migration.migrations.

Who is using it?

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 12
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固