Move migration files.

@return null
176873
public function moveMigrationFiles()
    {
        $databaseDirectory = base_path('Modules/'.$this->module.'/database');
        if (!$this->files->exists($databaseDirectory.'/migrations')) {
            return;
        }
        $files = $this->files->files($databaseDirectory.'/migrations');
        foreach ($files as $from) {
            $file = basename($from);
            $to = base_path('database/migrations/'.$file);
            $this->files->move($from, $to);
        }
        $this->files->deleteDirectory($databaseDirectory);
    }
836664
private function migrate()
    {
        $action = $this->arg->getParameter('action');

        if (!is_null($action)) {
            $this->throwFailsCommand('This action is not allow!', 'help migration');
        }

        $this->command->call(
            'migrate',
            'migration',
            null
        );
    }
75086
public function down()
    {
        // Check if the images table exists
        if (Schema::hasTable('images')) {
            if (Schema::hasColumn('images', 'imageable_type')) {
                $images = DB::select('select * from images');
                foreach ($images as $image) {
                    // Get the model name
                    $old_type_array = explode('\\', $image->imageable_type);
                    $last_model = array_pop($old_type_array);
                    
                    // Move image back to old folder
                    $image_folder = Config::get('redminportal::image.upload_dir');
                    $filename_array = explode('/', $image->path);
                    $filename = array_pop($filename_array);
                    
                    switch ($last_model) {
                        case 'Category':
                            $move_file = $this->moveFileOldToNew($image_folder, $image, 'categories');
                            break;
                        case 'Media':
                            $move_file = $this->moveFileOldToNew($image_folder, $image, 'medias');
                            break;
                        case 'Module':
                            $move_file = $this->moveFileOldToNew($image_folder, $image, 'modules');
                            break;
                        case 'Promotion':
                            $move_file = $this->moveFileOldToNew($image_folder, $image, 'promotions');
                            break;
                        default:
                            $move_file = false;
                            break;
                    }
                    
                    // Remove folder if move succeed
                    if ($move_file) {
                        $this->recursiveRemoveDirectory(public_path() . '/' . $move_file);
                    }
                    
                    // Points to old namespace Redooor\\Redminportal\\
                    $old_type = 'Redooor\\Redminportal\\' . $last_model;
                    DB::table('images')
                        ->where('id', $image->id)
                        ->update([
                            'imageable_type' => $old_type,
                            'path' => ($move_file ? $filename : $image->path)
                        ]);
                }
            }
        }
    }
1193586
public function up()
    {
        Schema::create('attachments', function (Blueprint $table) {
            $table->increments('id');
            $table->text('name');
            $table->text('original_name');
            $table->string('mime');
            $table->string('extension')->nullable();
            $table->bigInteger('size')->default(0);
            $table->integer('sort')->default(0);
            $table->text('path');
            $table->text('description')->nullable();
            $table->text('alt')->nullable();
            $table->text('hash')->nullable();
            $table->string('disk')->default('public');
            $table->unsignedBigInteger('user_id')->nullable();
            $table->string('group')->nullable();
            $table->timestamps();
        });

        Schema::create('attachmentable', function (Blueprint $table) {
            $table->increments('id');
            $table->string('attachmentable_type');
            $table->unsignedInteger('attachmentable_id');
            $table->unsignedInteger('attachment_id');

            $table->index(['attachmentable_type', 'attachmentable_id']);

            $table->foreign('attachment_id')
                ->references('id')
                ->on('attachments')
                ->onUpdate('cascade')
                ->onDelete('cascade');
        });
    }
993666
public function up()
    {
        Schema::create('FILE_File', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name' , 100);
            $table->char('type' , 1);
            $table->string('system_type', 100)->nullable();
            $table->string('system_route')->nullable();
            $table->text('url')->nullable();
            $table->text('url_html')->nullable();
            $table->boolean('is_public')->default(false);
            $table->string('key')->nullable();
            $table->string('icon' , 20)->nullable();
            $table->string('icon_html')->nullable();
            $table->float('width')->nullable();
            $table->float('height')->nullable();
            $table->unsignedInteger('parent_file_id')->nullable();
            $table->string('system_reference_type' , 40)->nullable();
            $table->unsignedInteger('system_reference_id')->nullable();

            //Foreign Keys
            $table->unsignedInteger('organization_id');

            //Timestamps
      			$table->timestamps(); //Adds created_at and updated_at columns
      			$table->softDeletes(); //Adds deleted_at column for soft deletes
        });

        Schema::table('FILE_File', function(Blueprint $table)
        {
          //Foreign Key
          $table->foreign('parent_file_id')->references('id')->on('FILE_File');
        });
    }
