CodeIgniter Forums
Migration on group and namespace - 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: Migration on group and namespace (/showthread.php?tid=79608)



Migration on group and namespace - superior - 07-07-2021

Hi,
I'm trying to run a migration to my maindb group from my modules folder, to do this i've been reading the migration what command to use. This doesn't seem to be working and i'm wondering if it's something wrong on my side or someone has the same issue, below the coding for this and command i've used.
PHP Code:
<?php

namespace Modules\Database\Migrations;

use 
CodeIgniter\Database\Migration;

class 
ModCalendar extends Migration
{
 public function 
up()
 {
 
$this->forge->addField([
 
'id' => ['type' => 'int''constraint' => 11'unsigned' => true'auto_increment' => true],
 
'client_id' => ['type' => 'int''constraint' => 11'unsigned' => true],
 
'subject' => ['type' => 'varchar''constraint' => 255],
 
'weblink' => ['type' => 'varchar''constraint' => 255],
 
'date_start'=> ['type' => 'datetime'],
 
'date_end'  => ['type' => 'datetime''null' => true'default' => null],
 
'created_at'=> ['type' => 'datetime''null' => true'default' => null],
 
'updated_at'=> ['type' => 'datetime''null' => true'default' => null],
 
'deleted_at'=> ['type' => 'datetime''null' => true'default' => null],
 ]);

 
$this->forge->addKey('id'true);
 
$this->forge->addForeignKey('client_id''clients''id'false'CASCADE');

 
// Create table
 
$this->forge->createTable('mod_calendar');
 }

 public function 
down()
 {
 if (
$this->db->DBDriver != 'SQLite3')
        {
            $this->forge->dropForeignKey('mod_calendar''mod_calendar_client_id_foreign');
        }

 
// Drop table
 
$this->forge->dropTable('mod_calendar'true);
 }

With the cmmand:
Code:
php spark migrate -g maindb -n Modules

OR

php spark migrate -g maindb -n Modules\Calendar

Did someone encountered this issue or is it just me?


RE: Migration on group and namespace - paliz - 07-07-2021

I see this problem too you need use - - namespace instead of - n



It s work for me


RE: Migration on group and namespace - superior - 07-07-2021

Hi paliz!

thank you for your answer, did try your solution but it's looking for APPPATH and that's not my directory structure. My modules folder is outside of the app root, it doesn't return any errors when i use the userguide commands but nothing happens inside the query.


RE: Migration on group and namespace - paliz - 07-07-2021

Use rootapp or rootpath


RE: Migration on group and namespace - InsiteFX - 07-08-2021

If you want to know how to do this download Boilerplate by user @agungsugiarto

Look at the folder Commands 
InstallCommand.php and PublishCommand.php

He is re-writing the namespace form the module to the App Path.

Download:
CodeIgniter 4 Application Boilerplate


RE: Migration on group and namespace - superior - 07-09-2021

@InsiteFX According to the documentation the -n is for the namespace, it seems like that isn't working correctly right now?


RE: Migration on group and namespace - InsiteFX - 07-09-2021

I'll look into it and get back to you in a short.


RE: Migration on group and namespace - ARAmiss - 10-18-2021

(07-08-2021, 01:22 AM)InsiteFX Wrote: If you want to know how to do this download Boilerplate by user @agungsugiarto

Look at the folder Commands 
InstallCommand.php and PublishCommand.php

He is re-writing the namespace form the module to the App Path.

Download:
CodeIgniter 4 Application Boilerplate

I also had to write custom spark conmmand because it was not possible to run migrations this way:
Code:
migrate -g mygroup -n mynamespace

I was getting an error:
Code:
Unable to connect to the database.

Main connection [MySQLi]: No such file or directory



RE: Migration on group and namespace - InsiteFX - 10-19-2021

If you change the folder paths then you need to edit the spark file and change the path in it also.

Spark points to the public folder in the root.


RE: Migration on group and namespace - ARAmiss - 10-19-2021

It is not very convenient to customize the default spark file in the root of the site in the case of using modules. But that's just my opinion.
Therefore, I chose the option of adding custom command to the module itself.