Generate a migration preview from given entity definitions.
@param  array|\Asgard\Entity\Definition $definitions
@param  string                          $migrationName
@return string                          name of migration
5896
public function previewMigration($definitions, $migrationName) {
		if(!is_array($definitions))
			$definitions = [$definitions];
		$entitiesSchema = $this->getEntitiesSchemas($definitions);
		$sqlSchema = $this->getSQLSchemas();
		$up = $this->buildMigration($entitiesSchema, $sqlSchema, false);
		$down = $this->buildMigration($sqlSchema, $entitiesSchema, true);

		if($up == '' && $down == '')
			return;

		return $this->MigrationManager->createCode($up, $down, $migrationName, '\Asgard\Migration\DBMigration');
	}
96525
public function add($migrationName) {
		$list = $this->getList(false);
		if(isset($list[$migrationName]))
			return;
		$list[$migrationName] = ['added'=>time()+microtime(true)];
		$this->writeMigrations($list);
	}
570835
public function generateMigration(): string
    {
        return $this->view->renderFile(Yii::getAlias($this->templateFile), [
            'table' => $this->table,
            'className' => $this->className,
            'namespace' => $this->normalizedNamespace
        ]);
    }
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 );
    }
781740
private function generateNamesDescription()
    {
        foreach ($this->app['config']->get('contenttypes') as $ctname => $ctype) {
            $keyprefix = 'contenttypes.' . $this->slugifyKey($ctname) . '.';

            // Names & description
            $setkeys = [
                'name.plural'   => 'name',
                'name.singular' => 'singular_name',
                'description'   => 'description',
            ];
            foreach ($setkeys as $setkey => $getkey) {
                $key = $keyprefix . $setkey;

                if ($this->isSaved($key)) {
                    $this->translation[$key] = $this->saved[$key];
                } else {
                    if (isset($ctype[$getkey]) && $ctype[$getkey] !== '') {
                        $this->hints[$key] = $ctype[$getkey];
                    } else {
                        $fallback = $this->fallback($key);
                        if ($fallback !== false) {
                            $this->hints[$key] = $fallback;
                        }
                    }
                    $this->translation[$key] = '';
                }
                // Remember names for later usage
                if ($setkey == 'name.plural') {
                    $this->ctnames[$ctname]['%contenttypes%'] = $this->translation[$key];
                } elseif ($setkey == 'name.singular') {
                    $this->ctnames[$ctname]['%contenttype%'] = $this->translation[$key];
                }
            }
        }
    }
1082175
def get_new_filename(self, name):
        """"""
        name = MigrationFile.normalize_name(name)
        migrations = self.get_migration_files()
        migration_id = migrations[-1].id if migrations else 0
        migration_id += 1
        return '{:04}_{}.py'.format(migration_id, name)
1029470
def get_migration(plugin, filename):
    ''''''
    db = get_db()
    return db.migrations.find_one({'plugin': plugin, 'filename': filename})
291545
public static function addColumns($tableName, array $columnDefinitions)
    {
        return [
            'up' => function (Builder $schema) use ($tableName, $columnDefinitions) {
                $schema->table($tableName, function (Blueprint $table) use ($schema, $columnDefinitions) {
                    foreach ($columnDefinitions as $columnName => $options) {
                        $type = array_shift($options);
                        $table->addColumn($type, $columnName, $options);
                    }
                });
            },
            'down' => function (Builder $schema) use ($tableName, $columnDefinitions) {
                $schema->table($tableName, function (Blueprint $table) use ($columnDefinitions) {
                    $table->dropColumn(array_keys($columnDefinitions));
                });
            }
        ];
    }
36482
protected function migrated($className)
    {
        $classInfo = new ReflectionClass($className);
        $fileName  = str_replace('.php', '', basename($classInfo->getFileName()));

        $result = $this->connection->createQueryBuilder()->select('version')
            ->from('schema_migrations')
            ->where('version = ?')
            ->setParameter(0, $fileName)
            ->execute();

        if (!count($result->fetchAll())) {
            return $fileName;
        } else {
            return false;
        }
    }
654121
protected function generateVersionTable($name, Annotation $annotation, EntityDefinition &$entityMetadata)
    {
        $annotation = clone $annotation;
        $annotation->name ='ref_' . $annotation->name;
        $annotation->autoIncrement = false;

        // copy primary key to version table
        $entityMetadata['versionTable']['columns'][] = $this->generateColumn($name, $annotation);
    }
822357
public function actionGenerate()
	{
		$tableName = Enter::display('Enter table name');
		$className = MigrationHelper::generateByTableName($tableName);
		Output::block($className, 'Migration created!');
	}
1106461
function (migrationName, scope, callback) {
    var executeCreateMigration = load('create-migration');
    if (typeof scope === 'function') {
      callback = scope;
    } else if (scope) {
      this.internals.migrationMode = scope;
      this.internals.matching = scope;
    }

    this.internals.argv._.push(migrationName);
    return Promise.fromCallback(
      function (callback) {
        executeCreateMigration(this.internals, this.config, callback);
      }.bind(this)
    ).asCallback(callback);
  }
697603
public function getDefinition($definitionName)
    {
        if (!$this->hasDefinition($definitionName)) {
            throw new DcGeneralInvalidArgumentException(
                'Definition ' . $definitionName . ' is not registered in the configuration ' . $this->getName() . '.'
            );
        }

        return $this->definitions[$definitionName];
    }
1258052
public function generateMigration()
    {
        if (!$this->confirm('Do you want to create a migration?')) {
            return;
        }

        $this->console->call('generate:migration', [
            'name' => "create_{$this->getEntities()}_table",
            '--fields' => $this->console->option('fields'),
            '--force' => $this->console->option('force'),
        ]);
    }
904848
public function setMigrationName($migrationName)
    {
        $this->migrationName = $migrationName;
        $migrationNameAsUnderscoreSrtring = S::underscored($migrationName);
        $items = explode('_', $migrationNameAsUnderscoreSrtring);
        if (count($items) >= 3) {
            $this->action = in_array($items[0], $this->validActions)
                ? $items[0]
                : null;
            $this->actionObject = in_array($items[1], $this->validActionObjects)
                ? $items[1]
                : null;
            $this->model = str_replace($items[0] . '_' . $items[1] . '_', '', $migrationNameAsUnderscoreSrtring);
        }
    }
397987
protected function generateMigrationMessage()
    {
        $tables = Collection::make(Config::get('laratrust.tables'))
            ->reject(function ($value, $key) {
                return $key == 'teams' && !Config::get('laratrust.use_teams');
            })
            ->sort();

        return "A migration that creates {$tables->implode(', ')} "
            . "tables will be created in database/migrations directory";
    }
1062100
protected function showNewMigrations()
    {
        $new = collect($this->migrator->getMigrationsToRun());

        $this->output->writeln("<fg=green>New migrations:\r\n</>");

        foreach ($new as $migration) {
            $this->output->writeln("<fg=green>{$migration}.php</>");
        }
    }