├── .php_cs.dist.php ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Commands └── LaravelCreateDbCommand.php └── LaravelCreateDbServiceProvider.php /.php_cs.dist.php: -------------------------------------------------------------------------------- 1 | in([ 5 | __DIR__ . '/src', 6 | ]) 7 | ->name('*.php') 8 | ->notName('*.blade.php') 9 | ->ignoreDotFiles(true) 10 | ->ignoreVCS(true); 11 | 12 | return (new PhpCsFixer\Config()) 13 | ->setRules([ 14 | '@PSR12' => true, 15 | 'array_syntax' => ['syntax' => 'short'], 16 | 'ordered_imports' => ['sort_algorithm' => 'alpha'], 17 | 'no_unused_imports' => true, 18 | 'not_operator_with_successor_space' => true, 19 | 'trailing_comma_in_multiline' => true, 20 | 'phpdoc_scalar' => true, 21 | 'unary_operator_spaces' => true, 22 | 'binary_operator_spaces' => true, 23 | 'blank_line_before_statement' => [ 24 | 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], 25 | ], 26 | 'phpdoc_single_line_var_spacing' => true, 27 | 'phpdoc_var_without_name' => true, 28 | 'class_attributes_separation' => [ 29 | 'elements' => [ 30 | 'method' => 'one', 31 | ], 32 | ], 33 | 'method_argument_space' => [ 34 | 'on_multiline' => 'ensure_fully_multiline', 35 | 'keep_multiple_spaces_after_comma' => true, 36 | ], 37 | 'single_trait_insert_per_statement' => true, 38 | ]) 39 | ->setFinder($finder); 40 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-create-db` will be documented in this file. 4 | 5 | ## 1.0.0 - 202X-XX-XX 6 | 7 | - initial release 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) ArondeParon 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Create DB 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/arondeparon/laravel-create-db.svg?style=flat-square)](https://packagist.org/packages/arondeparon/laravel-create-db) 4 | [![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/arondeparon/laravel-create-db/Check%20&%20fix%20styling?label=code%20style)](https://github.com/arondeparon/laravel-create-db/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain) 5 | [![Total Downloads](https://img.shields.io/packagist/dt/arondeparon/laravel-create-db.svg?style=flat-square)](https://packagist.org/packages/arondeparon/laravel-create-db) 6 | 7 | This package adds an easy-to-use Artisan command to your application that allows 8 | you to create a new database schema. 9 | 10 | The package is currently simple by design: there are no options apart from defining the schema and connection. If you need anything else, please submit a pull request. 11 | 12 | 13 | ## Installation 14 | 15 | You can install the package via composer: 16 | 17 | ```bash 18 | composer require arondeparon/laravel-create-db 19 | ``` 20 | 21 | ## Usage 22 | 23 | ```php 24 | php artisan migrate:create-db mydatabase [--connection myconnection] 25 | ``` 26 | 27 | ## Contributing 28 | 29 | Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. 30 | 31 | ## Credits 32 | 33 | - [Aron Rotteveel](https://github.com/ArondeParon) 34 | - [All Contributors](../../contributors) 35 | 36 | ## License 37 | 38 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 39 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "arondeparon/laravel-create-db", 3 | "description": "A package that adds database creation to your Laravel app via Artisan.", 4 | "keywords": [ 5 | "ArondeParon", 6 | "laravel", 7 | "laravel-create-db" 8 | ], 9 | "homepage": "https://github.com/arondeparon/laravel-create-db", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Aron Rotteveel", 14 | "email": "hi@aron.codes", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": "^8.0", 20 | "spatie/laravel-package-tools": "^1.4.3", 21 | "illuminate/contracts": "^8.37" 22 | }, 23 | "require-dev": { 24 | "brianium/paratest": "^6.2", 25 | "nunomaduro/collision": "^5.3", 26 | "orchestra/testbench": "^6.15", 27 | "phpunit/phpunit": "^9.3", 28 | "spatie/laravel-ray": "^1.23", 29 | "vimeo/psalm": "^4.8" 30 | }, 31 | "autoload": { 32 | "psr-4": { 33 | "ArondeParon\\LaravelCreateDb\\": "src", 34 | "ArondeParon\\LaravelCreateDb\\Database\\Factories\\": "database/factories" 35 | } 36 | }, 37 | "autoload-dev": { 38 | "psr-4": { 39 | "ArondeParon\\LaravelCreateDb\\Tests\\": "tests" 40 | } 41 | }, 42 | "scripts": { 43 | "psalm": "vendor/bin/psalm", 44 | "test": "./vendor/bin/testbench package:test --parallel --no-coverage", 45 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 46 | }, 47 | "config": { 48 | "sort-packages": true 49 | }, 50 | "extra": { 51 | "laravel": { 52 | "providers": [ 53 | "ArondeParon\\LaravelCreateDb\\LaravelCreateDbServiceProvider" 54 | ], 55 | "aliases": { 56 | "LaravelCreateDb": "ArondeParon\\LaravelCreateDb\\LaravelCreateDbFacade" 57 | } 58 | } 59 | }, 60 | "minimum-stability": "dev", 61 | "prefer-stable": true 62 | } 63 | -------------------------------------------------------------------------------- /src/Commands/LaravelCreateDbCommand.php: -------------------------------------------------------------------------------- 1 | argument('schema') ?? $this->ask('What is the name of your database schema?'); 17 | $connection = $this->option('connection') ?? DB::getDefaultConnection(); 18 | 19 | config(["database.connections.{$connection}.database" => null]); 20 | 21 | DB::connection($connection)->statement("CREATE DATABASE IF NOT EXISTS {$schema}"); 22 | 23 | $this->info("Database {$schema} has succesfully been created."); 24 | 25 | return Command::SUCCESS; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/LaravelCreateDbServiceProvider.php: -------------------------------------------------------------------------------- 1 | name('laravel-create-db') 15 | ->hasCommand(LaravelCreateDbCommand::class); 16 | } 17 | } 18 | --------------------------------------------------------------------------------