1220151
public function up()
    {
        Schema::create('files', function (Blueprint $table) {
            $table->increments('id');
            $table->string('file_id')->unique();
            $table->string('name');
            $table->string('extension')->nullable();
            $table->string('path')->nullable();
            $table->string('mime_type');
            $table->integer('byte_size');
            $table->json('data');
            $table->string('disk');
            $table->dateTime('saved_at');
        });
    }
601345
protected function moveSettings()
    {
        try {
            if (!$this->fs->exists($this->appRoot.'/sites/'.$this->directory.'/settings.php')) {
                $this->fs->copy(
                    $this->appRoot.'/sites/'.$this->uri.'/settings.php',
                    $this->appRoot.'/sites/'.$this->directory.'/settings.php'
                );
                $this->fs->remove($this->appRoot.'/sites/'.$this->uri.'/settings.php');
            }
        } catch (IOExceptionInterface $e) {
            $this->getIo()->error(
                sprintf(
                    $this->trans('commands.multisite.update.errors.copy-fail'),
                    $this->appRoot.'/sites/'.$this->explodeDirectory[0].'/settings.php',
                    $this->directory.'/settings.php'
                )
            );
            return 1;
        }
    }
1074204
public function migrate()
	{
		$this->msg( 'Update charset and collation for Laravel tables', 0 );
		$this->status( '' );

		foreach( $this->tables as $rname => $list ) {
			$this->checkTables( $list, $rname );
		}
	}
495487
private function runMigration()
    {
        $this->info("Running database migration...");
        $this->call('migrate', ['--force' => true]);

        $this->line('');
        $this->advanceBar();

        $this->clearCaches();
        return $this;
    }
888889
protected function copyMigrations() : void
    {
        $this->stdout("\nCopy the migration files in a temp directory\n", Console::FG_YELLOW);
        FileHelper::removeDirectory($this->migrationPath);
        FileHelper::createDirectory($this->migrationPath);
        if (!is_dir($this->migrationPath)) {
            $this->stdout("Could not create a temporary directory migration\n", Console::FG_RED);
            exit();
        }
        $this->stdout("\tCreated a directory migration\n", Console::FG_GREEN);
        if ($dirs = $this->findMigrationDirs()) {
            foreach ($dirs as $dir) {
                FileHelper::copyDirectory($dir, $this->migrationPath);
            }
        }
        $this->stdout("\tThe copied files components migrations\n", Console::FG_GREEN);
        $appMigrateDir = \Yii::getAlias("@app/commands");
        if (is_dir($appMigrateDir)) {
            FileHelper::copyDirectory($appMigrateDir, $this->migrationPath);
        }
        $this->stdout("\tThe copied files app migrations\n\n", Console::FG_GREEN);
    }
1010440
private function moveFilesToDatabaseMigrations( $folder )
	{
		$moved = array();
        if( ! file_exists( base_path( 'database/migrations/vendor/' . $this->currentStructure['vendor'] ) ) ) {
            mkdir( base_path( 'database/migrations/vendor/' . $this->currentStructure['vendor'] ), 0777 );
        }
        if( ! file_exists( base_path( 'database/migrations/vendor/' . $this->currentStructure['vendor'] . '/' . $this->currentStructure['module'] ) ) ) {
            mkdir( base_path( 'database/migrations/vendor/' . $this->currentStructure['vendor'] . '/' . $this->currentStructure['module'] ), 0777 );
        }
		foreach( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $folder ) ) as $file ) {
			if( $file->getExtension() === 'php' ) {
				copy( $folder . $file->getBasename(), base_path( 'database/migrations/vendor/' . $this->currentStructure['vendor'] . '/' . $this->currentStructure['module'] . '/' . $file->getBasename() ) );
				$moved[] = $file->getBasename() . ' moved to database/migrations';
				unlink( $folder . $file->getBasename() );
			}
		}
		if( ! $moved ) {
			$this->line( 'no migrations to move' );
		} else {
			foreach( $moved as $message ) {
				$this->info( $message );
			}
		}
	}
191146
public function up()
    {
        $this->create('migrations', function ($table) {
            // Place table rows here
            $table->increments('id');
            $table->string('migration');
            $table->integer('migrated');
            $table->timestamps();
        });
    }
