Welcome Guest, Not a member yet? Register   Sign In
Migration on group and namespace
#1

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

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



It s work for me
Enlightenment  Is  Freedom
Reply
#3

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

Use rootapp or rootpath
Enlightenment  Is  Freedom
Reply
#5

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

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

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

I'll look into it and get back to you in a short.
What did you Try? What did you Get? What did you Expect?

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

(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
Reply
#9

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB