public function runMigrations()
    {
        // Check we havy any
        if (!file_exists(DIR_MIGRATIONS)) {
            return 0;
        }

        // Have DB already?
        new MigrationEntityRepository;

        // Check we have DB structure and any migration applied
        $migrated_files = [];
        if (SQL::getInstance()->getTables()) {
            $migrated_files = MigrationEntityRepository::getInstance()->getPairs('filename', 'filename');
        }

        $existing_files = FileSystem::scanDirs(DIR_MIGRATIONS);
        if (!$existing_files) {
            return 0;
        }

        $to_migrate = [];
        // Filters migrations that are already done
        foreach ($existing_files as $file) {
            if (isset($migrated_files[$file['name']])) {
                continue;
            }

            $to_migrate[] = $file['name'];
        }

        // Run new migrations
        foreach ($to_migrate as $file) {
            $this->runMigrationFile($file);

            $this->setMigrationFileAsCompleted($file);
        }

        return count($to_migrate);
    }
public function runMigrations()
    {
        // Check we havy any
        if (!file_exists(DIR_MIGRATIONS)) {
            return 0;
        }

        // Have DB already?
        new MigrationEntityRepository;

        // Check we have DB structure and any migration applied
        $migrated_files = [];
        if (SQL::getInstance()->getTables()) {
            $migrated_files = MigrationEntityRepository::getInstance()->getPairs('filename', 'filename');
        }

        $existing_files = FileSystem::scanDirs(DIR_MIGRATIONS);
        if (!$existing_files) {
            return 0;
        }

        $to_migrate = [];
        // Filters migrations that are already done
        foreach ($existing_files as $file) {
            if (isset($migrated_files[$file['name']])) {
                continue;
            }

            $to_migrate[] = $file['name'];
        }

        // Run new migrations
        foreach ($to_migrate as $file) {
            $this->runMigrationFile($file);

            $this->setMigrationFileAsCompleted($file);
        }

        return count($to_migrate);
    }
public function runMigrations ( ) { // Check we havy any if ( ! file_exists ( DIR_MIGRATIONS ) ) { return 0 ; } // Have DB already? new MigrationEntityRepository ; // Check we have DB structure and any migration applied $ migrated_files = [ ] ; if ( SQL :: getInstance ( ) -> getTables ( ) ) { $ migrated_files = MigrationEntityRepository :: getInstance ( ) -> getPairs ( 'filename' , 'filename' ) ; } $ existing_files = FileSystem :: scanDirs ( DIR_MIGRATIONS ) ; if ( ! $ existing_files ) { return 0 ; } $ to_migrate = [ ] ; // Filters migrations that are already done foreach ( $ existing_files as $ file ) { if ( isset ( $ migrated_files [ $ file [ 'name' ] ] ) ) { continue ; } $ to_migrate [ ] = $ file [ 'name' ] ; } // Run new migrations foreach ( $ to_migrate as $ file ) { $ this -> runMigrationFile ( $ file ) ; $ this -> setMigrationFileAsCompleted ( $ file ) ; } return count ( $ to_migrate ) ; }
Run DB migrations from migration .sql files
@return int count of applied migrations
Run DB migrations from migration . sql files