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


Messages In This Thread
Can't get migration in module to be recognised by spark migrate --all - by BuckMulligan_ - 01-07-2025, 02:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB