Creates the migration file for the given table.
@return mixed|string
@todo softDeletes, timestamps
173834
protected function createMigrationFile()
    {
        $fieldObjects = $this->getFields();

        if (@$fieldObjects['id']) {
            unset($fieldObjects['id']);
        }

        if (@$fieldObjects['created_at'] && @$fieldObjects['updated_at']) {
            $this->addGenericCall((new Base())->timestamps());

            unset($fieldObjects['created_at'], $fieldObjects['updated_at']);
        } // if

        if (@$fieldObjects['deleted_at']) {
            $this->addGenericCall((new Base())->softDeletes());

            unset($fieldObjects['deleted_at']);
        } // if

        $schema = implode(', ', $fieldObjects);

        if (strpos($schema, 'enum') !== false) {
            $this->getCommand()->info(sprintf('Please change the enum field of table "%s" manually.',
                $this->getName()));
        }

        if ($this->isPivotTable()) {
            $tables = array_keys($this->getForeignKeys());

            Artisan::call(
                'make:migration:pivot',
                [
                    'tableOne' => $tables[0],
                    'tableTwo' => $tables[1]
                ]
            );
        } else {
            Artisan::call(
                'make:migration:schema',
                [
                    'name' => "create_{$this->getName()}_table",
                    '--model' => $this->needsLaravelModel(),
                    '--schema' => $fieldObjects ? $schema : ''
                ]
            );

            $migrationFiles = glob(
                database_path('migrations') . DIRECTORY_SEPARATOR . "*_create_{$this->getName()}_table.php"
            );
        }

        return @$migrationFiles ? end($migrationFiles) : '';
    }
255703
public function table()
    {
        return $this->database ? $this->laravel['db']->connection($this->database)->table(config('database.migrations')) : $this->laravel['db']->table(config('database.migrations'));
    }
390285
protected function exportCreateTable()
    {
        $table = new Table(self::TABLE_NAME, array(), array(), array(), false, array());
        $table->addColumn('id', 'string', array('length' => 64, 'notnull' => true));
        $table->setPrimaryKey(array('id'));
        $table->addColumn('value', 'string', array('length' => 64));

        $sql = $this->getConnection()
            ->getDatabasePlatform()
            ->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)
        ;

        return array_pop($sql).';'.PHP_EOL;
    }
1127267
public function getTableDumper()
    {
        if ($this->migrated) {
            return new TableDumper($this->getEntities());
        }

        return new FieldsDumper($this->console->option('fields'));
    }
955337
public function moveMigrationFile()
    {
        $from = base_path('Modules/'.$this->module.'/database/migrations/2016_01_04_225000_create_objects_table.php');
        $to = base_path('database/migrations/'.date('Y_m_d_His').'_create_'.strtolower($this->module).'_table.php');
        $this->files->move($from, $to);
    }
570835
public function generateMigration(): string
    {
        return $this->view->renderFile(Yii::getAlias($this->templateFile), [
            'table' => $this->table,
            'className' => $this->className,
            'namespace' => $this->normalizedNamespace
        ]);
    }
981712
public function getMigrations( )
    {
        $migrations = array();
        
        $dir = opendir( $this->migrationPath );
        
        while ( ( $file = readdir( $dir ) ) !== FALSE )
        {
            if ( '.' !== $file && '..' !== $file )
            {
                $migrations[] = str_replace( '.php', '', $file );
            }
        }
        
        closedir( $dir );
        
        usort( $migrations, array( $this, '_sortMigrations' ) );
        
        return $this->filter( self::ON_GET_MIGRATIONS_FILTER, $migrations );
    }
