{"id":21965514,"url":"https://github.com/softius/phig","last_synced_at":"2026-05-09T14:46:05.126Z","repository":{"id":6140256,"uuid":"7368992","full_name":"softius/phig","owner":"softius","description":"Database migrations for PHP 5.3","archived":false,"fork":false,"pushed_at":"2013-01-07T17:34:49.000Z","size":144,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T01:25:47.639Z","etag":null,"topics":[],"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/softius.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":"2012-12-29T18:12:04.000Z","updated_at":"2018-07-22T15:34:58.000Z","dependencies_parsed_at":"2022-09-14T18:51:07.562Z","dependency_job_id":null,"html_url":"https://github.com/softius/phig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softius%2Fphig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softius%2Fphig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softius%2Fphig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softius%2Fphig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softius","download_url":"https://codeload.github.com/softius/phig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245022330,"owners_count":20548520,"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":[],"created_at":"2024-11-29T12:47:54.817Z","updated_at":"2026-05-09T14:46:05.033Z","avatar_url":"https://github.com/softius.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Phig\n====\n\n**phig** provides a convenient way to perform database migrations in PHP. It is  vendor and framework independent and can be used with any PDO driver or database abstraction framework like Doctrine. \n\nThe aims of phig are:\n\n* to be database framework independent: is not necessary to have background on  a particular framework or library to get started.\n* provide solid migration mechanism, embeddable to any project\n\nPHP 5.3+ is required.\n\nInstallation\n------------\n**phig** is available on packagist. All you need is to add the following lines in your project `composer.json`:\n\n``` JSON\n\t{\n    \t\"require\": {\n        \t\"softius/phig\": \"*@dev\"\n\t    }\n\t}\n```\nand install via composer:\n\n```\n\tphp composer.phar install\n```\n\nAn executable will be added under your project `vendor/bin` directory. If you would like to change this setup, please refer to this [guide](http://getcomposer.org/doc/articles/vendor-bins.md#can-vendor-bins-be-installed-somewhere-other-than-vendor-bin-).\n\nRunning migrations\n------------------\n\n**phig** provides a set of tasks which either execute pending migrations or reversed (rollback) already executed migration steps.\n\nFor instance, to execute all pending migrations run:\n\n```\n\tphig migrate\n```\n\nIf you would like to reach a particular migration you can specified it via arguments as specified below. If ommited, all pending migrations will be executed.\n\n```\n\tphig migrate 20121230185208\n```\n\nThis works for both upwards and downwards migrations. For instance, if target 20121230185208 is greater than the current version, this will trigger upwards migration (call up method on all migrations). On the contrary, if target 20121230185208 is less or equal than the current version, this will trigger downwards migration (call down method on all migrations). For further information on up and down methods, refer to **Writing a migration** section.\n\n### Rolling back\n\nTo rollback the last migration step run:\n\n```\n\tphig rollback\n```\n\nIf you would like to undo multiple migration steps you can specify it via the `step` argument:\n\n```\n\tphig rollback 5\n```\n\nThe above will undo the last 5 migrations. \n\n\n### Dump execution\n\nIf you would like to view the results of any of the commands above without actually executing them, append the option `--dump`. This will return usefull information about the actions planned to be carried out by the corresponding command. The following examples are all valid:\n\n```\n\tphig migrate --dump\n\tphig migrate 20121230185208 --dump\n\tphig rollback --dump\n\tphig rollback 3 --dump\n```\n\n\nWriting a migration\n--------------------\nMigrations are nothing more but classes in PHP, with the following constraints that you should be aware before starting writing code:\n\n* All migrations must be placed in a single directory. \n* Any migration class must extend the `MigratableInterface` and thus the methods `up` and `down`. The `up` method is called when executing an upwards migrations while the `down` method is called on downwards migrations and rollbacks. In other words, the `up` method is called to create a change while `down` method of the same class is called to reverse that change.\n* The filename of the migration is important since it is used as a reference hash for **phig** operations. While it is possible to use either datetime or a sequence (integer i.e. build number) or even a versioning scheme, I am suggesting to follow the datetime pattern. \n\nHere is an example\n\n``` PHP\n\t// yourproject/migrations/20130104152443-MigrationExample.php\n\tclass MigrationExample implements \\Phig\\MigratableInterface\n\t{\n\t\tpublic method up()\n\t\t{\n\t\t\tcreate_table('users');\n\t\t}\n\t\t\n\t\tpublic method down()\n\t\t{\n\t\t\tdestroy_table('users');\n\t\t}\n\t}\n```\n\n### Using PDO Drivers\n\nThe following example illustrates how PDO Migratable abstract class can be used. As you can see no database helpers are provided.\n\n``` PHP\n\t// yourproject/migrations/20130107193139-PdoMigrationExample.php\n\tclass PdoMigrationExample extends \\Phig\\Migratable\\Pdo\n\t{\n\t\tpublic method up()\n\t\t{\n\t\t\t$this-\u003egetConnection()-\u003eexec('CREATE TABLE users … ');\n\t\t}\n\t\t\n\t\tpublic method down()\n\t\t{\n\t\t\t$this-\u003egetConnection()-\u003eexec('DROP TABLE users');\n\t\t}\n\t}\n```\n\nTODO\n----\n* Provide abstract classes for ~~PDO Drivers~~ and Doctrine library\n* Improve configuration / add section in documentation\n* ~~Allow class names to be defined (and hence discovered) in migration filename i.e. `20121230185208-MigrationExample` (instead of `20121230185208.php`)~~\n* Support more than one migration folder\n* Add more examples in section *Writing a migration*\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftius%2Fphig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftius%2Fphig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftius%2Fphig/lists"}