{"id":14966539,"url":"https://github.com/andy87/yii2-migrate-architect","last_synced_at":"2026-02-16T14:32:13.473Z","repository":{"id":246477874,"uuid":"821255852","full_name":"andy87/yii2-migrate-architect","owner":"andy87","description":"Yii2 extension. Migration helper","archived":false,"fork":false,"pushed_at":"2025-03-20T08:11:56.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-25T16:37:38.249Z","etag":null,"topics":["interface","migration","yii2"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andy87.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-28T06:30:51.000Z","updated_at":"2025-03-20T08:11:59.000Z","dependencies_parsed_at":"2025-02-10T19:36:26.482Z","dependency_job_id":"8606f70f-3563-4158-89e6-449e3031f288","html_url":"https://github.com/andy87/yii2-migrate-architect","commit_stats":{"total_commits":22,"total_committers":2,"mean_commits":11.0,"dds":0.2272727272727273,"last_synced_commit":"99c507826cce3f3b5f7abc26e84e52f17f81d309"},"previous_names":["andy87/yii2-migrate-architect"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/andy87/yii2-migrate-architect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andy87%2Fyii2-migrate-architect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andy87%2Fyii2-migrate-architect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andy87%2Fyii2-migrate-architect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andy87%2Fyii2-migrate-architect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andy87","download_url":"https://codeload.github.com/andy87/yii2-migrate-architect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andy87%2Fyii2-migrate-architect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29510165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["interface","migration","yii2"],"created_at":"2024-09-24T13:36:33.860Z","updated_at":"2026-02-16T14:32:13.444Z","avatar_url":"https://github.com/andy87.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003ch1 align=\"center\"\u003eYii2 migrate architect\u003c/h1\u003e\n\nYii2 migrate architect - библиотека для фреймворка Yii2 упрощающая написание кода миграций. \n\nЦель: сделать простой и быстрый инструмент добавления миграций.\n\n### Содержание:\n\n- [Установка](#yii2-migrate-architect-setup)\n- [Использование](#yii2-migrate-architect-use)\n\n___\n\n\u003ch2 align=\"center\"\u003e \u003cspan id=\"yii2-migrate-architect-setup\"\u003e\u003c/span\u003e\n    Установка\n\u003c/h2\u003e\n\n\u003ch3\u003eТребования\u003c/h3\u003e \u003cspan id=\"yii2-migrate-architect-setup-require\"\u003e\u003c/span\u003e\n\n- php \u003e=8.0\n- Yii2\n\n\u003ch3\u003e\n    \u003ca href=\"https://getcomposer.org/download/\"\u003eComposer\u003c/a\u003e\n\u003c/h3\u003e \u003cspan id=\"yii2-migrate-architect-setup-composer\"\u003e\u003c/span\u003e\n\n## Добавление пакета в проект\n\n\u003ch3\u003eИспользуя: консольные команды. \u003csmall\u003e\u003ci\u003e(Предпочтительней)\u003c/i\u003e\u003c/small\u003e\u003c/h3\u003e\u003cspan id=\"yii2-migrate-architect-setup-composer-cli\"\u003e\u003c/span\u003e\n\n- используя composer, установленный локально\n```bash\ncomposer require andy87/yii2-migrate-architect\n````  \n- используя composer.phar\n```bash\nphp composer.phar require andy87/yii2-migrate-architect\n```\n**Далее:** обновление зависимостей `composer install`\n\n\n\u003ch3\u003eИспользуя: файл `composer.json`\u003c/h3\u003e\u003cspan id=\"yii2-migrate-architect-setup-composer-composer-json\"\u003e\u003c/span\u003e\n\nОткрыть файл `composer.json`  \nВ раздел, ключ `require` добавить строку  \n`\"andy87/yii2-migrate-architect\": \"*\"`  \n**Далее:** обновление зависимостей `composer install`\n\n\u003cp align=\"center\"\u003e- - - - -\u003c/p\u003e\n\nВ конфигурационном файле `config/console.php` добавить контроллер:  \n`andy87\\yii2\\architect\\components\\controllers\\ArchitectController`\n```php\nuse andy87\\yii2\\architect\\components\\controllers\\ArchitectController;\n\nreturn [\n    // ...\n    'controllerMap' =\u003e [\n        // ...\n    \n        'architect' =\u003e ArchitectController::class,\n        // ...\n    ],\n    // ...\n];\n\n\n```\nПример с кастомизацией:\n- **directoryTemplateMigrations** _путь к шаблонам миграций_\n- **migrateTemplateMapping** _маппинг шаблонов миграций_\n- **snippetsMigrationFilename** _шаблоны имён файлов миграции_\n- **migrationPath** _(массив)путь к директории в которую будет сгенерирована миграция_\n\n```php\nuse andy87\\yii2\\architect\\components\\controllers\\ArchitectController;\n\nreturn [\n    // ...\n    'controllerMap' =\u003e [\n        // ...\n    \n        'architect' =\u003e [\n            'class' =\u003e ArchitectController::class,\n            'directoryTemplateMigrations' =\u003e '@app/path/to/migrations/template/',\n            'migrateTemplateMapping' =\u003e [\n                ArchitectController::SCENARIO_COLUMN_ADD =\u003e 'create_table_template',\n                ArchitectController::SCENARIO_UPDATE =\u003e 'update_table_template',\n                //,,,\n            ],\n            'snippetsMigrationFilename' =\u003e [\n                ArchitectController::SCENARIO_COLUMN_ADD =\u003e 'create_table__%s',\n                ArchitectController::SCENARIO_UPDATE =\u003e 'update_table__%s',\n                //,,,\n            ],\n            'migrationPath' =\u003e ['@console/migration']\n        ],\n        // ...\n    ],\n    // ...\n];\n```\n___\n\n## Использование \u003cspan id=\"yii2-migrate-architect-use\"\u003e\u003c/span\u003e\n\n\nКонсольная команда:\n```bash\n  php yii architect\n```\nЗапускает интерактивное меню для:\n- запуска миграций\n- создания миграций\n    - с предустановленными шаблонами миграций использующих базовые классы:\n        - `andy87\\yii2\\architect\\CreateTable`\n        - `andy87\\yii2\\architect\\UpdateTable`\n\n```\n\u003e php yii architect                             \nYii Migration Tool (based on Yii v2.0.51-dev)\n\nSelect action:\n 1. Create migration\n 2. Apply migrations\n 3. Down migrations\n 4. Run migrations\n 0. Exit\n--------------------\n variant: 2\n`Create migration`:\n 1. Create table\n 2. Update column\n 3. Add column\n 4. Rename column\n 5. Remove column\n 0. Exit\n--------------------\naction: 1\n\nTable name: product\nCreate new migration '../console/migrations\\m240628_072029_create_table__product.php'? (yes|no) [no]:y\nNew migration created successfully.\n\n```\n\n___\n\n## Простые примеры миграций\n\n### CreateTable.\n\n#### Создание таблицы\nКолонки: `id`, `created_at`, `updated_at` создадутся автоматически\n```php\n\u003c?php\n\nuse andy87\\yii2\\architect\\CreateTable;\n\n/**\n * Class m240626_210742_create_table__role\n */\nclass m240626_210742_create_table__role extends CreateTable\n{\n    public string $scenario = self::SCENARIO_CREATE;\n\n    /** @var string Название таблицы */\n    public string $tableName = '{{%role}}';\n    \n    /** \n     * @var array Список для генерации внешних ключей.\n     * Для примера добавлены два внешних ключа.\n     */\n    public array $foreignKeyList = [\n        'module' =\u003e 'id', // fk--role-module_id--module-id\n        'sub_module_id' =\u003e ['module' =\u003e 'id'], // fk--role-sub_module_id--module-id  \n    ];\n\n    /**\n     * @return array\n     */\n    public function columns(): array\n    {\n        return  [\n            'status' =\u003e $this-\u003esmallInteger()-\u003enotNull()-\u003edefaultValue(10),\n            'key' =\u003e $this-\u003estring(32)-\u003enotNull()-\u003eunique(),\n            'name' =\u003e $this-\u003estring(64)-\u003enotNull()-\u003eunique(),\n            'priority' =\u003e $this-\u003einteger(4)-\u003edefaultValue(1),\n            'module_id' =\u003e $this-\u003einteger(4)-\u003enotNull(),\n            'sub_module_id' =\u003e $this-\u003einteger(4)-\u003enotNull(),\n        ];\n    }\n}\n```\nОтмена создания колонок, происходит через назначение значения `false` или `null` для колонки.\nДля примера: `id`, `updated_at` не будут созданы\n```php\n\u003c?php\n\nuse andy87\\yii2\\architect\\CreateTable;\n\n/**\n * Class m240626_210741_create_table__log\n */\nclass m240626_210741_create_table__log extends CreateTable\n{\n    public string $scenario = self::SCENARIO_CREATE;\n\n    /** @var string Название таблицы */\n    public string $tableName = 'log';\n    \n    /**\n     * @return array\n     */\n    public function columns(): array\n    {\n        return  [\n            self::COLUMN_ID =\u003e false,\n            'text' =\u003e $this-\u003estring(32)-\u003enotNull()-\u003eunique(),\n            self::COLUMN_UPDATED_AT =\u003e null,\n        ];\n    }\n}\n```\n\n### UpdateTable.\n\n#### Добавление колонки\nДля добавления колонки, необходимо переопределить метод `columnsListAdd`, вернув массив с описанием колонок.\n```php\n\u003c?php\n\nuse andy87\\yii2\\architect\\UpdateTable;\n\n\n/**\n * Class m240626_210729_update_table__user\n */\nclass m240626_210729_update_table__user extends UpdateTable\n{\n    public string $scenario = self::SCENARIO_COLUMN_ADD;\n    \n    /** @var string Название таблицы */\n    public string $tableName = 'user';\n\n    /**\n     * Список колонок для добавления\n     * \n     * @return array\n     */\n    public function columnsListAdd(): array\n    {\n        return [\n            'verification_token' =\u003e $this-\u003estring()-\u003edefaultValue(null)\n        ];\n    }\n}\n```\n\n#### Добавление колонок и внешних ключей\nДля добавления колонок и внешних ключей, необходимо переопределить методы `columnsListAdd` и `foreignKeyList`, вернув массивы с описанием колонок и внешних ключей.\n```php\n\u003c?php\n\nuse andy87\\yii2\\architect\\UpdateTable;\n\n\n/**\n * Class m240626_210728_update_table__category\n */\nclass m240626_210728_update_table__category extends UpdateTable\n{\n    public string $scenario = self::SCENARIO_COLUMN_ADD;\n\n    /** @var string Название таблицы */\n    protected string $tableName = 'category';\n\n    /** @var array Мэппинг внешних ключей */\n    protected array $foreignKeyList = [\n        'user'      =\u003e 'id', // fk--category-user_id--user-id\n        'author_id' =\u003e ['user' =\u003e 'id'], // fk--category-author_id--user-id\n        'parent_id' =\u003e ['category' =\u003e 'id'], // fk--category-parent_id--category-id\n    ];\n    \n    /**\n     * Список колонок для добавления\n     *\n     * @return array\n     */\n    public function columnsListAdd(): array\n    {\n        return [\n            'user_id'   =\u003e $this-\u003einteger(8)-\u003enotNull(),\n            'author_id' =\u003e $this-\u003einteger(8)-\u003enotNull()-\u003eafter('user_id'),\n            'parent_id' =\u003e $this-\u003einteger(8)-\u003enull()-\u003eafter('id'),\n        ];\n    }\n}\n```\n\n#### Редактирование таблицы\nДля редактирования колонки, необходимо переопределить метод `columnsListUpdate`, вернув массив с описанием колонок.\n```php\n\u003c?php\n\nuse andy87\\yii2\\architect\\UpdateTable;\nuse app\\common\\models\\sources\\Role;\n\n/**\n * Class m240626_210729_update_table__user\n */\nclass m240626_210729_update_table__user extends UpdateTable\n{\n    public string $scenario = self::SCENARIO_UPDATE;\n\n    /** @var string Название таблицы */\n    protected string $tableName = 'user';\n\n    /**\n     * Список колонок для изменения\n     *\n     * @return array\n     */\n    public function columnsListUpdate(): array\n    {\n        return [\n            'auth_key' =\u003e $this-\u003estring(64)-\u003enotNull()-\u003eunique(),\n            'author_id' =\u003e $this-\u003einteger(4)-\u003enotNull()-\u003eunique(),\n        ];\n    }\n}\n```\n\n#### Переименование колонки\nДля переименования колонки, необходимо переопределить свойство `renameColumnList`, вернув массив с мэппингом старых и новых названий колонок.\n```php\n\u003c?php\n\nuse app\\common\\models\\sources\\Role;\nuse andy87\\yii2\\architect\\UpdateTable;\n\n/**\n * Class m240626_210725_update_table__product\n */\nclass m240626_210725_update_table__product extends UpdateTable\n{\n    public string $scenario = self::SCENARIO_COLUMN_RENAME;\n\n    /** @var string Название таблицы */\n    protected string $tableName = 'product';\n\n    /** @var array Список колонок для переименования */\n    protected array $renameColumnList = [\n        'old_price' =\u003e 'price',\n        'new_price' =\u003e 'price_new',\n    ];\n}\n```\n#### Удаление колонок\nДля удаления колонок, необходимо переопределить свойство `removeColumnList`, вернув массив с названиями колонок для удаления в ключе, а в значении массив указывающий на связи через внешние ключи.\n```php\n\u003c?php\n\nuse app\\common\\models\\sources\\Role;\nuse andy87\\yii2\\architect\\UpdateTable;\n\n/**\n * Class m240626_210735_update_table__service\n */\nclass m240626_210735_update_table__service extends UpdateTable\n{\n    public string $scenario = self::SCENARIO_COLUMN_REMOVE;\n\n    /** @var string Название таблицы */\n    protected string $tableName = 'service';\n\n    /** @var array Список колонок для удаления */\n    protected array $removeColumnList = [\n        'comments' =\u003e null,\n        'property' =\u003e null,\n        'user_id' =\u003e ['user' =\u003e 'id'],\n    ];\n}\n```\n\n[Packagist](https://packagist.org/packages/andy87/yii2-migrate-architect)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandy87%2Fyii2-migrate-architect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandy87%2Fyii2-migrate-architect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandy87%2Fyii2-migrate-architect/lists"}