{"id":26485813,"url":"https://github.com/alirezasalehizadeh/quickmigration","last_synced_at":"2026-04-05T20:38:40.673Z","repository":{"id":97262458,"uuid":"608570748","full_name":"alirezasalehizadeh/QuickMigration","owner":"alirezasalehizadeh","description":"A quick package for implement migrations in your PHP project.","archived":false,"fork":false,"pushed_at":"2023-10-21T08:27:12.000Z","size":129,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"1.8.x","last_synced_at":"2025-02-09T03:35:53.143Z","etag":null,"topics":["migration","php","php-migration"],"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/alirezasalehizadeh.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,"governance":null}},"created_at":"2023-03-02T09:44:35.000Z","updated_at":"2023-03-02T11:00:13.000Z","dependencies_parsed_at":"2023-09-29T20:33:21.736Z","dependency_job_id":null,"html_url":"https://github.com/alirezasalehizadeh/QuickMigration","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"500823c76adcaba27d819d51ae78f89514d8ffb4"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alirezasalehizadeh%2FQuickMigration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alirezasalehizadeh%2FQuickMigration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alirezasalehizadeh%2FQuickMigration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alirezasalehizadeh%2FQuickMigration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alirezasalehizadeh","download_url":"https://codeload.github.com/alirezasalehizadeh/QuickMigration/tar.gz/refs/heads/1.8.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244560338,"owners_count":20472219,"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":["migration","php","php-migration"],"created_at":"2025-03-20T06:00:17.313Z","updated_at":"2025-12-31T00:07:50.242Z","avatar_url":"https://github.com/alirezasalehizadeh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QuickMigration\n\nRun your migration quickly with Quick Migration!\n\n##  Requirements\n\nPHP \u003e= 8.1\n#### Available database:\n* MySql\n* PostgreSql\n\n\n## Getting Started\n\n#### Installation:\nvia Composer:\n```\ncomposer require alirezasalehizadeh/quick-migration\n```\n#### Migration class template:\nCreate a `xMigration` class like this that must extends from `\\Alirezasalehizadeh\\QuickMigration\\Migration` class:\n``` php\n\nuse Alirezasalehizadeh\\QuickMigration\\Migration;\nuse Alirezasalehizadeh\\QuickMigration\\Structure\\Structure;\nuse Alirezasalehizadeh\\QuickMigration\\Structure\\StructureBuilder;\n\nclass xMigration extends Migration\n{\n\n    protected $database = \"database name\";\n\n    protected $translator = \"set database translator name from available translators array (default MySql)\";\n\n    public function set(): array\n    {\n        return Structure::create('table_name', function (StructureBuilder $structure) {\n            // Write your structure here...\n        });\n    }\n\n}\n```\n\n#### Run migration:\nNext, create a object from `xMigration` class and run `migrate` method:\n```php\n// index.php\n\n$connection = PDO connection object;\n\n(new xMigration($connection))-\u003emigrate();\n```\n```\nphp index.php\n```\n##### drop table:\n```php\n// index.php\n\n$connection = PDO connection object;\n\n(new xMigration($connection))-\u003edrop('table name');\n// OR\n(new xMigration($connection))-\u003edropIfExists('table name');\n```\n```\nphp index.php\n```\n\n## Usage\n\n#### Structure methods:\n```php\n$structure-\u003eid(string $name);\n$structure-\u003euuid(string $name, int $length);\n$structure-\u003eulid(string $name, int $length);\n$structure-\u003estring(string $name, int $length);\n$structure-\u003enumber(string $name);\n$structure-\u003etext(string $name);\n$structure-\u003etimestamp(string $name);\n$structure-\u003etimestamps();\n$structure-\u003ejson(string $name);\n$structure-\u003eenum(string $name, array $enums);\n$structure-\u003earray(string $name, array $values);\n$structure-\u003eforeign(string $column)-\u003ereference(string $column)-\u003eon(string $table);\n```\n*NOTE: See the [Structure Test](https://github.com/alirezasalehizadeh/QuickMigration/blob/1.7.x/test/Structure/StructureBuilderTest.php) file for examples\n#### Column attributes:\n```php\n$structure-\u003enumber('test')\n-\u003eprimary()                 // Set this as primary key\n-\u003enullable()                // Set this nullable or not\n-\u003eunique()                  // Set this unique\n-\u003edefault(1)                // Set default value\n-\u003eautoIncrement()           // Set this auto increment\n-\u003eindex()                   // Index this column\n-\u003eunsigned()                // Set unsigned attribute\n-\u003eafter('column')           // Set this column after specific column\n-\u003echeck('test \u003e= 0')        // Check a expression\n-\u003ecomment('this is test column')  // Set a comment\n```\n#### Custom Column:\nSometimes it happens that you need a specific type of column that is not available in `Type` enum and you have to create it manually. `QuickMigration` has provided you with a quick and easy way to create a specific type of column!\n\nTo create a column, it is enough to set the `method name` equal to the `column type` and write the `column name` in the `first argument`, like this:\n```php\n// TINYTEXT type not defined in `Type` enum\n\n$structure = new StructureBuilder('table name');\n\n$structure-\u003etinyText('foo');\n// ...\n```\n#### Commands:\n```php\nmigrate();\ndropIfExists(string $table);\ndrop(string $table);\ncreateIndex(string $name, string $table, array $columns);    // It is used to index several columns together\ndropIndex(string $name, string $table);\nalterTable();\ndropCheck(string $table, string $name);\n```\n*NOTE: See the [Command Test](https://github.com/alirezasalehizadeh/QuickMigration/blob/1.7.x/test/Command/CommandTranslator/CommandTranslatorTest.php) file for examples\n\n#### Get SQL:\nYou can get the sql`s by call the migration class object as string:\n```php\n$obj = new xMigration($connection);\n$obj-\u003edropIfExists('bar');\n$obj-\u003emigrate();\necho $obj;\n\n/**\nDROP TABLE IF EXISTS `foo`.`bar`\nCREATE TABLE `foo`.`bar` (`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, ...)\n**/\n\n```\n##### Get SQL as File:\nYou can use `export` method, for get your sql`s in a file:\n```php\n$obj = new xMigration($connection);\n$obj-\u003edropIfExists('bar');\n$obj-\u003emigrate();\n$obj-\u003eexport(string $fileName);\n\n// Create a file named fileName.sql\n\n```\n\n#### Custom Foreign Key:\nA quick way to create a foreignkey is this that the `name of the method` must to be`foreign + {foreignColumnName}`:\n```php\n$structure = new StructureBuilder('table name');\n\n$structure-\u003eforeign('bar_id')-\u003ereference('id')-\u003eon('bar');\n// OR\n$structure-\u003eforeignBarId()-\u003ereference('id')-\u003eon('bar');\n// ...\n```\n\n### Modify Table:\nNow, for modify your tables can use `change` method on `Structure`:\n``` php\n\nuse Alirezasalehizadeh\\QuickMigration\\Migration;\nuse Alirezasalehizadeh\\QuickMigration\\Structure\\Structure;\nuse Alirezasalehizadeh\\QuickMigration\\Structure\\TableAlter;\n\nclass xMigration extends Migration\n{\n\n    protected $database = \"database name\";\n\n    protected $translator = \"set database translator name from available translators array (default MySql)\";\n\n    public function set(): array\n    {\n        return Structure::change('table_name', function (TableAlter $alter) {\n            // Write your commands for modify table...\n        });\n    }\n\n}\n```\n#### Run commands:\n```php\n// index.php\n\n$connection = PDO connection object;\n\n(new xMigration($connection))-\u003ealterTable();\n```\n```\nphp index.php\n```\n*NOTE: See the [Table Alter Test](https://github.com/alirezasalehizadeh/QuickMigration/blob/1.7.x/test/Structure/StructureAlterTest.php) file for examples\n\n\n\n## Contributing\nSend pull request or open issue for contributing.\n\n\n## License\n\n[MIT](LICENSE).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falirezasalehizadeh%2Fquickmigration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falirezasalehizadeh%2Fquickmigration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falirezasalehizadeh%2Fquickmigration/lists"}