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

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Migrate Regress not limited to chosen group (/showthread.php?tid=76075)



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.

Example:


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

  try {
    $migrate->regress(-1,'content');
    $migrate->latest('content');
    $migrate->latest('users');
..... 

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;

class 
Add_FAQ extends \CodeIgniter\Database\Migration {
  protected $DBGroup 'content';
  public function up(){
          $this->forge->addField([
                  'faq_id'          => [
                          'type'           => 'INT',
                          'constraint'     => 5,
                          'unsigned'       => TRUE,
                          'auto_increment' => TRUE
                  
],
                  'faq_title'       => [
                          'type'           => 'VARCHAR',
                          'constraint'     => '100',
                  ],
                  'faq_description' => [
                          'type'           => 'TEXT',
                          'null'           => TRUE,
                  ],
          ]);
          $this->forge->addKey('faq_id'TRUE);
          $this->forge->createTable('faq');
  }

  public function down(){
    $this->forge->dropTable('faq');
  }


Here are the entries in the "migrations" table of the main "default" database.
Code:
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.

Thanks