Skip to content

Commit

Permalink
use phinx for migrations and seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed Feb 20, 2018
1 parent c8a33b4 commit 91ef30d
Show file tree
Hide file tree
Showing 97 changed files with 1,179 additions and 2,936 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Ignore configuration files
api/config.php
config/*
!config/migrations.php
!config/api_sample.php

documents

Expand Down
2 changes: 1 addition & 1 deletion api/bootstrap/application.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$configFilePath = realpath(__DIR__ . '/../') . '/config.php';
$configFilePath = realpath(__DIR__ . '/../../') . '/config/api.php';

// Creates a simple endpoint to test the server rewriting
// If the server responds "pong" it means the rewriting works
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Directus\Authentication\User\User;
use Directus\Database\RowGateway\BaseRowGateway;
use Directus\Database\TableGateway\BaseTableGateway;
use Directus\Database\TableGateway\DirectusUsersTableGateway;
use Directus\Util\DateUtils;
use Zend\Db\Sql\Select;

Expand Down
2 changes: 1 addition & 1 deletion api/core/Directus/Console/Common/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct($base_path)
$this->directus_path = $base_path;
}

$app = new Application($base_path, require $this->directus_path . '/api/config.php');
$app = new Application($base_path, require $this->directus_path . '/config/api.php');
// $this->db = new Connection();//Bootstrap::get('ZendDb');
$this->db = $app->getContainer()->get('database');

Expand Down
2 changes: 1 addition & 1 deletion api/core/Directus/Console/Common/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct($base_path)
$this->directus_path = $base_path;
}

$this->app = new Application($base_path, require $base_path. '/api/config.php');
$this->app = new Application($base_path, require $base_path. '/config/api.php');
$this->db = $this->app->getContainer()->get('database');

$this->usersTableGateway = new TableGateway('directus_users', $this->db);
Expand Down
41 changes: 22 additions & 19 deletions api/core/Directus/Console/Modules/DatabaseModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
namespace Directus\Console\Modules;

use Directus\Util\ArrayUtils;
use Phinx\Config\Config;
use Phinx\Migration\Manager;
use Ruckusing\Framework as Ruckusing_Framework;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\NullOutput;

class DatabaseModule extends ModuleBase
{
Expand Down Expand Up @@ -38,29 +42,28 @@ public function cmdUpgrade($args, $extra)
$this->runMigration('upgrades');
}

protected function runMigration($migrationDirectory)
protected function runMigration($name)
{
$directusPath = BASE_PATH;
$appConfig = require_once $directusPath . '/api/config.php';
$config = require $directusPath . '/api/ruckusing.conf.php';
$dbConfig = getDatabaseConfig([
'type' => ArrayUtils::get($appConfig, 'database.type'),
'host' => ArrayUtils::get($appConfig, 'database.host'),
'port' => ArrayUtils::get($appConfig, 'database.port'),
'name' => ArrayUtils::get($appConfig, 'database.name'),
'user' => ArrayUtils::get($appConfig, 'database.username'),
'pass' => ArrayUtils::get($appConfig, 'database.password'),
'directory' => $migrationDirectory,
'prefix' => '',
]);

$config = array_merge($config, $dbConfig);
$main = new Ruckusing_Framework($config);
$configPath = $directusPath . '/config';
$apiConfig = require $configPath . '/api.php';
$configArray = require $configPath . '/migrations.php';
$configArray['paths']['migrations'] = $directusPath . '/migrations/db/' . $name;
$configArray['environments']['development'] = [
'adapter' => ArrayUtils::get($apiConfig, 'database.type'),
'host' => ArrayUtils::get($apiConfig, 'database.host'),
'port' => ArrayUtils::get($apiConfig, 'database.port'),
'name' => ArrayUtils::get($apiConfig, 'database.name'),
'user' => ArrayUtils::get($apiConfig, 'database.username'),
'pass' => ArrayUtils::get($apiConfig, 'database.password'),
'charset' => ArrayUtils::get($apiConfig, 'database.charset', 'utf8')
];
$config = new Config($configArray);

$output = $main->execute(['', 'db:setup']);
echo 'db:setup - ' . $output['message'] . PHP_EOL;
$manager = new Manager($config, new StringInput(''), new NullOutput());
$manager->migrate('development');

$output = $main->execute(['', 'db:migrate']);
echo 'db:migrate - ' . $output['message'] . PHP_EOL;
// TODO: Flush Output
}
}
2 changes: 1 addition & 1 deletion api/core/Directus/Console/Modules/InstallModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function cmdConfig($args, $extra)
}
}

$apiPath = rtrim($directusPath, '/') . '/api';
$apiPath = rtrim($directusPath, '/') . '/config';
if (!file_exists($apiPath)) {
throw new \Exception(sprintf('Path "%s" does not exists', $apiPath));
}
Expand Down
2 changes: 1 addition & 1 deletion api/core/Directus/Util/Installation/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function createConfig()
}
}

InstallerUtils::createConfig($data, $this->directusPath . '/api');
InstallerUtils::createConfig($data, $this->directusPath . '/config');

$this->clear();
}
Expand Down
54 changes: 29 additions & 25 deletions api/core/Directus/Util/Installation/InstallerUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Directus\Application\Application;
use Directus\Bootstrap;
use Directus\Database\Connection;
use Directus\Util\ArrayUtils;
use Directus\Util\StringUtils;
use Ruckusing\Framework as Ruckusing_Framework;
use Phinx\Config\Config;
use Phinx\Migration\Manager;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\NullOutput;
use Zend\Db\TableGateway\TableGateway;

class InstallerUtils
Expand Down Expand Up @@ -58,7 +60,7 @@ protected static function createConfigFile(array $data, $path)

$configStub = static::createConfigFileContent($data);

$configPath = rtrim($path, '/') . '/config.php';
$configPath = rtrim($path, '/') . '/api.php';
file_put_contents($configPath, $configStub);
}

Expand Down Expand Up @@ -94,24 +96,26 @@ public static function createTables($directusPath)
*/
static::checkConfigurationFile($directusPath);

