Skip to content

Instantly share code, notes, and snippets.

Last active March 12, 2020 19:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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