Welcome Guest, Not a member yet? Register   Sign In
Can't get migration in module to be recognised by spark migrate --all
#1

(This post was last modified: 01-07-2025, 02:07 PM by BuckMulligan_.)

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.
Reply
#2

Please wait until the end of day, I' am working on and testing this out now.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(This post was last modified: 01-08-2025, 01:40 AM by BuckMulligan_.)

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.
Reply
#5

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?)
Reply
#6

You have to pass the name space with the Seeder:
Code:
php spark db:seed Modules\YourModuleName\Database\Seeds\YourSeederName
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

I'm not using seeder at all.
Reply
#8

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB