Z
Z
Zittz2016-04-23 19:04:39
MySQL
Zittz, 2016-04-23 19:04:39

How to convert sql file to yii2 migration with yii\db\Migration?

Good afternoon.
I am creating migrations in a yii2 project from a sql file downloaded from mysql workbench.
do it by type

public function safeUp()
    {
        $this->execute("
          CREATE TABLE IF NOT EXISTS `table1` (
          `name` VARCHAR(10) NOT NULL COMMENT '',
          `nameFull` VARCHAR(45) NULL COMMENT '',
          PRIMARY KEY (`name`)  COMMENT '')
          ENGINE = InnoDB DEFAULT CHARSET UTF8;
        ");
    }

but now it is customary to use yii\db\Migration, i.e. type
$this->createTable('news', [
            'id' => $this->primaryKey(),
            'title' => $this->string()->notNull(),
            'content' => $this->text(),
        ]);

and similar methods.
Is there a utility or way to convert sql commands to code using yii\db\Migration methods? without using execute.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2016-04-23
@Zittz

What for to transform if on an output there will be a similar request?
yii\db\Migration is used for flexible query building, but if you already have it, and when it is executed, the desired result is produced, then in my opinion there is no point in rewriting

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question