├── .styleci.yml ├── CHANGELOG.md ├── src ├── Commands │ ├── stubs │ │ └── refactor.stub │ ├── RefactorDbCommand.php │ └── RefactorMakeCommand.php └── RefactorServiceProvider.php ├── LICENSE.md ├── composer.json └── README.md /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - single_class_element_per_statement 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-database-refactors` will be documented in this file 4 | 5 | ## 1.0.0 - 2018-05-18 6 | 7 | - Initial release! 8 | -------------------------------------------------------------------------------- /src/Commands/stubs/refactor.stub: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 19 | $this->commands([ 20 | RefactorDbCommand::class, 21 | RefactorMakeCommand::class, 22 | ]); 23 | } 24 | } 25 | 26 | /** 27 | * Register the service provider. 28 | * 29 | * @return void 30 | */ 31 | public function register() 32 | { 33 | // 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Commands/RefactorDbCommand.php: -------------------------------------------------------------------------------- 1 | option('class'); 33 | 34 | if (! class_exists($class)) { 35 | throw new Exception('Invalid refactor class: '.$class); 36 | } 37 | 38 | if (! (new ReflectionClass($class))->hasMethod('run')) { 39 | throw new Exception('Method run does not exist on: '.$class); 40 | } 41 | 42 | (new $class)->run(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) Signifly 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "signifly/laravel-database-refactors", 3 | "description": "Add database refactors to your Laravel app.", 4 | "homepage": "https://github.com/signifly/laravel-database-refactors", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Morten Poul Jensen", 9 | "email": "mpj@signifly.com", 10 | "role": "Developer" 11 | } 12 | ], 13 | "require": { 14 | "php": "^7.2.5|^8.0", 15 | "illuminate/console": "^6.0|^7.0|^8.0", 16 | "illuminate/database": "^6.0|^7.0|^8.0", 17 | "illuminate/filesystem": "^6.0|^7.0|^8.0", 18 | "illuminate/support": "^6.0|^7.0|^8.0" 19 | }, 20 | "require-dev": { 21 | "phpunit/phpunit": "^7.0|^8.0|^9.0", 22 | "orchestra/testbench": "^4.0|^5.0|^6.0" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "Signifly\\DatabaseRefactors\\": "src" 27 | } 28 | }, 29 | "autoload-dev": { 30 | "psr-4": { 31 | "Signifly\\DatabaseRefactors\\Test\\": "tests" 32 | } 33 | }, 34 | "scripts": { 35 | "test": "vendor/bin/phpunit" 36 | }, 37 | "config": { 38 | "sort-packages": true 39 | }, 40 | "extra": { 41 | "laravel": { 42 | "providers": [ 43 | "Signifly\\DatabaseRefactors\\RefactorServiceProvider" 44 | ], 45 | "aliases": { 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Commands/RefactorMakeCommand.php: -------------------------------------------------------------------------------- 1 | composer = $composer; 51 | } 52 | 53 | /** 54 | * Execute the console command. 55 | * 56 | * @return void 57 | */ 58 | public function handle() 59 | { 60 | parent::handle(); 61 | 62 | $this->composer->dumpAutoloads(); 63 | } 64 | 65 | /** 66 | * Get the stub file for the generator. 67 | * 68 | * @return string 69 | */ 70 | protected function getStub() 71 | { 72 | return __DIR__.'/stubs/refactor.stub'; 73 | } 74 | 75 | /** 76 | * Get the destination class path. 77 | * 78 | * @param string $name 79 | * @return string 80 | */ 81 | protected function getPath($name) 82 | { 83 | return $this->laravel->databasePath().'/refactors/'.$name.'.php'; 84 | } 85 | 86 | /** 87 | * Parse the class name and format according to the root namespace. 88 | * 89 | * @param string $name 90 | * @return string 91 | */ 92 | protected function qualifyClass($name) 93 | { 94 | return $name; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Add database refactors to your Laravel app 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/signifly/laravel-database-refactors.svg?style=flat-square)](https://packagist.org/packages/signifly/laravel-database-refactors) 4 | [![Build Status](https://img.shields.io/travis/signifly/laravel-database-refactors/master.svg?style=flat-square)](https://travis-ci.org/signifly/laravel-database-refactors) 5 | [![StyleCI](https://styleci.io/repos/133973365/shield?branch=master)](https://styleci.io/repos/133973365) 6 | [![Quality Score](https://img.shields.io/scrutinizer/g/signifly/laravel-database-refactors.svg?style=flat-square)](https://scrutinizer-ci.com/g/signifly/laravel-database-refactors) 7 | [![Total Downloads](https://img.shields.io/packagist/dt/signifly/laravel-database-refactors.svg?style=flat-square)](https://packagist.org/packages/signifly/laravel-database-refactors) 8 | 9 | The `signifly/laravel-database-refactors` package allows you to easily add database refactors to your Laravel app. 10 | 11 | Below is a small example of how to use it. 12 | 13 | Run the refactor in terminal: 14 | 15 | ```bash 16 | php artisan db:refactor --class="UsersTableRefactor" 17 | ``` 18 | 19 | or programatically in a migration: 20 | 21 | ```php 22 | // use Illuminate\Support\Facades\Artisan; 23 | Artisan::call('db:refactor', [ 24 | '--class' => 'UsersTableRefactor', 25 | ]); 26 | ``` 27 | 28 | **IMPORTANT!** 29 | Update your `composer.json` file in order to autoload the database refactors: 30 | 31 | ``` 32 | "autoload": { 33 | "classmap": [ 34 | "database/seeds", 35 | "database/factories", 36 | "database/refactors" 37 | ], 38 | "psr-4": { 39 | "App\\": "app/" 40 | } 41 | }, 42 | ``` 43 | 44 | ## Installation 45 | 46 | You can install the package via composer: 47 | 48 | ```bash 49 | composer require signifly/laravel-database-refactors 50 | ``` 51 | 52 | The package will automatically register itself. 53 | 54 | ## Basic Usage 55 | 56 | In order to generate a new refactor file, you may use the following command: 57 | 58 | ```bash 59 | php artisan make:refactor UsersTableRefactor 60 | ``` 61 | 62 | The file will be located in the `database/refactors` folder. 63 | 64 | ## Testing 65 | 66 | ```bash 67 | composer test 68 | ``` 69 | 70 | ## Security 71 | 72 | If you discover any security issues, please email dev@signifly.com instead of using the issue tracker. 73 | 74 | ## Credits 75 | 76 | - [Morten Poul Jensen](https://github.com/pactode) 77 | - [All contributors](../../contributors) 78 | 79 | ## License 80 | 81 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 82 | --------------------------------------------------------------------------------