public static function execute($migrationsInstance) { $executed = Db::query('SELECT alias FROM db_migrations')->fetchAll(\PDO::FETCH_COLUMN); $rc = new \ReflectionClass($migrationsInstance); foreach ($rc->getMethods() as $method) { $method instanceof \ReflectionMethod; // if migration method not executed, run if (!in_array($method->name, $executed)) { // invoke the method try { $method->invoke($migrationsInstance); $failed = false; } catch (\Exception $e) { // when sql error ... $failed = true; } // save flag to migrations table Db::save('db_migrations', array('alias' => $method->name, 'failed' => $failed)); } } }