Skip to content

Commit

Permalink
Merge pull request #2191 from MGatner/migration-rollback-reverse
Browse files Browse the repository at this point in the history
Migration rollback reverse
  • Loading branch information
lonnieezell authored Sep 5, 2019
2 parents 847b1c1 + dc9a911 commit 3768431
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions system/Database/MigrationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function regress(int $targetBatch = 0, string $group = null)
}

// Get the migrations from each history
foreach ($this->getBatchHistory($batch) as $history)
foreach ($this->getBatchHistory($batch, 'desc') as $history)
{
// Create a UID from the history to match its migration
$uid = $this->getObjectUid($history);
Expand Down Expand Up @@ -789,13 +789,13 @@ public function getHistory(string $group = 'default'): array
*
* @return array
*/
public function getBatchHistory(int $batch): array
public function getBatchHistory(int $batch, $order = 'asc'): array
{
$this->ensureTable();

$query = $this->db->table($this->table)
->where('batch', $batch)
->orderBy('id', 'asc')
->orderBy('id', $order)
->get();

return $query ? $query->getResultObject() : [];
Expand Down
8 changes: 4 additions & 4 deletions user_guide_src/source/dbmgmt/migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ Foreign Keys
============

When your tables include Foreign Keys, migrations can often cause problems as you attempt to drop tables and columns.
To temporarily bypass the foreign key checks while running migrations, use the ``disableForeignKeyConstraints()`` and
``enableForeignKeyConstraints()`` methods on the database connection.
To temporarily bypass the foreign key checks while running migrations, use the ``disableForeignKeyChecks()`` and
``enableForeignKeyChecks()`` methods on the database connection.

::

public function up()
{
$this->db->disableForeignKeyConstraints();
$this->db->disableForeignKeyChecks();

// Migration rules would go here...

$this->db->enableForeignKeyConstraints();
$this->db->enableForeignKeyChecks();
}

Database Groups
Expand Down

0 comments on commit 3768431

Please sign in to comment.