CodeIgniter Forums
How to Run Migration via PHP Code? - 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: How to Run Migration via PHP Code? (/showthread.php?tid=90459)



How to Run Migration via PHP Code? - RedWd - 03-21-2024

Hi, i already use migration via cli, now i want to run php spark migrate --all via php controller. How can i do this? Thank you


RE: How to Run Migration via PHP Code? - luckmoshy - 03-21-2024

(03-21-2024, 08:43 AM)RedWd Wrote: Hi, i already use migration via cli, now i want to run php spark migrate --all via php controller. How can i do this? Thank you

maybe you can do something like this
PHP Code:
$this->migrate = \Config\Services::migrations()


private function 
runAllMaigrate (){
        try {
            if($this->migrate){
 
$this->migrate->latest();
 }
        } catch (\Throwable $e) {
            die('there is a critical issue on running migration '.$e->getMessage());
 exit();
        }
 }