Repository: codeigniter4/CodeIgniter4 (PHP)

Issue:
Bug: Migration status not working with different namespaces
### PHP Version

7.4

### CodeIgniter4 Version

4.1.7

### CodeIgniter4 Installation Method

Composer (using `codeigniter4/appstarter`)

### Which operating systems have you tested for this bug?

Windows, Linux

### Which server did you use?

apache

### Database

MySQL 8.0.27-0ubuntu0.20.04.1

### What happened?

On the command php spark migrate:status 
The migrated details for columns "Group", "Migrated On", "Batch" are missing on all namespaces besides App namespace.
Please refer to the image below:
![image_2022_01_15T10_38_24_142Z (1)](https://user-images.githubusercontent.com/19651216/150298045-a1adf231-26b5-45c1-946c-058d5233fb1b.png)

### Steps to Reproduce

Do migration on multiple namespaces and check php spark migrate:status
You will see that data for columns "Group", "Migrated On", "Batch" missing for all namespaces besides App namespace,

### Expected Output

php spark migrate:status 
"Group", "Migrated On", "Batch" data on all namespaces.

### Anything else?

_No response_


Discussion:
@demirkaric The screenshot was deleted.
You can upload it to GitHub by dragging it into the text area.
I've confirmed this bug.

```
$ php spark migrate:status

CodeIgniter v4.1.7 Command Line Tool - Server Time: 2022-01-20 02:49:14 UTC-06:00

+-----------+-------------------+-----------------------+---------+---------------------+-------+
| Namespace | Version           | Filename              | Group   | Migrated On         | Batch |
+-----------+-------------------+-----------------------+---------+---------------------+-------+
| App       | 2022-01-20-084314 | CreateCiSessionsTable | default | 2022-01-20 02:47:08 | 1     |
| Myth\Auth | 2017-11-20-223112 | create_auth_tables    | ---     | ---                 | ---   |
+-----------+-------------------+-----------------------+---------+---------------------+-------+
```

```
SELECT * FROM `migrations`

id	version	class	group	namespace	time	batch	
1	2022-01-20-084314	App\Database\Migrations\CreateCiSessionsTable	default	App	1642668428	1	
2	2017-11-20-223112	Myth\Auth\Database\Migrations\CreateAuthTables	default	Myth\Auth	1642668543	2	
```
@demirkaric Try this:
```diff
--- a/system/Commands/Database/MigrateStatus.php
+++ b/system/Commands/Database/MigrateStatus.php
@@ -108,6 +108,7 @@ class MigrateStatus extends BaseCommand
                 continue;
             }
 
+            $runner->setNamespace(null);
             $history = $runner->getHistory((string) $group);
             ksort($migrations);
 
```

@demirkaric Try #5605 if you can.




Patch:
diff --git a/system/Commands/Database/MigrateStatus.php b/system/Commands/Database/MigrateStatus.php
index 91b52950b2b4..8b0885a659b1 100644
--- a/system/Commands/Database/MigrateStatus.php
+++ b/system/Commands/Database/MigrateStatus.php
@@ -79,8 +79,8 @@ class MigrateStatus extends BaseCommand
      */
     public function run(array $params)
     {
-        $runner = Services::migrations();
-        $group  = $params['g'] ?? CLI::getOption('g');
+        $runner     = Services::migrations();
+        $paramGroup = $params['g'] ?? CLI::getOption('g');
 
         // Get all namespaces
         $namespaces = Services::autoloader()->getNamespace();
@@ -108,7 +108,8 @@ public function run(array $params)
                 continue;
             }
 
-            $history = $runner->getHistory((string) $group);
+            $runner->setNamespace($namespace);
+            $history = $runner->getHistory((string) $paramGroup);
             ksort($migrations);
 
             foreach ($migrations as $uid => $migration) {


Test patch:
diff --git a/tests/system/Commands/Database/MigrateStatusTest.php b/tests/system/Commands/Database/MigrateStatusTest.php
new file mode 100644
index 000000000000..8f6997d01127
--- /dev/null
+++ b/tests/system/Commands/Database/MigrateStatusTest.php
@@ -0,0 +1,112 @@
+<?php
+
+/**
+ * This file is part of CodeIgniter 4 framework.
+ *
+ * (c) CodeIgniter Foundation <admin@codeigniter.com>
+ *
+ * For the full copyright and license information, please view
+ * the LICENSE file that was distributed with this source code.
+ */
+
+namespace CodeIgniter\Commands\Database;
+
+use CodeIgniter\Test\CIUnitTestCase;
+use CodeIgniter\Test\Filters\CITestStreamFilter;
+
+/**
+ * @internal
+ */
+final class MigrateStatusTest extends CIUnitTestCase
+{
+    private $streamFilter;
+    private string $migrationFileFrom = SUPPORTPATH . 'MigrationTestMigrations/Database/Migrations/2018-01-24-102301_Some_migration.php';
+    private string $migrationFileTo   = APPPATH . 'Database/Migrations/2018-01-24-102301_Some_migration.php';
+
+    protected function setUp(): void
+    {
+        parent::setUp();
+
+        if (! is_file($this->migrationFileFrom)) {
+            $this->fail(clean_path($this->migrationFileFrom) . ' is not found.');
+        }
+
+        if (is_file($this->migrationFileTo)) {
+            @unlink($this->migrationFileTo);
+        }
+
+        copy($this->migrationFileFrom, $this->migrationFileTo);
+
+        $contents = file_get_contents($this->migrationFileTo);
+        $contents = str_replace(
+            'namespace Tests\Support\MigrationTestMigrations\Database\Migrations;',
+            'namespace App\Database\Migrations;',
+            $contents
+        );
+        file_put_contents($this->migrationFileTo, $contents);
+
+        CITestStreamFilter::$buffer = '';
+
+        $this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter');
+        $this->streamFilter = stream_filter_append(STDERR, 'CITestStreamFilter');
+    }
+
+    protected function tearDown(): void
+    {
+        parent::tearDown();
+
+        $db = db_connect();
+        $db->table('migrations')->emptyTable();
+
+        if (is_file($this->migrationFileTo)) {
+            @unlink($this->migrationFileTo);
+        }
+
+        stream_filter_remove($this->streamFilter);
+    }
+
+    public function testMigrateAllWithWithTwoNamespaces(): void
+    {
+        command('migrate --all');
+        CITestStreamFilter::$buffer = '';
+
+        command('migrate:status');
+
+        $result   = str_replace(["\033[0;33m", "\033[0m"], '', CITestStreamFilter::$buffer);
+        $result   = preg_replace('/\d{4}-\d\d-\d\d \d\d:\d\d:\d\d/', 'YYYY-MM-DD HH:MM:SS', $result);
+        $expected = <<<'EOL'
+            +---------------+-------------------+--------------------+-------+---------------------+-------+
+            | Namespace     | Version           | Filename           | Group | Migrated On         | Batch |
+            +---------------+-------------------+--------------------+-------+---------------------+-------+
+            | App           | 2018-01-24-102301 | Some_migration     | tests | YYYY-MM-DD HH:MM:SS | 1     |
+            | Tests\Support | 20160428212500    | Create_test_tables | tests | YYYY-MM-DD HH:MM:SS | 1     |
+            +---------------+-------------------+--------------------+-------+---------------------+-------+
+
+
+            EOL;
+        $this->assertSame($expected, $result);
+    }
+
+    public function testMigrateWithWithTwoNamespaces(): void
+    {
+        command('migrate -n App');
+        command('migrate -n Tests\\\\Support');
+        CITestStreamFilter::$buffer = '';
+
+        command('migrate:status');
+
+        $result   = str_replace(["\033[0;33m", "\033[0m"], '', CITestStreamFilter::$buffer);
+        $result   = preg_replace('/\d{4}-\d\d-\d\d \d\d:\d\d:\d\d/', 'YYYY-MM-DD HH:MM:SS', $result);
+        $expected = <<<'EOL'
+            +---------------+-------------------+--------------------+-------+---------------------+-------+
+            | Namespace     | Version           | Filename           | Group | Migrated On         | Batch |
+            +---------------+-------------------+--------------------+-------+---------------------+-------+
+            | App           | 2018-01-24-102301 | Some_migration     | tests | YYYY-MM-DD HH:MM:SS | 1     |
+            | Tests\Support | 20160428212500    | Create_test_tables | tests | YYYY-MM-DD HH:MM:SS | 2     |
+            +---------------+-------------------+--------------------+-------+---------------------+-------+
+
+
+            EOL;
+        $this->assertSame($expected, $result);
+    }
+}