CodeIgniter Forums
Can't get migration in module to be recognised by spark migrate --all - 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: Can't get migration in module to be recognised by spark migrate --all (/showthread.php?tid=92295)



Can't get migration in module to be recognised by spark migrate --all - BuckMulligan_ - 01-07-2025

I have modules separate to the app namespace. I'm following the instructions about modules and trying to run a migration that lives under my own namespace, but spark migrate is completely ignoring it and I can't figure out why.

My file structure:

app
midair
system

I have the following code:

app/Config/Autoload.php
PHP Code:
public $psr4 = [
    APP_NAMESPACE => APPPATH,
    'Midair\Article' => ROOTPATH 'midair/Article',
]; 

midair/Article/Database/Migrations/2025-01-07-195230_CreateArticle.php
PHP Code:
namespace Midair\Article\Database\Migrations;

use 
CodeIgniter\Database\Migration;

class 
CreateArticle extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'          => 'INT',
                'constraint'    => 5,
                'unsigned'      => true,
                'auto_increment' => true,
            ],
            'title' => [
                'type'      => 'VARCHAR',
                'constraint' => '255',
            ],
            'link' => [
                'type'      => 'VARCHAR',
                'constraint' => '255',
            ],
            'description' => [
                'type'      => 'TEXT',
            ],
            'author' => [
                'type'      => 'VARCHAR',
                'constraint' => '255',
            ],
            'categories' => [
                'type'      => 'VARCHAR',
                'constraint' => '255',
            ],
            'guid' => [
                'type'      => 'VARCHAR',
                'constraint' => '255',
            ],
            'pubDate' => [
                'type' => 'DATETIME',
            ],
            'content' => [
                'type' => 'TEXT',
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->addKey('pubDate');
        $this->forge->addUniqueKey('link');
        $this->forge->createTable('articles');
    }

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


And then when my server starts I'm executing
Code:
php spark migrate --all

I've tested moving the migration into app/Database/Migrations (and adjusting the namespace) and it works fine, but for some reason it's refusing to see the migration when it lives under my own namespace. I also tried running php spark migrate -n Midair\\Article and that also didn't work.


RE: Can't get migration in module to be recognised by spark migrate --all - InsiteFX - 01-07-2025

Please wait until the end of day, I' am working on and testing this out now.


RE: Can't get migration in module to be recognised by spark migrate --all - InsiteFX - 01-07-2025

PHP Code:
'Midair\Article' => ROOTPATH 'midair/Article',

// should be
'Midair\Article' => ROOTPATH 'Midair/Article'

There is a bug with the Seeder and Module which has been reported.

The Module Migrations work just fine if your Autoload namespaces are correct, this has just been tested
by me.


RE: Can't get migration in module to be recognised by spark migrate --all - BuckMulligan_ - 01-08-2025

Even though my folder name is lowercase? Why would that work?

Edit: I tried your suggestion and it didn't make any difference. I also tried renaming my module folder to capitalized Midair, same thing.


RE: Can't get migration in module to be recognised by spark migrate --all - BuckMulligan_ - 01-08-2025

Update: I've verified that a Route added under midair/Article/Config.Routes.php works fine, so the app is correctly detecting the autoloaded namespace. It's just the migration from that module that isn't being seen by the php spark call.

I'm executing the php spark --all call on a Docker instance, but I don't see how that can make any difference (and I've already seen it run migrations that are under app).

(PS: Why are you replying to me but not approving my moderated posts?)


RE: Can't get migration in module to be recognised by spark migrate --all - InsiteFX - 01-08-2025

You have to pass the name space with the Seeder:
Code:
php spark db:seed Modules\YourModuleName\Database\Seeds\YourSeederName



RE: Can't get migration in module to be recognised by spark migrate --all - BuckMulligan_ - 01-09-2025

I'm not using seeder at all.


RE: Can't get migration in module to be recognised by spark migrate --all - BuckMulligan_ - 01-09-2025

Solved the problem. Entirely my dumb fault - I had changed the php spark migrate call in my Dockerfile, but had forgotten to rebuild the image. Now it's working as expected. Thanks for your help.