54705
private function createMigrationsTable($db)
	{
		$this->log('Migrations table did not exist...attempting to create it now');

		$query = "CREATE TABLE `{$this->get('tbl_name')}` (
					`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
					`file` varchar(255) NOT NULL DEFAULT '',
					`scope` varchar(255) NOT NULL,
					`hash` char(32) NOT NULL DEFAULT '',
					`direction` varchar(10) NOT NULL DEFAULT '',
					`date` datetime NOT NULL,
					`action_by` varchar(255) NOT NULL DEFAULT '',
					`status` varchar(255) NOT NULL DEFAULT '',
					PRIMARY KEY (`id`)
				) ENGINE=InnoDB DEFAULT CHARSET=utf8;";

		// Try creating the migrations table now
		try
		{
			$db->setQuery($query);
			$db->query();
			$this->log('Migrations table successfully created');
			return true;
		}
		catch (\Hubzero\Database\Exception\QueryFailedException $e)
		{
			$this->log('Unable to create needed migrations table', 'error');
			return false;
		}
	}
1294520
public function getSqlCreateTable($table)
    {
        if (empty($this->sqlCreateTable[$table])) {
            $query = $this->pdo->query("SHOW CREATE TABLE $table");

            $this->sqlCreateTable[$table] = $query->fetchColumn(1);
        }

        return $this->sqlCreateTable[$table];
    }
1195366
public function createMigration()
    {
        $migration = $this->laravel->path . '/database/migrations/' . date('Y_m_d_His') . '_drawbridge_migrations_tables.php';
        $view = $this->laravel->make('view')->make('drawbridge::migration')->render();

        if (! file_exists($migration))
        {
            $fs = fopen($migration, 'x');
            if ($fs)
            {
                fwrite($fs, $view);
                fclose($fs);
                return true;
            }
        }

        return false;
    }
653102
protected function createBaseMigration()
	{
		$name = 'create_password_reminders_table';

		$path = $this->flyphp['path'].'/database/migrations';

		return $this->flyphp['migration.creator']->create($name, $path);
	}
663596
protected function getMigrationStub()
	{
		$stub = file_get_contents(__DIR__.'/../Mmanos/Metable/Stubs/MetasMigration.stub.php');
		
		$stub = str_replace('{{table}}', $this->tableName(), $stub);
		$stub = str_replace(
			'{{class}}',
			'Create' . Str::studly($this->tableName()) . 'Table',
			$stub
		);
		
		return $stub;
	}
1299146
public function construct()
	{
		switch ($this->arguments->getOpt(4))
		{
			case 'for':
				$prefix = App::get('db')->getPrefix();
				$tables = App::get('db')->getTableList();

				if (!$table = $this->arguments->getOpt(5))
				{
					$this->output->error('Please specify the table for which a migration is being created');
				}
				else if (!in_array($table, $tables))
				{
					$this->output->error('Table does not exist');
				}

				$this->addReplacement('description', "creating table {$table}")
					 ->addReplacement('table_name', str_replace($prefix, '#__', $table))
					 ->addReplacement('up', '$^create.table^$')
					 ->addReplacement('down', '$^drop.table^$')
					 ->addReplacement('create_table', $this->showCreateTable($table));
				break;

			default:
				$this->addReplacement('description', '...')
					 ->addReplacement('up', '')
					 ->addReplacement('down', '');
				break;
		}

		// Determine our base path
		$base       = $this->arguments->getOpt('app') ? PATH_APP : PATH_CORE;
		$installDir = trim($this->arguments->getOpt('install-dir'));
		if ($installDir && strlen($installDir) > 0)
		{
			if (substr($installDir, 0, 1) == DS)
			{
				$base = rtrim($installDir, DS);
			}
			else
			{
				$base .= DS . trim($installDir, DS);
			}
		}

		// Install directory is migrations folder within base
		$installDir = $base . DS . 'migrations';

		// Extension
		$extension = null;
		if ($this->arguments->getOpt('e') || $this->arguments->getOpt('extension'))
		{
			$extension = ($this->arguments->getOpt('e')) ? $this->arguments->getOpt('e') : $this->arguments->getOpt('extension');

			if ($extension != 'core' && !$this->isValidExtension($extension, $base) && !$this->arguments->getOpt('i'))
			{
				$this->output->error("Error: the extension provided ({$extension}) does not appear to be valid.");
			}
		}
		else
		{
			$this->output->error("Error: an extension should be provided.");
		}

		// Editor
		$editor = null;
		if ($this->arguments->getOpt('editor'))
		{
			$editor = $this->arguments->getOpt('editor');
		}
		else
		{
			$editor = (getenv('EDITOR')) ? getenv('EDITOR') : 'vi';
		}

		// Create filename varient of extension
		$ext = '';
		if (!preg_match('/core/i', $extension))
		{
			$parts = explode('_', $extension);
			foreach ($parts as $part)
			{
				$ext .= ucfirst($part);
			}
		}
		else
		{
			$ext = 'Core';
		}

		// Craft file/classname
		$classname   = 'Migration' . with(new Date('now'))->format("YmdHis") . $ext;
		$destination = $installDir . DS . $classname . '.php';

		$this->addTemplateFile("{$this->getType()}.tmpl", $destination)
			 ->addReplacement('class_name', $classname)
			 ->make();

		// Open in editor
		system("{$editor} {$destination} > `tty`");
	}
419099
protected function migrationsToRun()
    {
        // Get all migration files
        $path = APPDIR.'/src/'.str_replace('\\', '/', $this->migrationNamespace);

        if (! is_dir($path)) {
            return [];
        }

        $dir = new DirectoryIterator($path);

        $migrations = [];
        foreach ($dir as $file) {
            // Ignore directories and dotfiles (e.g. .DS_Store)
            if (! $file->isFile() or substr($file->getBasename(), 0, 1) === '.') {
                continue;
            }

            $class = $this->migrationNamespace.$file->getBasename('.php');

            $migrations[] = new $class;
        }

        $alreadyExecutedMigrations = $this->alreadyExecutedMigrations();

        $migrationsToRun = [];
        foreach ($migrations as $migration) {
            $compare = new ArrayObject([
                'description' => $migration->getDescription(),
                'timestamp'   => $migration->getTimestamp(),
            ]);

            if (in_array($compare, $alreadyExecutedMigrations)) {
                continue;
            }

            $migrationsToRun[] = $migration;
        }

        return $migrationsToRun;
    }
837786
final public function table($table) {
      $this->connection();
      if (func_num_args()>1)
         $table = func_get_args();
      else if(is_string($table))
         $table = [$table];
      
      $schema = '';
      if ($this->driver=='pgsql' && $this->schema)
         $schema = $this->schema ? $this->schema.'.' : '';

      $tmp_table = [];
      foreach($table as $table) {
         if (preg_match('/\./', $table)) {
            $tmp_table[] = $table;
         }
         else {
            $tmp_table[] = $schema.$table;
         }
      }

      $table = implode(",", $tmp_table);

      if ($this->extended) {
         if ( $this->table ) {
            $this->table = $schema.$this->table.",".$table;
         } else {
            $this->table = $table;
         }
      }
      else {
         $this->table = $table;
      }

      $this->find_first_data = $this->find_save_data = $this->find_delete_data = FALSE;

      $this->get_instance();
      return $this;
   }
458824
protected function getStub($table, $create)
    {
        if (is_null($table)) {
            $stub = config('stubs.path') . '/migration.blank.stub';
        } else {
            $stub = $create
                ? config('stubs.path') . '/migration.create.stub'
                : config('stubs.path') . '/migration.update.stub';
        }

        return file_exists($stub) ? $this->files->get($stub) : parent::getStub($table, $create);
    }
1231953
private function createMigrationTable()
    {
        $adapter = Database::getConnectionAdapter();
        $table = $adapter->getTablePrefix().config('database.migration');
        $generator = new SQLGenerator(
            $table,
            $adapter->getName(),
            'create'
        );

        $generator->addColumn('migration', 'string', ['unique' => true]);
        $generator->addColumn('batch', 'int');
        $generator->addColumn('created_at', 'datetime', [
            'default' => 'CURRENT_TIMESTAMP',
            'nullable' => true
        ]);

        $sql = sprintf(
            'CREATE TABLE IF NOT EXISTS %s (%s);',
            $table,
            $generator->make()
        );

        return Database::statement($sql);
    }