A have a file containing SQL migration commands. For example
// 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);
I want to add another command before the line containing the "createTable() command, so that my example file will look as follows :-
// 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);
I am seeing lots of examples to delete lines matching a pattern, but none so far that can get me the above changes.
The closest I came is
awk '/createTable/{print "$this->DropTable();"}1' file
but I cannot fill in the contents inside the brackets.