Skip to content

Commit

Permalink
Migrations should only look in setPath when one has been set.
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed Nov 18, 2016
1 parent 8fe1d1f commit 2a88bfd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
12 changes: 0 additions & 12 deletions application/Config/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,4 @@ class Migrations extends BaseConfig
*/
public $currentVersion = 0;

/*
|--------------------------------------------------------------------------
| Migrations Path
|--------------------------------------------------------------------------
|
| Path to your migrations folder.
| Typically, it will be within your application path.
| Also, writing permission is required within the migrations path.
|
*/
public $path = APPPATH.'Database/Migrations/';

}
26 changes: 19 additions & 7 deletions system/Database/MigrationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ public function __construct(BaseConfig $config, ConnectionInterface $db = null)
$this->type = $config->type ?? 'timestamp';
$this->table = $config->table ?? 'migrations';
$this->currentVersion = $config->currentVersion ?? 0;
$this->path = $config->path ?? 'Database/Migrations/';

$this->path = rtrim($this->path, '/').'/';

if (empty($this->table))
{
Expand Down Expand Up @@ -285,14 +282,29 @@ public function findMigrations()
{
$migrations = [];

$config = new Autoload();
// If $path has been set, ONLY do that one since
// the user has specified their will. Otherwise,
// scan all PSR4 paths. This is required so
// when tests are ran, it will only look in it's
// location.
$paths = [];
if (empty($this->path))
{
$config = new Autoload();
foreach ($config->psr4 as $dir)
{
$paths[] = rtrim($dir, '/').'/Database/Migrations/';
}
}
else
{
$paths[] = $this->path;
}

// Loop through all of our namespaced folders
// searching for migration directories.
foreach ($config->psr4 as $namespace => $dir)
foreach ($paths as $dir)
{
$dir = rtrim($dir, '/').'/'.$this->path;

if (! is_dir($dir))
{
continue;
Expand Down
20 changes: 10 additions & 10 deletions system/Test/CIDatabaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ class CIDatabaseTestCase extends CIUnitTestCase

/**
* Our database connection.
*
*
* @var BaseConnection
*/
protected $db;

/**
* Migration Runner instance.
*
*
* @var MigrationRunner|mixed
*/
protected $migrations;

/**
* Seeder instance
* Seeder instance
*
* @var \CodeIgniter\Database\Seeder
*/
Expand Down Expand Up @@ -125,7 +125,7 @@ public function loadDependencies()
$config->enabled = true;

$this->migrations = Services::migrations($config, $this->db);
$this->migrations->setSilent(true);
$this->migrations->setSilent(false);
}

if ($this->seeder === null)
Expand Down Expand Up @@ -165,7 +165,7 @@ public function setUp()
{
$this->seeder->setPath(rtrim($this->basePath, '/').'/seeds');
}

$this->seed($this->seed);
}
}
Expand Down Expand Up @@ -225,13 +225,13 @@ public function dontSeeInDatabase(string $table, array $where)

$this->assertTrue($count == 0, 'Row was found in database');
}

//--------------------------------------------------------------------

/**
* Asserts that records that match the conditions in $where DO
* exist in the database.
*
*
* @param string $table
* @param array $where
*
Expand Down Expand Up @@ -271,7 +271,7 @@ public function grabFromDatabase(string $table, string $column, array $where)

return $query->$column ?? false;
}

//--------------------------------------------------------------------

/**
Expand Down Expand Up @@ -314,7 +314,7 @@ public function seeNumRecords(int $expected, string $table, array $where)

$this->assertEquals($expected, $count, 'Wrong number of matching rows in database.');
}

//--------------------------------------------------------------------

}

0 comments on commit 2a88bfd

Please sign in to comment.