{"id":15062159,"url":"https://github.com/semisedlak/migratte","last_synced_at":"2026-01-30T08:13:05.297Z","repository":{"id":47304119,"uuid":"496364352","full_name":"semisedlak/migratte","owner":"semisedlak","description":"Migratte is simple SQL migrations management standalone CLI app, framework-agnostic.","archived":false,"fork":false,"pushed_at":"2024-05-08T18:40:40.000Z","size":125,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T00:38:14.806Z","etag":null,"topics":["database","migrations","php"],"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/semisedlak.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":"2022-05-25T19:30:10.000Z","updated_at":"2024-05-08T18:40:44.000Z","dependencies_parsed_at":"2024-05-08T19:49:42.672Z","dependency_job_id":"ddbfa754-bd32-49d8-be54-d42d52d47311","html_url":"https://github.com/semisedlak/migratte","commit_stats":{"total_commits":63,"total_committers":1,"mean_commits":63.0,"dds":0.0,"last_synced_commit":"29ae7fa1ea6fcca8a4b8081cf39e100761f09476"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/semisedlak/migratte","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semisedlak%2Fmigratte","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semisedlak%2Fmigratte/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semisedlak%2Fmigratte/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semisedlak%2Fmigratte/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/semisedlak","download_url":"https://codeload.github.com/semisedlak/migratte/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semisedlak%2Fmigratte/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259846200,"owners_count":22920883,"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":["database","migrations","php"],"created_at":"2024-09-24T23:31:16.083Z","updated_at":"2026-01-30T08:13:00.268Z","avatar_url":"https://github.com/semisedlak.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Migratte\n========\n\n- [How it works](#how-it-works)\n- [Migration anatomy](#migration-anatomy)\n- [Configuration](#configuration)\n- [Executable file](#executable-file)\n- [Commands](#commands)\n  - [`migratte:generate`](#migrattegenerate)\n  - [`migratte:commit`](#migrattecommit)\n  - [`migratte:rollback`](#migratterollback)\n  - [`migratte:status`](#migrattestatus)\n  - [`migratte:info`](#migratteinfo)\n- [Are you using Nette Framework?](#are-you-using-nette-framework)\n- [Changelog](#changelog)\n  - [0.4.0](#040)\n\nMigratte is simple SQL migrations management standalone CLI app, framework-agnostic. It is inspired by [Phinx](https://phinx.org/), but it is much simpler, and it doesn't require CakePHP framework to be installed.\n\nYou can install it using composer:\n\n```shell\n$ composer require semisedlak/migratte\n```\n\n## How it works\nIt is controlled by ([Symfony Console](https://github.com/symfony/console)) CLI commands for:\n\n1. [generate](#migrattegenerate) new migration\n2. [commit](#migrattecommit) migration\n3. [rollback](#migratterollback) migration\n4. showing migrations [status](#migrattestatus)\n5. showing configuration [info](#migratteinfo)\n\n## Migration anatomy\nMigrations are simple [PHP files](#migration-anatomy) keeping plain SQL queries. If plain SQL so why PHP files then? Answer is simple. For keeping [\"up\"](#example-migration) (for [commit](#migrattecommit)) and [\"down\"](#example-migration) (for [rollback](#migratterollback)) SQL queries with additional metadata all together.\n\n\u003e 💡 Migratte doesn't provide (yet) rich migrations management. It is just a simple tool for executing your SQL queries and it is up to you to write them. You can use any SQL query you want.\n\u003e\n\u003e You can still use [Phinx](https://phinx.org/) with [CakePHP Migrations](https://book.cakephp.org/3.0/en/migrations.html) for migrations management. I recommend [Adminer](https://www.adminer.org/) for database management.\n\nSpecific migration class extends from basic migration class. It contains timestamp in file name and class name witch should not be modified.\n\nMigration file that doesn't contain `down()` method is \"breakpoint\", that means rollback cannot be performed. BUT! There is an option `--force` to perform rollback with this kind of migration.\n\nThis tool creates it's \"memory\" in same database as migrations target. It uses [dibi database layer](https://dibiphp.com/) for connection and queries executions.\n\nYou can use it with:\n* MySQL database\n* PostgreSQL database\n* SQLite database\n\n## Configuration\nYou can override this default configuration options:\n\n```php\n'timezone'        =\u003e 'UTC',\n'migrationsDir'   =\u003e \"$workingDir/database/migrations\",\n'migrationsTable' =\u003e [\n  'name'        =\u003e 'migrations',\n  'primaryKey'  =\u003e 'id',\n  'fileName'    =\u003e 'filename',\n  'groupNo'     =\u003e 'group',\n  'committedAt' =\u003e 'committed_at',\n],\n'connection'      =\u003e [\n  'driver'   =\u003e 'sqlite', // mysqli or postgre\n  'database' =\u003e \"$workingDir/database/migratte.s3db\",\n],\n```\n\nproviding options array as first argument of `Application::boot()` method from executable file. You can read how to set up connection in [dibi documentation](https://dibiphp.com/).\n\n## Executable file\nCreate a file `bin/migrations` in the root dir of your project with following content:\n\n```php\n#!/usr/bin/env php\n\u003c?php\n\nuse Semisedlak\\Migratte\\Application\\Application;\n\nrequire __DIR__ . '/../vendor/autoload.php';\n\n(Application::boot())-\u003erun();\n```\n\nDon't forget to change permission using `chmod +x bin/migrations`\n\n## Commands\nWhen you run `bin/migrations` in CLI you will see \"help\" overview with possible commands.\n\n```\nroot@12345:/var/www/html# bin/migrations\nMigratte 0.5.0\n\nUsage:\n  command [options] [arguments]\n\nOptions:\n  -h, --help            Display this help message\n  -q, --quiet           Do not output any message\n  -V, --version         Display this application version\n      --ansi            Force ANSI output\n      --no-ansi         Disable ANSI output\n  -n, --no-interaction  Do not ask any interactive question\n  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug\n\nAvailable commands:\n  help               Display help for a command\n  list               List commands\n migratte\n  migratte:commit    Commit (run) migrations\n  migratte:generate  Generate new migration file\n  migratte:info      Show migrations configuration info\n  migratte:rollback  Rollback migrations\n  migratte:status    Show migrations status\n```\n\n\u003e 💡 Hint: You can use `--help` (or `-h`) option for each command to see more details.\n\n### `migratte:generate`\nCommand generates new migration file which then can be modified. You can specify migration name as first argument. Write it as normal sentence, it will be converted to desired form automatically.\n\n```shell\n$ bin/migrations migratte:generate \"Create users table\"\n```\n\nThis will generate file `database/migrations/20190101_120000-create-users-table.php` with following content:\n\n```php\n\u003c?php\n\nuse Semisedlak\\Migratte\\Migrations\\Migration;\n\nclass Migration_20190101_120000 extends Migration\n{\n\tpublic static function getName(): string\n\t{\n\t\treturn 'Create users table';\n\t}\n\n\tpublic static function up(): string\n\t{\n\t\treturn \u003c\u003c\u003cSQL\n-- UP: Create users table\nSQL;\n\t}\n\n\tpublic static function down(): ?string\n\t{\n\t\treturn NULL;\n\t}\n}\n```\n\n\u003e ⚠️ Warning! Don't modify migration class name. Don't modify file name after it was committed. You can modify `up()` and `down()` methods to contain your SQL queries.\n\nIf you want to change migration name you can change it in `getName()` method. It is used only for displaying purposes.\n\nThen copy your SQL queries to `up()` and `down()` methods. If `down()` method returns NULL or FALSE it is considered as \"breakpoint\" migration (it cannot be rollbacked because it doesn't provide \"down\" operation).\n\n#### Example migration\n\n```php\npublic static function up(): string\n{\n\treturn \u003c\u003c\u003cSQL\nCREATE TABLE `users` (\n  `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,\n  `name` varchar(255) NOT NULL\n) ENGINE='InnoDB' COLLATE 'utf8mb4_general_ci';\nSQL;\n}\n\npublic static function down(): ?string\n{\n\treturn \u003c\u003c\u003cSQL\nDROP TABLE `users`;\nSQL;\n}\n```\n\n### `migratte:commit`\nCommand commits (runs) new migrations. By default, it will run all non-committed migrations one-by-one. You can specify less to commit with `limit` (first) argument:\n\n```shell\n$ bin/migrations migratte:commit 3\n```\n\nBut there is more. You can specify datetime limits `--from` and `--to` for limiting committing.\n\nAre you unsure what migrations will be committed? Use `--dry-run` (or `-d`) option to see what migrations will be committed without actually committing them.\n\nMigratte automatically put migrations into groups. These groups are simply integer numbers and they are important for rollback strategy. You can't specify group number. It will be automatically incremented. If you use default rollback strategy (by commit date) it will rollback migrations from the last group (with highest number) in reverse order of committing.\n\n### `migratte:rollback`\nCommand performs rollback operation to already committed migrations back to previous state. Rollback will be done only on (by default) migrations from latest group. You can specify more migrations to rollback with `limit` (first) argument:\n\n```shell\n$ bin/migrations migratte:rollback 3\n```\nIn this case, it will ignore groups and rollback last 3 committed migrations.\n\nIf migration doesn't contain `down()` method or this method simply returns NULL or FALSE it is considered as \"breakpoint\". Calling rollback on \"breakpoint\" will throw an error. This can be bypassed by using `--force` (or `-f`) option.\n\n#### Rollback strategy\n\nYou can specify rollback strategy by using `--strategy` option. There are currently three strategies for rollback:\n\n1. by commit **\"date\"** (this is default) (`--strategy=date`) - rollback by commit date (migrations from last group will be rollbacked by commit date in reverse order of committing)\n2. by migration **\"order\"** (`--strategy=order`) - rollback migrations by migrations order (if you sort files by name, you will get migrations order, so last committed file will be rollbacked first)\n3. by specific **\"file\"** (`--strategy=file`) - rollback specific migration file. You have to provide migration file name (without path) as `--file` option. Hint: you can omit `.php` extension.\n\n### `migratte:status`\nCommand shows current migrations' status (what is or isn't committed, which migration is breakpoint and more).\n\nThere is also an option `--compact` (or `-c`) to show compact table of migrations.\n\n### `migratte:info`\nCommand shows current Migratte configuration.\n\n## Are you using Nette framework?\n**Great!** You can use Nette DI extension to register a Migratte panel into [Tracy](https://tracy.nette.org/) (something like `migratte:status` and `migratte:info` combined but... in HTML... with styles). It will use `dibi` extension for connection definition.\n\n```neon\nextensions:\n    migratte: Semisedlak\\Migratte\\Nette\\DiExtension\n\nmigratte:\n    debug: true\n```\n\n## Changelog\n\n### 0.4.0\n\nPlease update your `bin/migrations` executable file `Application` class namespace like this:\n\n```php\n// use Semisedlak\\Migratte\\Migrations\\Application; // OLD NAMESPACE\nuse Semisedlak\\Migratte\\Application\\Application; // NEW NAMESPACE\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemisedlak%2Fmigratte","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsemisedlak%2Fmigratte","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemisedlak%2Fmigratte/lists"}