PHPackages                             aniart-solutions/bitrix-migrations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. aniart-solutions/bitrix-migrations

ActiveLibrary[Database &amp; ORM](/categories/database)

aniart-solutions/bitrix-migrations
==================================

Database migrations for Bitrix CMS

v1.2.0(1w ago)17MITPHPPHP &gt;=8.1.0,&lt;8.5.0

Since Mar 9Pushed 1w agoCompare

[ Source](https://github.com/aniart-solutions/bitrix-migrations)[ Packagist](https://packagist.org/packages/aniart-solutions/bitrix-migrations)[ Docs](https://github.com/aniart-solutions/bitrix-migrations)[ RSS](/packages/aniart-solutions-bitrix-migrations/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/2f3df34c68aeb72966f03021acc4b828ff562f18e4cd70a04cf6fdbd04330c38/68747470733a2f2f706f7365722e707567782e6f72672f616e696172742d736f6c7574696f6e732f6269747269782d6d6967726174696f6e732f762f737461626c652e737667)](https://packagist.org/packages/aniart-solutions/bitrix-migrations/)[![Total Downloads](https://camo.githubusercontent.com/0ba3386486533267c3b7d04666a8c33a2bd46f76e9d3c626ea4dbcf6935b69a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e696172742d736f6c7574696f6e732f6269747269782d6d6967726174696f6e732e7376673f7374796c653d666c6174)](https://packagist.org/packages/aniart-solutions/bitrix-migrations)[![License](https://camo.githubusercontent.com/c4102b42cbe060d09abc688dbd6d759e42acd87d5468a5b1c92a03fa79facb20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616e696172742d736f6c7574696f6e732f6269747269782d6d6967726174696f6e732e7376673f7374796c653d666c6174)](https://packagist.org/packages/aniart-solutions/bitrix-migrations)[![PHP Version](https://camo.githubusercontent.com/39186d8f30c2d344f47862fc3e7a13c1cf80165ba95794da298bb8594abd6385/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616e696172742d736f6c7574696f6e732f6269747269782d6d6967726174696f6e732e7376673f7374796c653d666c6174)](https://packagist.org/packages/aniart-solutions/bitrix-migrations)

Bitrix-migrations
=================

[](#bitrix-migrations)

*Database migrations for Bitrix CMS and more*

Installation
------------

[](#installation)

1. `composer require aniart-solutions/bitrix-migrations`
2. `cp vendor/aniart-solutions/bitrix-migrations/migrator migrator` - copy the executable file to a convenient location.
3. Open the file and make sure that `$_SERVER['DOCUMENT_ROOT']` is set correctly. Change settings if needed.
4. `php migrator install`

This command will create a table in the database to store the names of executed migrations.

By default:

1. The table is called `migrations`.
2. `composer.json` and `migrator` are located in the site root.
3. Migration files will be created in the `./migrations` directory relative to the file copied in step 2.

If necessary, all of this can be changed in the copied `migrator` file.

- It is highly recommended to make `migrator` and `./migrations` inaccessible via HTTP through the web server. \*

Usage
-----

[](#usage)

### Workflow

[](#workflow)

The workflow is done through the console and is briefly described as follows:

1. Create a migration file (or files) using `php migrator make migration_name`

A migration file is a class with two methods: `up()` and `down()`

2. Implement the necessary database changes in the `up()` method. Optionally, implement rollback of these changes in the `down()` method.
3. Apply available migrations - `php migrator migrate`
4. Add migration files to version control so they can be run on other machines.

### Available Commands

[](#available-commands)

You can get a list of available commands in the console - `php migrator list`

CommandDescription `php migrator install` Creates a table to store migrations. Run once. `php migrator make migration\_name`  Creates a migration file Options:
 `-d foo/bar` - specify a subdirectory in which the migration will be created
  `php migrator migrate` Applies all available migrations. Previously applied migrations are not applied. `php migrator rollback`  Rolls back the last migration (the `down()` method). After that, it can be applied again.
 Options:
 `--hard` - perform a hard rollback without calling the `down()` method
 `--delete` - delete the migration file after rollback.
  `php migrator templates` Shows a detailed table with all existing migration templates `php migrator status` Shows available migrations to run, as well as the last executed ones. `php migrator archive`  Moves all migrations to archive. By default, this is the `archive` directory, but it can be overridden in the config by specifying "dir\_archive"
 Options:
 `-w 10` - do not archive the last N migrations
 ### Migration Templates

[](#migration-templates)

Since changing the Bitrix database structure through its API is extremely unpleasant, there is a migration template mechanism to facilitate this process, which works as follows: When generating a migration file, you can specify its template: `php migrator make migration_name -t add_iblock` where `add_iblock` is the template name. A class with a boilerplate from the template will be generated and you only need to specify the details (for example, the name and code of the infoblock) You can add your own migration templates directly in the `migrator` file using `TemplateCollection::registerTemplate()`

Available templates:

NameDescriptionAliases `default` Clean default template  `add\_iblock\_type` Adding an infoblock type  `add\_iblock` Adding an infoblock  `add\_iblock\_element\_property` Adding a property to an infoblock `add\_iblock\_prop`, `add\_iblock\_element\_prop`, `add\_element\_prop`, `add\_element\_property` `add\_uf` Adding a UF property  `query` Custom database query via D7 API  `add\_table` Creating a table via D7 API `create\_table` `delete\_table` Deleting a table via D7 API `drop\_table`### Automatic Migration Creation

[](#automatic-migration-creation)

Another killer feature is the automatic migration creation mode. To enable it, add something like the following to `init.php`

```
AniartSolutions\BitrixMigrations\Autocreate\Manager::init($_SERVER["DOCUMENT_ROOT"].'/migrations');
```

The path to the directory similar to the config in the `migrator` file is passed to the `Manager::init()` method.

After that, when performing a number of actions in the admin panel, the following will happen:

1. A Bitrix event handler is triggered
2. A migration file is created as with `php migrator make`
3. The migration is marked as applied
4. A notification about the previous points is shown

Enabling this mode allows you to get rid of manually writing migrations for many cases. Nothing needs to be edited in automatically created migrations.

List of handled events:

EventComments Adding an infoblock  Updating infoblock base fields Due to the specifics of the Bitrix admin panel, this migration is often created when it's not needed, for example when adding a custom property to an infoblock. Nothing fatal, but you have to accept it. Deleting an infoblock  Adding a custom property to an infoblock  Updating an infoblock custom property Migration is created only if any of the property attributes were changed Deleting an infoblock custom property  Adding a UF property anywhere (infoblock section, user, highload block) Unfortunately, Bitrix does not allow tracking changes to such a property - only addition and deletion Deleting a UF property  Adding a highload block  Updating a highload block Migration is created only if any of the highload block attributes were changed Deleting a highload block  Adding a user group  Updating a user group  Deleting a user group - Migrations use `OnBefore...` events. If an error occurred during your change (for example, the site binding was not specified when adding an infoblock) and a notification was shown that the migration was created, you must manually rollback such a migration using `php migrator rollback --hard --delete` \*

### Migration Error Handling

[](#migration-error-handling)

To cancel a migration during its execution, it is enough to throw an exception - `php throw new MigrationException('Error text here');`Neither the migration itself nor subsequent ones will be applied.

Usage Outside Bitrix
--------------------

[](#usage-outside-bitrix)

The package is created for use with Bitrix, but it can be easily used in other systems as well. To do this, you need to in the `migrator` file:

1. Replace the Bitrix core connection with the core of another system.
2. Implement your own analogue of `AniartSolutions\BitrixMigrations\Repositories\BitrixDatabaseRepository;` and use it.
3. Optionally disable existing migration templates by creating your own.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance98

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

12d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/48c31322a3ea3600210d5fd498107fd892069dfb27f8c1f0ddf7f54128cb3c2f?d=identicon)[aniart-solutions](/maintainers/aniart-solutions)

---

Top Contributors

[![burcev-alex](https://avatars.githubusercontent.com/u/11717148?v=4)](https://github.com/burcev-alex "burcev-alex (2 commits)")

---

Tags

bitrixmigrations

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aniart-solutions-bitrix-migrations/health.svg)

```
[![Health](https://phpackages.com/badges/aniart-solutions-bitrix-migrations/health.svg)](https://phpackages.com/packages/aniart-solutions-bitrix-migrations)
```

###  Alternatives

[doctrine/migrations

PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.

4.8k200.9M369](/packages/doctrine-migrations)[doctrine/doctrine-migrations-bundle

Symfony DoctrineMigrationsBundle

4.3k174.5M461](/packages/doctrine-doctrine-migrations-bundle)[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k45.4M373](/packages/robmorgan-phinx)[lulco/phoenix

Database Migrations for PHP

178324.9k4](/packages/lulco-phoenix)[masom/lhm

Large Hadron Migrator for phinx

319.3k](/packages/masom-lhm)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