1315214
private function moveFiles()
    {
        // Ensure we have the file permissions not in cache as new files were installed.
        clearstatcache();
        // Now move all the files over.
        $destinationDir = $this->file->get(self::SETTING_DESTINATION_DIR);
        $ioHandler      = $this->getIO();
        $logging        = $ioHandler->isVeryVerbose();
        $this->folders  = [];
        foreach (Finder::create()->in($this->tempDir)->ignoreDotFiles(false)->ignoreVCS(false) as $file) {
            $this->moveFile($file, $destinationDir, $logging, $ioHandler);
        }

        foreach (array_reverse($this->folders) as $folder) {
            if ($logging) {
                $ioHandler->write(sprintf('remove directory %s', $folder));
            }
            rmdir($folder);
        }
    }
834674
protected function setMigrationFiles()
    {
        $result = [];
        foreach ($this->allMigrationPaths as $paths) {
            if (!is_array($paths)) {
                $paths = [$paths];
            }

            foreach ($paths as $path) {
                if (!file_exists($path) || is_file($path)) {
                    continue;
                }
                $handle = opendir($path);
                while (($file = readdir($handle)) !== false) {
                    if ($file === '.' || $file === '..') {
                        continue;
                    }
                    $filePath = $path . DIRECTORY_SEPARATOR . $file;
                    if (preg_match('/^(m(\d{6}_\d{6})_.*?)\.php$/', $file, $matches) && is_file($filePath)) {
                        $result[$filePath] = $matches[1];
                    }
                }
                closedir($handle);
            }
        }
        return $this->migrationFiles = $result;
    }
1026295
protected function migrate_course_files() {
        $ids  = array();
        $fileman = $this->converter->get_file_manager($this->converter->get_contextid(CONTEXT_COURSE), 'course', 'legacy');
        $this->converter->set_stash('course_files_ids', array());
        if (file_exists($this->converter->get_tempdir_path().'/course_files')) {
            $ids = $fileman->migrate_directory('course_files');
            $this->converter->set_stash('course_files_ids', $ids);
        }
        $this->log('course files migrated', backup::LOG_INFO, count($ids));
    }
