Write the migration file to disk.

@param  string  $driver
@param  string  $name
@param  string  $table
@param  bool    $create

@return string
439683
protected function writeMigration($driver, $name, $table, $create)
    {
        $migrator = $this->tenant->driver($driver);
        $files = $this->creator->getFilesystem();
        $path = $migrator->getMigrationPaths();

        if (! $files->isDirectory($path)) {
            $files->makeDirectory($path, 0755, true);
        }

        if ($this->tenant->getConfig("{$driver}.shared", true) === true) {
            $table = Str::replace($migrator->getTablePrefix()."_{$table}", ['id' => '{$id}']);
        }

        $name = \implode('_', [$driver, 'tenant', $name]);

        $file = \pathinfo($this->creator->create($name, $path, $table, $create), PATHINFO_FILENAME);

        $this->line("<info>Created Migration:</info> $file");
    }
785083
public function getMigrationTemplate( $name )
    {
        $template = '<?php' . PHP_EOL . PHP_EOL;
        
        if ( '' !== $this->migrationNamespace )
        {
            $template .= 'namespace ' . $this->migrationNamespace . ';' . PHP_EOL . PHP_EOL;
        }
        
        $template .= 'use RawPHP\RawMigrator\Migration;' . PHP_EOL;
        $template .= 'use RawPHP\RawDatabase\IDatabase;' . PHP_EOL . PHP_EOL;
        
        $template .= 'class ' . $name . ' extends Migration' . PHP_EOL;
        $template .= '{' . PHP_EOL;
        
        $template .= '    /**' . PHP_EOL;
        $template .= '     * Implement database changes here.' . PHP_EOL;
        $template .= '     * ' . PHP_EOL;
        $template .= '     * @param IDatabase $db database instance' . PHP_EOL;
        $template .= '     */' . PHP_EOL;
        $template .= '    public function migrateUp( IDatabase $db )' . PHP_EOL;
        $template .= '    {' . PHP_EOL;
        $template .= '        ' . PHP_EOL;
        $template .= '    }' . PHP_EOL . PHP_EOL;
        
        $template .= '    /**' . PHP_EOL;
        $template .= '     * Implement reverting changes here.' . PHP_EOL;
        $template .= '     * ' . PHP_EOL;
        $template .= '     * @param IDatabase $db database instance' . PHP_EOL;
        $template .= '     */' . PHP_EOL;
        $template .= '    public function migrateDown( IDatabase $db )' . PHP_EOL;
        $template .= '    {' . PHP_EOL;
        $template .= '        ' . PHP_EOL;
        $template .= '    }' . PHP_EOL . PHP_EOL;
        
        $template .= '    /**' . PHP_EOL;
        $template .= '     * Alternatively to <code>migrateUp()</code>, this method will' . PHP_EOL;
        $template .= '     * use transactions (if available) to process the database changes.' .
                          PHP_EOL;
        $template .= '     * ' . PHP_EOL;
        $template .= '     * @param IDatabase $db database instance' . PHP_EOL;
        $template .= '     */' . PHP_EOL;
        $template .= '    public function safeMigrateUp( IDatabase $db )' . PHP_EOL;
        $template .= '    {' . PHP_EOL;
        $template .= '        ' . PHP_EOL;
        $template .= '    }' . PHP_EOL . PHP_EOL;
        
        $template .= '    /**' . PHP_EOL;
        $template .= '     * Alternatively to <code>migrateDown()</code>, this method will' . 
                          PHP_EOL;
        $template .= '     * use transactions (if available) to revert changes.' . PHP_EOL;
        $template .= '     * ' . PHP_EOL;
        $template .= '     * @param IDatabase $db database instance' . PHP_EOL;
        $template .= '     */' . PHP_EOL;
        $template .= '    public function safeMigrateDown( IDatabase $db )' . PHP_EOL;
        $template .= '    {' . PHP_EOL;
        $template .= '        ' . PHP_EOL;
        $template .= '    }' . PHP_EOL;
        $template .= '}';
        
        return $this->filter( self::ON_GET_MIGRATION_TEMPLATE_FILTER, $template, $name );
    }
1346434
public function writeContent($name, $source, $dependencies = array())
    {
        $source = $source;

        return $this->write($name, 'script', $source, $dependencies);
    }
997929
public function createDb($name)
    {
        $sql = $this->query->createDb($name);
        $this->db->exec($sql);

        return true;
    }
742663
function create(name) {
		var path = 'migrations/' + name + '.js';
		log('create', join(process.cwd(), path));
		fs.writeFileSync(path, template);
	}
