public function actionCreate(string $table): int
    {
        $tables = [$table];
        if (strpos($table, ',') !== false) {
            $tables = explode(',', $table);
        }

        $migrationsGenerated = 0;
        foreach ($tables as $name) {
            $this->stdout(" > Generating create migration for table '{$name}' ...", Console::FG_YELLOW);

            $className = 'm' . gmdate('ymd_His') . '_create_table_' . $name;
            $file = Yii::getAlias($this->workingPath . DIRECTORY_SEPARATOR . $className . '.php');

            $generator = new Generator([
                'db' => $this->db,
                'view' => $this->view,
                'useTablePrefix' => $this->useTablePrefix,
                'templateFile' => $this->templateFile,
                'tableName' => $name,
                'className' => $className,
                'namespace' => $this->migrationNamespace,
                'generalSchema' => $this->generalSchema,
                'tableOptionsInit' => $this->tableOptionsInit,
                'tableOptions' => $this->tableOptions,
            ]);

            if ($generator->tableSchema === null) {
                $this->stdout("ERROR!\n > Table '{$name}' does not exist!\n\n", Console::FG_RED);

                return ExitCode::DATAERR;
            }

            if ($this->generateFile($file, $generator->generateMigration()) === false) {
                $this->stdout("ERROR!\n > Migration file for table '{$name}' can not be generated!\n\n", Console::FG_RED);

                return ExitCode::SOFTWARE;
            }

            $migrationsGenerated++;

            $this->stdout("DONE!\n", Console::FG_GREEN);
            $this->stdout(" > Saved as '{$file}'\n");

            if ($this->fixHistory) {
                if ($this->db->schema->getTableSchema($this->migrationTable, true) === null) {
                    $this->createMigrationHistoryTable();
                }

                $this->addMigrationHistory($className, $this->migrationNamespace);
            }

            $this->stdout("\n");
        }

        if ($migrationsGenerated) {
            $this->stdout(" Generated $migrationsGenerated file(s).\n", Console::FG_YELLOW);
            $this->stdout(" (!) Remember to verify files before applying migration.\n\n", Console::FG_YELLOW);
        } else {
            $this->stdout(" No files generated.\n\n", Console::FG_YELLOW);
        }

        return ExitCode::OK;
    }
public function actionCreate(string $table): int
    {
        $tables = [$table];
        if (strpos($table, ',') !== false) {
            $tables = explode(',', $table);
        }

        $migrationsGenerated = 0;
        foreach ($tables as $name) {
            $this->stdout(" > Generating create migration for table '{$name}' ...", Console::FG_YELLOW);

            $className = 'm' . gmdate('ymd_His') . '_create_table_' . $name;
            $file = Yii::getAlias($this->workingPath . DIRECTORY_SEPARATOR . $className . '.php');

            $generator = new Generator([
                'db' => $this->db,
                'view' => $this->view,
                'useTablePrefix' => $this->useTablePrefix,
                'templateFile' => $this->templateFile,
                'tableName' => $name,
                'className' => $className,
                'namespace' => $this->migrationNamespace,
                'generalSchema' => $this->generalSchema,
                'tableOptionsInit' => $this->tableOptionsInit,
                'tableOptions' => $this->tableOptions,
            ]);

            if ($generator->tableSchema === null) {
                $this->stdout("ERROR!\n > Table '{$name}' does not exist!\n\n", Console::FG_RED);

                return ExitCode::DATAERR;
            }

            if ($this->generateFile($file, $generator->generateMigration()) === false) {
                $this->stdout("ERROR!\n > Migration file for table '{$name}' can not be generated!\n\n", Console::FG_RED);

                return ExitCode::SOFTWARE;
            }

            $migrationsGenerated++;

            $this->stdout("DONE!\n", Console::FG_GREEN);
            $this->stdout(" > Saved as '{$file}'\n");

            if ($this->fixHistory) {
                if ($this->db->schema->getTableSchema($this->migrationTable, true) === null) {
                    $this->createMigrationHistoryTable();
                }

                $this->addMigrationHistory($className, $this->migrationNamespace);
            }

            $this->stdout("\n");
        }

        if ($migrationsGenerated) {
            $this->stdout(" Generated $migrationsGenerated file(s).\n", Console::FG_YELLOW);
            $this->stdout(" (!) Remember to verify files before applying migration.\n\n", Console::FG_YELLOW);
        } else {
            $this->stdout(" No files generated.\n\n", Console::FG_YELLOW);
        }

        return ExitCode::OK;
    }
public function actionCreate ( string $ table ) : int { $ tables = [ $ table ] ; if ( strpos ( $ table , ',' ) !== false ) { $ tables = explode ( ',' , $ table ) ; } $ migrationsGenerated = 0 ; foreach ( $ tables as $ name ) { $ this -> stdout ( " > Generating create migration for table '{$name}' ..." , Console :: FG_YELLOW ) ; $ className = 'm' . gmdate ( 'ymd_His' ) . '_create_table_' . $ name ; $ file = Yii :: getAlias ( $ this -> workingPath . DIRECTORY_SEPARATOR . $ className . '.php' ) ; $ generator = new Generator ( [ 'db' => $ this -> db , 'view' => $ this -> view , 'useTablePrefix' => $ this -> useTablePrefix , 'templateFile' => $ this -> templateFile , 'tableName' => $ name , 'className' => $ className , 'namespace' => $ this -> migrationNamespace , 'generalSchema' => $ this -> generalSchema , 'tableOptionsInit' => $ this -> tableOptionsInit , 'tableOptions' => $ this -> tableOptions , ] ) ; if ( $ generator -> tableSchema === null ) { $ this -> stdout ( "ERROR!\n > Table '{$name}' does not exist!\n\n" , Console :: FG_RED ) ; return ExitCode :: DATAERR ; } if ( $ this -> generateFile ( $ file , $ generator -> generateMigration ( ) ) === false ) { $ this -> stdout ( "ERROR!\n > Migration file for table '{$name}' can not be generated!\n\n" , Console :: FG_RED ) ; return ExitCode :: SOFTWARE ; } $ migrationsGenerated ++ ; $ this -> stdout ( "DONE!\n" , Console :: FG_GREEN ) ; $ this -> stdout ( " > Saved as '{$file}'\n" ) ; if ( $ this -> fixHistory ) { if ( $ this -> db -> schema -> getTableSchema ( $ this -> migrationTable , true ) === null ) { $ this -> createMigrationHistoryTable ( ) ; } $ this -> addMigrationHistory ( $ className , $ this -> migrationNamespace ) ; } $ this -> stdout ( "\n" ) ; } if ( $ migrationsGenerated ) { $ this -> stdout ( " Generated $migrationsGenerated file(s).\n" , Console :: FG_YELLOW ) ; $ this -> stdout ( " (!) Remember to verify files before applying migration.\n\n" , Console :: FG_YELLOW ) ; } else { $ this -> stdout ( " No files generated.\n\n" , Console :: FG_YELLOW ) ; } return ExitCode :: OK ; }
Creates new migration for the given tables.
@param string $table Table names separated by commas.
@return int
@throws DbException
Creates new migration for the given tables .