src/console/controllers/Migrate.php
public function up($limit = null) {

        $applied = 0;

        $migrations = $this->migrations_list;

        $limit = (int)$limit;

        if ($limit > 0) {
            $migrations = array_slice($migrations, 0, $limit);
        }

        foreach ($migrations as $migration) {

            if ($migration['applied'])
                continue;

            $name = $migration['name'];

            $this->info('Loading migration #:name', [':name' => $name]);

            $obj = $this->load_migration($migration);
            $obj->init();
            if ($obj->up() === false) {
                $this->error('Migration #:name failed. Stop.', [':name' => $name]);
                return;
            };

            DB::begin();
            try {
                $obj->safe_up();
                DB::commit();
            } catch (\Throwable $e) {
                DB::rollback();
            }

            DB::insert('INSERT INTO`' . $this->migrate_table . '`(`name`, `date`) VALUES(:name, :date)',
                [
                    ':name' => $name,
                    ':date' => time()
                ]);

            $this->info('Migration up successfully', [':name' => $name]);
            $applied++;

        }
        if (!$applied) {
            $this->warning('No new migration found');
        }
    }
public function up($limit = null) {

        $applied = 0;

        $migrations = $this->migrations_list;

        $limit = (int)$limit;

        if ($limit > 0) {
            $migrations = array_slice($migrations, 0, $limit);
        }

        foreach ($migrations as $migration) {

            if ($migration['applied'])
                continue;

            $name = $migration['name'];

            $this->info('Loading migration #:name', [':name' => $name]);

            $obj = $this->load_migration($migration);
            $obj->init();
            if ($obj->up() === false) {
                $this->error('Migration #:name failed. Stop.', [':name' => $name]);
                return;
            };

            DB::begin();
            try {
                $obj->safe_up();
                DB::commit();
            } catch (\Throwable $e) {
                DB::rollback();
            }

            DB::insert('INSERT INTO`' . $this->migrate_table . '`(`name`, `date`) VALUES(:name, :date)',
                [
                    ':name' => $name,
                    ':date' => time()
                ]);

            $this->info('Migration up successfully', [':name' => $name]);
            $applied++;

        }
        if (!$applied) {
            $this->warning('No new migration found');
        }
    }
public function up ( $ limit = null ) { $ applied = 0 ; $ migrations = $ this -> migrations_list ; $ limit = ( int ) $ limit ; if ( $ limit > 0 ) { $ migrations = array_slice ( $ migrations , 0 , $ limit ) ; } foreach ( $ migrations as $ migration ) { if ( $ migration [ 'applied' ] ) continue ; $ name = $ migration [ 'name' ] ; $ this -> info ( 'Loading migration #:name' , [ ':name' => $ name ] ) ; $ obj = $ this -> load_migration ( $ migration ) ; $ obj -> init ( ) ; if ( $ obj -> up ( ) === false ) { $ this -> error ( 'Migration #:name failed. Stop.' , [ ':name' => $ name ] ) ; return ; } ; DB :: begin ( ) ; try { $ obj -> safe_up ( ) ; DB :: commit ( ) ; } catch ( \ Throwable $ e ) { DB :: rollback ( ) ; } DB :: insert ( 'INSERT INTO`' . $ this -> migrate_table . '`(`name`, `date`) VALUES(:name, :date)' , [ ':name' => $ name , ':date' => time ( ) ] ) ; $ this -> info ( 'Migration up successfully' , [ ':name' => $ name ] ) ; $ applied ++ ; } if ( ! $ applied ) { $ this -> warning ( 'No new migration found' ) ; } }
Apply new migrations
Apply new migrations