387284
public function getData(string $table, $name = ""){
            
            $file = $this->base . '/' . $table . '.json';
            if(file_exists($file)){
                return json_decode(file_get_contents($file), true);
            }else{
                throw new \NonDB\Exceptions\DriverException('Table Not Exists.', 1002);
            }

        }
1066401
public function addDriver(string $name, DriverInterface $driver): DatabaseManager
    {
        if (isset($this->drivers[$name])) {
            throw new DBALException("Connection '{$name}' already exists");
        }

        $this->drivers[$name] = $driver;

        return $this;
    }
463336
protected function _copy($source, $targetDir, $name) {
		$this->clearcache();
		$id = $this->_joinPath($targetDir, $name);

		$sql = $id > 0
			? sprintf('REPLACE INTO %s (id, parent_id, name, content, size, mtime, mime, width, height, `read`, `write`, `locked`, `hidden`) (SELECT %d, %d, name, content, size, mtime, mime, width, height, `read`, `write`, `locked`, `hidden` FROM %s WHERE id=%d)', $this->tbf, $id, $this->_dirname($id), $this->tbf, $source)
			: sprintf('INSERT INTO %s (parent_id, name, content, size, mtime, mime, width, height, `read`, `write`, `locked`, `hidden`) SELECT %d, "%s", content, size, %d, mime, width, height, `read`, `write`, `locked`, `hidden` FROM %s WHERE id=%d', $this->tbf, $targetDir, $this->db->real_escape_string($name), time(), $this->tbf, $source);

		return $this->query($sql);
	}
260899
public function destroySourceTableMigration($name, array $fields)
    {
        $path = $this->getMigrationPath($name);

        $this->delete($path);

        foreach ($fields as $field)
        {
            $this->destroyFieldMigrationForTable($field, $name);
        }
    }
308595
public function makeMigration($name)
  {
    $m = $this->getManager();
    $t = $m->getPrefix() . $this->getTable();

    $class = StaticStringy::upperCamelize($name);

    $head = "<?php\n\n"
      . "use Phinx\\Migration\\AbstractMigration;\n\n"
      . "class $class extends AbstractMigration\n"
      . "{\n";

    $pk       = $this->getPrimaryKey();
    $tbl_opts = 'array(\'id\' => ' . ($pk ? "'$pk'" : 'false') . ')';

    $tbl  = '    $tbl = $this->table(\'' . $t . '\', ' . $tbl_opts . ');' . "\n";
    $save = '    $tbl->save();' . "\n";
    $up   = $down = false;

    $drop = $upd = false;

    $tbl_exists = $this->checkTableExists();
    if ($tbl_exists) {
      $columns = $this->getActualColumns(true);

      $drop = array_diff($columns, array_keys($this->columns));
      $add  = array_diff(array_keys($this->columns), $columns);
    } else {
      $down = '    $tbl->drop();' . "\n";
      $add  = array_keys($this->columns);
    }

    if (!empty($add)) {
      foreach ($add as $col) {
        $up .= $this->makeAddExpr($col);
        if ($tbl_exists) {
          $down .= $this->makeDropExpr($col);
        }
      }
    }

    if (!empty($drop)) {
      foreach ($drop as $col) {
        if ($col != $this->getPrimaryKey()) {
          $up .= $this->makeDropExpr($col);
          $down .= "    // TODO: добавить инструкции для создания столбца $col\n";
        }
      }
    }

    foreach ($this->columns as $col => $arr) {
      if (empty($add) || !in_array($col, $add)) {
        $up .= $this->makeAddExpr($col, true);
      }
    }

    if (!empty($this->indexes)) {
      foreach ($this->indexes as $a) {
        $up .= $this->makeAddIndex($a, $tbl_exists);
      }
    }

    if (!empty($this->foreign_keys)) {
      foreach ($this->foreign_keys as $arr) {
        $up .= $this->makeFK($arr, $tbl_exists);
      }
    }

    return $head
    . "  public function up()\n"
    . "  {\n" . $tbl . $up . $save
    . "  }\n\n"
    . "  public function down()\n"
    . "  {\n" . $tbl . $down . ($tbl_exists ? $save : '')
    . "  }\n"
    . "}\n";
  }
