{"id":19382977,"url":"https://github.com/elao/commandmigration","last_synced_at":"2025-04-23T20:32:36.605Z","repository":{"id":56976227,"uuid":"138278268","full_name":"Elao/CommandMigration","owner":"Elao","description":"Library to run migration commands, for example on deployment","archived":false,"fork":false,"pushed_at":"2019-01-15T13:24:13.000Z","size":28,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-02T20:11:44.244Z","etag":null,"topics":["continuous-integration","deployment","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Elao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-22T08:43:10.000Z","updated_at":"2024-05-29T12:56:20.000Z","dependencies_parsed_at":"2022-08-21T11:20:29.654Z","dependency_job_id":null,"html_url":"https://github.com/Elao/CommandMigration","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elao%2FCommandMigration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elao%2FCommandMigration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elao%2FCommandMigration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elao%2FCommandMigration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Elao","download_url":"https://codeload.github.com/Elao/CommandMigration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250509899,"owners_count":21442518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["continuous-integration","deployment","symfony"],"created_at":"2024-11-10T09:24:03.928Z","updated_at":"2025-04-23T20:32:35.552Z","avatar_url":"https://github.com/Elao.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CommandMigration\n\nPHP library to run commands, for example on deployment.\n\n## Why\n\nSometimes, on deployment or when switching to a branch, we need to run some migration commands,\nfor example reindex a database, calculate aggregation, remove whatever uploaded files...\n\nDo not do it manually anymore by connecting to your server in ssh!\nThis library allow you to declare in your feature git branch what command(s) need to be run once deployed.\n\n## Install\n\n    $ composer require elao/command-migration\n**Enable the bundle on Symfony \u003c= 3.4 (app/AppKernel.php)**\n      \n    public function registerBundles()\n    {\n        $bundles = array(\n            // ...\n            new Elao\\CommandMigration\\Bridge\\Symfony\\Bundle\\CommandMigrationBundle(),\n            // ...\n        );\n    }\n\n**Enable the bundle on Symfony 4 (config/bundles.php)**\n    \n    return [\n        // ...\n        Elao\\CommandMigration\\Bridge\\Symfony\\Bundle\\CommandMigrationBundle::class =\u003e ['all' =\u003e true],\n        // ...\n    ];\n\nAdd a `elao_command_migration.yaml` file (in a not public directory of course!):\n\n```yaml\nelao_command_migration:\n    storage:\n        type: dbal\n        dsn: '%env(DATABASE_DSN)%'\n        table_name: 'command_migrations'\n    migrations: []\n```\n\n## Usage\n\nDeclare what command(s) need to be run in the `migrations` entry in your `elao_command_migration.yaml` file:\n\n```yaml\nelao_command_migration:\n    # ...\n    migrations:\n        whateverUniqueIdentifier:\n            - php bin/console app:posts:reindex\n        20180510173033:\n            - php bin/console app:posts:reindex\n            - php bin/console doctrine:migrations:migrate\n        20180622110900:\n            - php bin/console app:posts:reindex\n            - node hello-world.js\n            - php bin/console doctrine:schema:update --force\n            - rm -rf public/uploads/lolcats\n            - php bin/console app:recalculate:turnover\n```\n\nEntries in `migrations` could have whatever identifier, but we recommend to use a date + time format: YYYYMMDDHHMMSS\n\nRun `php bin/elao-command-migration path/to/elao_command_migration.yaml` to test it.\n\n## Integration\n\nAdd `php bin/elao-command-migration path/to/elao_command_migration.yaml`\nto your deployment process.\n\n### Capifony\n\nSet in deploy.rb:\n\n```rb\n    after :deploy, 'app_tasks:elao_command_migration'\n\n    namespace :app_tasks do\n      task :elao_command_migration do\n        capifony_pretty_print \"--\u003e Run command migrations\"\n        invoke_command \"php bin/elao-command-migration path/to/elao_command_migration.yaml\", :via =\u003e run_method\n        capifony_puts_ok\n      end\n    end\n```\n\n### Ansible\n\nWith [Manala/ansible-role-deploy](https://github.com/manala/ansible-role-deploy), add in `ansible/group_vars/deploy.yml`:\n\n```yaml\n    manala_deploy_tasks:\n      - command: php bin/elao-command-migration path/to/elao_command_migration.yaml\n```\n\nor\n\n```yaml\n    manala_deploy_post_tasks:\n      - command: php bin/elao-command-migration path/to/elao_command_migration.yaml\n```\n\n## How it works\n\nCommandMigration is very inspired by [Doctrine Migrations](https://github.com/doctrine/migrations) but\nfor running commands.\n\nThe `elao:command-migration:run` command :\n\n- Fetch all migrations already ran from `command_migrations` database table\n- Get only migrations not already ran from `elao_command_migration.migrations`\n- Store migration identifier in `command_migrations` database table.\n\n## Clean old migrations\n\nWhen the commands have been deployed and ran on production environment, you can (manually) delete the entries in\n`elao_command_migration.migrations`.\n\n## Who is using it?\n\n- [Vimeet](https://vimeet.events/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felao%2Fcommandmigration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felao%2Fcommandmigration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felao%2Fcommandmigration/lists"}