$appConfig = require $directusPath . '/api/config.php';
$config = require $directusPath . '/api/ruckusing.conf.php';
$dbConfig = getDatabaseConfig([
'type' => ArrayUtils::get($appConfig, 'database.type'),
'host' => ArrayUtils::get($appConfig, 'database.host'),
'port' => ArrayUtils::get($appConfig, 'database.port'),
'name' => ArrayUtils::get($appConfig, 'database.name'),
'user' => ArrayUtils::get($appConfig, 'database.username'),
'pass' => ArrayUtils::get($appConfig, 'database.password'),
'directory' => 'schema',
'prefix' => '',
]);

$config = array_merge($config, $dbConfig);
$main = new Ruckusing_Framework($config);
$configPath = $directusPath . '/config';

$apiConfig = require $configPath . '/api.php';
$configArray = require $configPath . '/migrations.php';
$configArray['paths']['migrations'] = $directusPath . '/migrations/db/schemas';
$configArray['paths']['seeds'] = $directusPath . '/migrations/db/seeds';
$configArray['environments']['development'] = [
'adapter' => ArrayUtils::get($apiConfig, 'database.type'),
'host' => ArrayUtils::get($apiConfig, 'database.host'),
'port' => ArrayUtils::get($apiConfig, 'database.port'),
'name' => ArrayUtils::get($apiConfig, 'database.name'),
'user' => ArrayUtils::get($apiConfig, 'database.username'),
'pass' => ArrayUtils::get($apiConfig, 'database.password'),
'charset' => ArrayUtils::get($apiConfig, 'database.charset', 'utf8')
];
$config = new Config($configArray);

$main->execute(['', 'db:setup']);
$main->execute(['', 'db:migrate']);
$manager = new Manager($config, new StringInput(''), new NullOutput());
$manager->migrate('development');
$manager->seed('development');
}

/**
Expand All @@ -133,7 +137,7 @@ public static function addDefaultSettings($data, $directusPath)

// require_once $directusPath . '/api/config.php';

$app = new Application($directusPath, require $directusPath . '/api/config.php');
$app = new Application($directusPath, require $directusPath . '/config/api.php');
// $db = Bootstrap::get('ZendDb');
$db = $app->getContainer()->get('database');

Expand All @@ -153,7 +157,7 @@ public static function addDefaultSettings($data, $directusPath)
*/
public static function addDefaultUser($data, $directusPath)
{
$app = new Application($directusPath, require $directusPath . '/api/config.php');
$app = new Application($directusPath, require $directusPath . '/config/api.php');
// $db = Bootstrap::get('ZendDb');
$db = $app->getContainer()->get('database');
$tableGateway = new TableGateway('directus_users', $db);
Expand Down Expand Up @@ -240,7 +244,7 @@ public static function installSchemaFromMigration($name, $directusPath)
*/
static::checkConfigurationFile($directusPath);

require_once $directusPath . '/api/config.php';
require_once $directusPath . '/config/api.php';

$config = require $directusPath . '/api/ruckusing.conf.php';
$dbConfig = getDatabaseConfig([
Expand Down Expand Up @@ -347,11 +351,11 @@ private static function getDefaultSettings($data)
private static function checkConfigurationFile($directusPath)
{
$directusPath = rtrim($directusPath, '/');
if (!file_exists($directusPath . '/api/config.php')) {
if (!file_exists($directusPath . '/config/api.php')) {
throw new \Exception('Config file does not exists, run [directus config]');
}

if (!file_exists($directusPath . '/api/ruckusing.conf.php')) {
if (!file_exists($directusPath . '/config/migrations.php')) {
throw new \Exception('Migration configuration file does not exists');
}
}
Expand Down
65 changes: 0 additions & 65 deletions api/migrations/schema/20150203221946_CreateDirectusGroupsTable.php

This file was deleted.

This file was deleted.

Loading

0 comments on commit 91ef30d

Please sign in to comment.