1323401
public function newMigration($name)
    {
        $time = time();
        $date = date("n/j/Y");

        $fileName = "{$time}_migration.php";
        if ($name) $fileName = "{$time}_{$name}.php";

        $file = $this->storagePath . "/" . $fileName;
        $class = 'Migration_' . ((int)$time);
        $contents = array('<?php');
        $contents[] = '/*';
        $contents[] = " * {$name} migration file";
        $contents[] = ' *';
        $contents[] = ' * @author ';
        $contents[] = ' * @version 1.0';
        $contents[] = " * @date $date";
        $contents[] = ' */';
        $contents[] = 'class ' . $class . ' extends \Core\Migration';
        $contents[] = '{';
        $contents[] = '';
        $contents[] = "    public function up()";
        $contents[] = "    {";
        $contents[] = "";
        $contents[] = "    }";
        $contents[] = "";
        $contents[] = "    public function down()";
        $contents[] = "    {";
        $contents[] = "";
        $contents[] = "    }";
        $contents[] = '}';

        if (file_put_contents($file, implode("\n", $contents))) {
            echo 'Create ' . $file . "\n\r";
            return $file;
        }
        return false;
    }
105300
protected function writeMigrate($author,$module,$name, $table, $create)
    {
        $path =  $this->laravel['path'].'/Modules/'.$author.'/'.$module.'/db/migrate';

        $file = pathinfo($this->creator->create($name, $path, $table, $create), PATHINFO_FILENAME);

        $this->line("<info>Created Migration:</info> $file");
    }
1230244
public function getTableFieldMigrationName($name, $tableName)
    {
        return sprintf(
            MigrationBuilder::PATTERN_FIELD,
            ucfirst($name),
            ucfirst($tableName)
        );
    }
629215
private function create($name, $timeout = null)
    {
        if(null === $timeout) {
            $timeout = 10000;
        }

        $sql = 'INSERT INTO ' . $this->queueTable . '
            (queue_name, timeout)
            VALUES
            (:queue_name, :timeout)
            ';
        $stmt = $this->getDb()->prepare($sql);
        $stmt->bindParam(':queue_name', $name, \PDO::PARAM_STR);
        $stmt->bindParam(':timeout', $timeout, \PDO::PARAM_INT);
        $stmt->execute();
        return true;
    }
83680
private function writeMigration($name, $eventObjectTable, $actionTiming, $event)
    {
        $file = pathinfo($this->creator->write(
            $name,
            $eventObjectTable,
            $actionTiming,
            $event,
            $this->getMigrationPath()
        ), PATHINFO_FILENAME);

        $this->line("<info>Created Migration:</info> {$file}");
    }
147549
public function migrate(Name $name, Direction $direction, OutputInterface $output)
    {
        $migration = $this->createMigrationInstance($name, $output);

        $output->writeln('<info>Migrating ' . $direction . '...</info> <comment>' . $name . '</comment>');

        if ($direction->isUp()) {
            $migration->up($this->getDatabase());
            $this->setMigrationApplied($name, true);
        } else {
            $migration->down($this->getDatabase());
            $this->setMigrationApplied($name, false);
        }

        $output->writeln('<info>Migrated ' . $direction . '</info>');
    }
731571
public function create($name, $path, $migrations)
    {
        $path = $this->getPath($name, $path);

        $ups = [];

        $downs = [];

        if(isset($migrations['create'])){

            foreach($migrations['create'] as $table => $data){

                $ups[] = $this->populateStub('create', [
                    'table' => $table,
                    'columns' => $this->format($data['cols'])
                ]);

                $downs[] = $this->populateStub('drop', ['table' => $table]);
            }
        }

        if(isset($migrations['update'])){

            foreach($migrations['update'] as $table => $data){

                $ups[] = $this->populateStub('update', [
                    'table' => $table,
                    'columns' => isset($data['cols']) ? $this->format($data['cols']) : null,
                    'foreign_keys' => isset($data['fks']) ? $this->format($data['fks']) : null
                ]);

                $downs[] = $this->populateStub('down', [
                    'table' => $table,
                    'columns' => isset($data['cols']) ? $this->format($this->drop(array_keys($data['cols']), 'Column')) : null,
                    'foreign_keys' => isset($data['fks']) ? $this->format($this->drop(array_keys($data['fks']), 'Foreign')) : null
                ]);
            }
        }

        $ups = array_filter($ups, 'strlen');
        $downs = array_filter($downs, 'strlen');

        if($ups){

            $this->files->put($path, $this->populateStub('blank', [
                'class' => studly_case($name),
                'up' => $this->format($ups, ''),
                'down' => $this->format(array_reverse($downs), '')
            ]));

            return $path;
        }

        return false;
    }