697602
public function up()
    {
        $driver = Schema::getConnection()->getDriverName();
        // Even though we take care of this scenario in the code,
        // SQL Server does not allow potential cascading loops,
        // so set the default no action and clear out created/modified by another user when deleting a user.
        $onDelete = (('sqlsrv' === $driver) ? 'no action' : 'set null');

        $output = new ConsoleOutput();
        $output->writeln("Migration driver used: $driver");

        // User table
        Schema::create(
            'user',
            function (Blueprint $t) use ($onDelete){
                $t->increments('id');
                $t->string('name');
                $t->string('first_name')->nullable();
                $t->string('last_name')->nullable();
                $t->dateTime('last_login_date')->nullable();
                $t->string('email')->unique();
                $t->text('password')->nullable();
                $t->boolean('is_sys_admin')->default(0);
                $t->boolean('is_active')->default(1);
                $t->string('phone', 32)->nullable();
                $t->string('security_question')->nullable();
                $t->text('security_answer')->nullable();
                $t->string('confirm_code')->nullable();
                $t->integer('default_app_id')->unsigned()->nullable();
                $t->rememberToken();
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
                $t->integer('created_by_id')->unsigned()->nullable();
                $t->foreign('created_by_id')->references('id')->on('user')->onDelete($onDelete);
                $t->integer('last_modified_by_id')->unsigned()->nullable();
                $t->foreign('last_modified_by_id')->references('id')->on('user')->onDelete($onDelete);
            }
        );

        // Password reset table
        Schema::create(
            'password_resets',
            function (Blueprint $t){
                $t->string('email')->index();
                $t->string('token')->index();
                $t->timestamp('created_date')->nullable();
            }
        );

        // Services
        Schema::create(
            'service',
            function (Blueprint $t) use ($onDelete){
                $t->increments('id');
                $t->string('name', 40)->unique();
                $t->string('label', 80);
                $t->string('description')->nullable();
                $t->boolean('is_active')->default(0);
                $t->string('type', 40);
                $t->boolean('mutable')->default(1);
                $t->boolean('deletable')->default(1);
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
                $t->integer('created_by_id')->unsigned()->nullable();
                $t->foreign('created_by_id')->references('id')->on('user')->onDelete($onDelete);
                $t->integer('last_modified_by_id')->unsigned()->nullable();
                $t->foreign('last_modified_by_id')->references('id')->on('user')->onDelete($onDelete);
            }
        );

        // Service API Docs
        Schema::create(
            'service_doc',
            function (Blueprint $t){
                $t->integer('service_id')->unsigned()->primary();
                $t->foreign('service_id')->references('id')->on('service')->onDelete('cascade');
                $t->integer('format')->unsigned()->default(0);
                $t->mediumText('content')->nullable();
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
            }
        );

        // Roles
        Schema::create(
            'role',
            function (Blueprint $t) use ($onDelete){
                $t->increments('id');
                $t->string('name', 64)->unique();
                $t->string('description')->nullable();
                $t->boolean('is_active')->default(0);
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
                $t->integer('created_by_id')->unsigned()->nullable();
                $t->foreign('created_by_id')->references('id')->on('user')->onDelete($onDelete);
                $t->integer('last_modified_by_id')->unsigned()->nullable();
                $t->foreign('last_modified_by_id')->references('id')->on('user')->onDelete($onDelete);
            }
        );

        // Roles to Services Allowed Accesses
        Schema::create(
            'role_service_access',
            function (Blueprint $t) use ($onDelete){
                $t->increments('id');
                $t->integer('role_id')->unsigned();
                $t->foreign('role_id')->references('id')->on('role')->onDelete('cascade');
                $t->integer('service_id')->unsigned()->nullable();
                $t->foreign('service_id')->references('id')->on('service')->onDelete('cascade');
                $t->string('component')->nullable();
                $t->integer('verb_mask')->unsigned()->default(0);
                $t->integer('requestor_mask')->unsigned()->default(0);
                $t->text('filters')->nullable();
                $t->string('filter_op', 32)->default('and');
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
                $t->integer('created_by_id')->unsigned()->nullable();
                $t->foreign('created_by_id')->references('id')->on('user')->onDelete($onDelete);
                $t->integer('last_modified_by_id')->unsigned()->nullable();
                $t->foreign('last_modified_by_id')->references('id')->on('user')->onDelete($onDelete);
            }
        );

        // Email Templates
        Schema::create(
            'email_template',
            function (Blueprint $t) use ($onDelete){
                $t->increments('id');
                $t->string('name', 64)->unique();
                $t->string('description')->nullable();
                $t->text('to')->nullable();
                $t->text('cc')->nullable();
                $t->text('bcc')->nullable();
                $t->string('subject', 80)->nullable();
                $t->text('body_text')->nullable();
                $t->text('body_html')->nullable();
                $t->string('from_name', 80)->nullable();
                $t->string('from_email')->nullable();
                $t->string('reply_to_name', 80)->nullable();
                $t->string('reply_to_email')->nullable();
                $t->text('defaults')->nullable();
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
                $t->integer('created_by_id')->unsigned()->nullable();
                $t->foreign('created_by_id')->references('id')->on('user')->onDelete($onDelete);
                $t->integer('last_modified_by_id')->unsigned()->nullable();
                $t->foreign('last_modified_by_id')->references('id')->on('user')->onDelete($onDelete);
            }
        );

        //Cors config table
        Schema::create(
            'cors_config',
            function (Blueprint $t) use ($onDelete){
                $t->increments('id');
                $t->string('path')->unique();
                $t->string('origin')->nullable();
                $t->text('header')->nullable();
                $t->integer('method')->unsigned()->default(0);
                $t->integer('max_age')->unsigned()->default(0);
                $t->boolean('enabled')->default(true);
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
                $t->integer('created_by_id')->unsigned()->nullable();
                $t->foreign('created_by_id')->references('id')->on('user')->onDelete($onDelete);
                $t->integer('last_modified_by_id')->unsigned()->nullable();
                $t->foreign('last_modified_by_id')->references('id')->on('user')->onDelete($onDelete);
            }
        );

        // Applications
        Schema::create(
            'app',
            function (Blueprint $t) use ($onDelete){
                $t->increments('id');
                $t->string('name', 64)->unique();
                $t->string('api_key')->nullable();
                $t->string('description')->nullable();
                $t->boolean('is_active')->default(0);
                $t->integer('type')->unsigned()->default(0);
                $t->text('path')->nullable();
                $t->text('url')->nullable();
                $t->integer('storage_service_id')->unsigned()->nullable();
                $t->foreign('storage_service_id')->references('id')->on('service')->onDelete('set null');
                $t->string('storage_container', 255)->nullable();
                $t->boolean('requires_fullscreen')->default(0);
                $t->boolean('allow_fullscreen_toggle')->default(1);
                $t->string('toggle_location', 64)->default('top');
                $t->integer('role_id')->unsigned()->nullable();
                $t->foreign('role_id')->references('id')->on('role')->onDelete('set null');
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
                $t->integer('created_by_id')->unsigned()->nullable();
                $t->foreign('created_by_id')->references('id')->on('user')->onDelete($onDelete);
                $t->integer('last_modified_by_id')->unsigned()->nullable();
                $t->foreign('last_modified_by_id')->references('id')->on('user')->onDelete($onDelete);
            }
        );

        // App relationship for user
        Schema::create(
            'user_to_app_to_role',
            function (Blueprint $t){
                $t->increments('id');
                $t->integer('user_id')->unsigned();
                $t->foreign('user_id')->references('id')->on('user')->onDelete('cascade');
                $t->integer('app_id')->unsigned();
                $t->foreign('app_id')->references('id')->on('app')->onDelete('cascade');
                $t->integer('role_id')->unsigned();
                $t->foreign('role_id')->references('id')->on('role')->onDelete('cascade');
            }
        );

        // JSON Web Token to system resources map
        Schema::create(
            'token_map',
            function (Blueprint $t){
                $t->integer('user_id')->unsigned();
                $t->foreign('user_id')->references('id')->on('user')->onDelete('cascade');
                $t->text('token');
                $t->integer('iat')->unsigned();
                $t->integer('exp')->unsigned();
            }
        );

        Schema::create(
            'file_service_config',
            function (Blueprint $t){
                $t->integer('service_id')->unsigned()->primary();
                $t->foreign('service_id')->references('id')->on('service')->onDelete('cascade');
                $t->text('public_path')->nullable();
                $t->text('container')->nullable();
            }
        );

        Schema::create(
            'service_cache_config',
            function (Blueprint $t){
                $t->integer('service_id')->unsigned()->primary();
                $t->foreign('service_id')->references('id')->on('service')->onDelete('cascade');
                $t->boolean('cache_enabled')->default(0);
                $t->integer('cache_ttl')->unsigned()->default(0);
            }
        );

        // System Configuration
        Schema::create(
            'system_config',
            function (Blueprint $t) use ($onDelete){
                $t->integer('service_id')->unsigned()->primary();
                $t->foreign('service_id')->references('id')->on('service')->onDelete('cascade');
                $t->integer('default_app_id')->unsigned()->nullable();
                $t->foreign('default_app_id')->references('id')->on('app')->onDelete('set null');
                $t->integer('invite_email_service_id')->unsigned()->nullable();
                $t->foreign('invite_email_service_id')->references('id')->on('service')->onDelete($onDelete);
                $t->integer('invite_email_template_id')->unsigned()->nullable();
                $t->foreign('invite_email_template_id')->references('id')->on('email_template')->onDelete($onDelete);
                $t->integer('password_email_service_id')->unsigned()->nullable();
                $t->foreign('password_email_service_id')->references('id')->on('service')->onDelete($onDelete);
                $t->integer('password_email_template_id')->unsigned()->nullable();
                $t->foreign('password_email_template_id')->references('id')->on('email_template')->onDelete($onDelete);
            }
        );

        // create system customizations
        Schema::create(
            'system_custom',
            function (Blueprint $t) use ($onDelete){
                $t->string('name')->primary();
                $t->mediumText('value')->nullable();
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
                $t->integer('created_by_id')->unsigned()->nullable();
                $t->foreign('created_by_id')->references('id')->on('user')->onDelete($onDelete);
                $t->integer('last_modified_by_id')->unsigned()->nullable();
                $t->foreign('last_modified_by_id')->references('id')->on('user')->onDelete($onDelete);
            }
        );

        // Lookups
        Schema::create(
            'lookup',
            function (Blueprint $t) use ($onDelete){
                $t->increments('id');
                $t->integer('app_id')->unsigned()->nullable();
                $t->foreign('app_id')->references('id')->on('app')->onDelete('cascade');
                $t->integer('role_id')->unsigned()->nullable();
                $t->foreign('role_id')->references('id')->on('role')->onDelete('cascade');
                $t->integer('user_id')->unsigned()->nullable();
                $t->foreign('user_id')->references('id')->on('user')->onDelete('cascade');
                $t->string('name');
                $t->text('value')->nullable();
                $t->boolean('private')->default(0);
                $t->text('description')->nullable();
                $t->timestamp('created_date')->nullable();
                $t->timestamp('last_modified_date')->useCurrent();
                $t->integer('created_by_id')->unsigned()->nullable();
                $t->foreign('created_by_id')->references('id')->on('user')->onDelete($onDelete);
                $t->integer('last_modified_by_id')->unsigned()->nullable();
                $t->foreign('last_modified_by_id')->references('id')->on('user')->onDelete($onDelete);
            }
        );
    }
312504
protected function bootMigrations()
    {
        if (isset($this->dir) and isset($this->migrationDirs) and is_array($this->migrationDirs)) {
            foreach ($this->migrationDirs as $dirPath) {
                $this->publishes([ $this->getDatabasePath($dirPath) => database_path($this->migrationDestinationPath) ], 'migrations');
            }
        }
    }