{"id":22123501,"url":"https://github.com/proai/laravel-super-migrations","last_synced_at":"2025-07-25T15:31:23.650Z","repository":{"id":57044772,"uuid":"74712448","full_name":"ProAI/laravel-super-migrations","owner":"ProAI","description":":card_file_box: Laravel package for big databases, which need an advanced migrations structure","archived":false,"fork":false,"pushed_at":"2024-08-26T19:30:04.000Z","size":34,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-03T07:23:35.085Z","etag":null,"topics":["laravel","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ProAI.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-25T00:09:24.000Z","updated_at":"2024-08-28T06:47:29.000Z","dependencies_parsed_at":"2024-08-28T00:48:06.709Z","dependency_job_id":null,"html_url":"https://github.com/ProAI/laravel-super-migrations","commit_stats":{"total_commits":31,"total_committers":3,"mean_commits":"10.333333333333334","dds":0.6129032258064516,"last_synced_commit":"52429ec2a64b8d266a66a8f34d93067098d32f8c"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProAI%2Flaravel-super-migrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProAI%2Flaravel-super-migrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProAI%2Flaravel-super-migrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProAI%2Flaravel-super-migrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ProAI","download_url":"https://codeload.github.com/ProAI/laravel-super-migrations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227586874,"owners_count":17790114,"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":["laravel","migrations","php"],"created_at":"2024-12-01T15:33:58.791Z","updated_at":"2024-12-01T15:33:59.345Z","avatar_url":"https://github.com/ProAI.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Super Migrations\n\n[![Latest Stable Version](https://poser.pugx.org/proai/laravel-super-migrations/v/stable)](https://packagist.org/packages/proai/laravel-super-migrations) [![Total Downloads](https://poser.pugx.org/proai/laravel-super-migrations/downloads)](https://packagist.org/packages/proai/laravel-super-migrations) [![Latest Unstable Version](https://poser.pugx.org/proai/laravel-super-migrations/v/unstable)](https://packagist.org/packages/proai/laravel-super-migrations) [![License](https://poser.pugx.org/proai/laravel-super-migrations/license)](https://packagist.org/packages/proai/laravel-super-migrations)\n\nThis is an extension for the Laravel migrations. It is useful when you have a big database that results in a lot of migration files. This package will help you to reduce the number of migration files and furthermore it will give you a better structure with which you will have all schema updates for a table in one file.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require proai/laravel-super-migrations\n```\n\n## Usage\n\nBasically we do not define table builder schemas by migration, but by table. For this purpose you need to create a `tables` folder in the `database/migrations` directory. For each table we will create a file in this new directory and link it in the migration files whereever needed. Here is a more detailed explanation:\n\n### Migration Classes\n\nFirstly here is a migration file in the `database/migrations` folder. Notice that we extend the `ProAI\\SuperMigrations\\Migration` class. Instead of an `up()` and a `down()` method this class needs a `schemas()` method:\n\n```php\n\u003c?php\n\nuse ProAI\\SuperMigrations\\Migration;\n\nclass InitProject extends Migration\n{\n    /**\n     * Get table names and related methods for up and down schemas.\n     *\n     * @return array\n     */\n    public function schemas()\n    {\n        return [\n            'users' =\u003e 'create',\n            'comments' =\u003e 'create'\n        ];\n    }\n}\n\n```\n\nThe `schemas()` method returns a list of all database tables that are affected by this migration (`users` and `comments` table in the example above). Since there can be more than one migration for a database table, we also need to assign a migration specific name for each table (i.e. `create` for the `users` and `comments` table).\n\nWith this pattern we can easily bundle schemas in one migration file. One more example: Let's say we want to add a roles table and a column for the `role_id` in the users table, then the `schemas()` method could look like the following:\n\n```php\nreturn [\n    'roles' =\u003e 'create',\n    'users' =\u003e 'addRoleIdColumn'\n];\n\n```\n\nThe idea behind this is that one migration file includes all schemas for a whole update step rather than just for a table (i.e. one migration `InitProject` vs. multiple migrations `CreateUsersTable`, `CreateCommentsTable` etc.). This way you will have less migration files.\n\n### Table Classes\n\nFor each tablename that is returned by the `schemas()` method Laravel Super Migrations searches for a php file in `database/migrations/tables` with the same name (i.e. for the table `users` there must exist a file `users.php`). This file must contain a class that extends `ProAI\\SuperMigrations\\Table` and that is named after the table (in camel case) with a `Table` suffix. For example the classname must be `UsersTable` for a table `users`.\n\nFurthermore for each of the migration specific names that we declared in the migration file, the table class must declare a method with the same name (i.e. a `create` method for the users table). Here is a sample users table class that fits to the migration class from the previous section:\n\n```php\n\u003c?php\n\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse ProAI\\SuperMigrations\\Table;\nuse Illuminate\\Support\\Facades\\DB;\n\nclass UserTable extends Table\n{\n    /**\n     * Create the table.\n     *\n     * @return void\n     */\n    public function create()\n    {\n        // These statements will be only executed if direction of migrations is up\n        $this-\u003eupSchema()-\u003ecreate(function (Blueprint $table) {\n            $table-\u003eincrements('id');\n            $table-\u003etimestamps();\n        });\n\n        $this-\u003eup(function($tableName) {\n            DB::raw('ALTER TABLE `'.$tableName.'` ADD `client_id` BINARY(16)');\n        });\n\n\n        // These statements will be only executed if direction of migrations is down\n        $this-\u003edownSchema()-\u003edropIfExists();\n\n        $this-\u003edown(function($tableName) {\n            // some code\n        });\n    }\n}\n\n```\n\nWe use `$this-\u003eupSchema()` and `$this-\u003edownSchema()` to define the up and down schema. These methods return a `ProAI\\SuperMigrations\\Builder` instance that is similar to the Laravel database schema builder (see [Laravel docs](https://laravel.com/docs/5.3/migrations)). The only difference is that you don't need the tablename as first argument, because the tablename is already known. Furthermore we use `$this-\u003eup(...)` and `$this-\u003edown(...)` to insert custom code like raw DB statements (usually we don't need these methods).\n\n### Generator Command\n\nRun `php artisan make:super-migration` to create a new migration class that fits to the pattern of this package. You can declare a custom path with the `--path` option. Note that you have to include the service provider in order to use this command (see installation section).\n\n## Support\n\nBugs and feature requests are tracked on [GitHub](https://github.com/proai/laravel-super-migrations/issues).\n\n## License\n\nThis package is released under the [MIT License](LICENSE).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproai%2Flaravel-super-migrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fproai%2Flaravel-super-migrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproai%2Flaravel-super-migrations/lists"}