A 有一个包含 SQL 迁移命令的文件。例如
// admin_setting
$this->createTable('{{%admin_setting}}', [
'setting_id' => Schema::TYPE_INTEGER . "(11) NOT NULL AUTO_INCREMENT",
'short_description' => Schema::TYPE_STRING . "(255) NOT NULL",
'value' => Schema::TYPE_TEXT . " NULL",
'PRIMARY KEY (setting_id)',
], $this->tableOptions);
// authorization
$this->createTable('{{%authorization}}', [
'authorization_id' => Schema::TYPE_INTEGER . "(11) NOT NULL AUTO_INCREMENT",
'short_description' => Schema::TYPE_STRING . "(255) NULL",
'PRIMARY KEY (authorization_id)',
], $this->tableOptions);
我想在包含“createTable() 命令的行之前添加另一个命令,以便我的示例文件如下所示:-
// admin_setting
$this->dropTable('{{%admin_setting}}');
$this->createTable('{{%admin_setting}}', [
'setting_id' => Schema::TYPE_INTEGER . "(11) NOT NULL AUTO_INCREMENT",
'short_description' => Schema::TYPE_STRING . "(255) NOT NULL",
'value' => Schema::TYPE_TEXT . " NULL",
'PRIMARY KEY (setting_id)',
], $this->tableOptions);
// authorization
$this->dropTable('{{%authorization}}');
$this->createTable('{{%authorization}}', [
'authorization_id' => Schema::TYPE_INTEGER . "(11) NOT NULL AUTO_INCREMENT",
'short_description' => Schema::TYPE_STRING . "(255) NULL",
'PRIMARY KEY (authorization_id)',
], $this->tableOptions);
我看到了很多删除与模式匹配的行的示例,但到目前为止还没有一个可以让我进行上述更改。
我来的最近的是
awk '/createTable/{print "$this->DropTable();"}1' file
但我无法填写括号内的内容。