CodeIgniter Forums
Migrate Regress not limited to chosen group - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Migrate Regress not limited to chosen group (/thread-76075.html)

Migrate Regress not limited to chosen group - ThomasB - 04-12-2020

The function $migrate->regress(-1,'content'); is rolling back the last migration regardless of its group.


PHP Code:
  $migrate = \Config\Services::migrations();

  try {

The above code will complete the migrations of the two groups correctly. 

If run a second time this will regress the 'users' migration and leave the 'content' migration alone. So the end result would be the last version of the 'content' up migration and the 'users' migration would be removed (down).

Here is an example of one of the migration classes:
PHP Code:
<?php namespace App\Database\Migrations;

Add_FAQ extends \CodeIgniter\Database\Migration {
  protected $DBGroup 'content';
  public function up(){
                  'faq_id'          => [
                          'type'           => 'INT',
                          'constraint'     => 5,
                          'unsigned'       => TRUE,
                          'auto_increment' => TRUE
                  'faq_title'       => [
                          'type'           => 'VARCHAR',
                          'constraint'     => '100',
                  'faq_description' => [
                          'type'           => 'TEXT',
                          'null'           => TRUE,

  public function down(){

Here are the entries in the "migrations" table of the main "default" database.
id    version                    class                                    group    namespace time            batch
29    2020-04-12-111100    App\Database\Migrations\Add_FAQ            content    App      1586702120    1
30    2020-04-12-131200    App\Database\Migrations\Add_Users    users    App      1586702120    2

If anyone can spot what's wrong with this or explain why the behaviour I'm seeing is actually correct I would much appreciate it.