CodeIgniter Forums
[SOLVED] Migrations in modules? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: [SOLVED] Migrations in modules? (/thread-73465.html)



[SOLVED] Migrations in modules? - MeltedRolo - 04-27-2019

Hi guys.

Just trying to get a module migration working and seem to be having a bit of bother.

I have done exactly what is described in the following article ...

Modules_in_CodeIgniter_4

Now my question is, in the migration file, what namespace am I supposed to be using?

And, they are supposed to just work right? no more configuring?

Thanks


RE: Migrations in modules? - InsiteFX - 04-27-2019

It will include all migrations it finds in Database/Migrations.

So by the User Guide you need to store your migrations under your namespace/Database/Migrations


RE: Migrations in modules? - MeltedRolo - 04-27-2019

Hi

Thanks for the response.

My Directory layout is as follows ...

App/ ...
Standard/Auth/Database/Migrations/
System/ ...

etc

My migration file in the above migration dir is 20190427134005_add_auth_users.php

and contains the following ...

PHP Code:
<?php namespace App\Database\Migrations;

use 
CodeIgniter\Database\Migration;

class 
Migration_Add_auth_users extends Migration
{
 public function 
up()
 {
 
$fields = [
 
'id' => ['type' => 'INT''constraint' => 9'unsigned' => true'auto_increment' => true],
 
'title'  => ['type' => 'VARCHAR''constraint' => '100''unique' => true]
 ];

 
$this->forge->addField($fields);
 
$this->forge->addKey('id'true);
 
$this->forge->createTable('users');
 }

 
//--------------------------------------------------------------------

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


I then execute the following in the terminal ...

PHP Code:
php spark migrate:latest -all 

Which is supposed to run all the migrations, but doesnt, only the ones located in the main app directory.

My autoload.php file in the main app config dir is changed as follows ...

PHP Code:
$psr4 = [
 
'Config'      => APPPATH 'Config',
 
APP_NAMESPACE => APPPATH               // For custom namespace
 
'App'         => APPPATH               // To ensure filters, etc still found,
 
'Standard'    => APPPATH '../standard'
]; 

I dunno what I'm doing wrong.


RE: Migrations in modules? - InsiteFX - 04-28-2019

Your namespace for standard should be in the root .

PHP Code:
app
system
standard

'Standard'      => ROOTPATH 'Standard',
'Standard/Auth' => ROOTPATH 'Standard/Auth'

When you use APPPATH or ROOTPATH you do not add the forward slash either.


RE: Migrations in modules? - MGatner - 04-28-2019

What InsiteFX said is right, and just to point out the main difference is your path is missing the “/Auth” at the end of your namespace.


RE: Migrations in modules? - MeltedRolo - 04-28-2019

Ahh I see.

Didn't realise that, thanks very much.


RE: Migrations in modules? - MeltedRolo - 04-28-2019

Hi again.

So I managed to get it do something, unfortunately it's still not working.

When I run the migrate all command I get the following ...


Code:
The migration class "Standard\Auth\Database\Migrations\Migration_add_auth_users" could not be found.
C:\xampp\www\public\ci4\system\Database\MigrationRunner.php - 274


Think it has something to do with the namespace, because its finding the file, but cant find the class inside the file.


RE: Migrations in modules? - MeltedRolo - 04-28-2019

Sorted.

So my original question was ...


Quote:Now my question is, in the migration file, what namespace am I supposed to be using?


And the answer is ...


PHP Code:
<? namespace Standard\Auth\Database\Migrations