Skip to content

Instantly share code, notes, and snippets.

@samsonasik
Last active Mar 12, 2020
Embed
What would you like to do?
create db command with ci 4
<?php namespace App\Commands;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
class CreateDb extends BaseCommand
{
protected $group = 'app';
protected $name = 'app:createdb';
protected $description = 'Create database';
public function run(array $params)
{
$forge = \Config\Database::forge();
$forge->createDatabase(env('database.default.database'), true);
}
}

run with command:

php spark app:createdb

or in composer.json, add to the script:

	"scripts": {
		"test": "phpunit",
		"post-update-cmd": [
			"@composer dump-autoload",
			"php spark app:createdb"
		],
		"post-install-cmd": [
			"php spark app:createdb"
		]
	},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment