yii2-openapi icon indicating copy to clipboard operation
yii2-openapi copied to clipboard

json field related errors

Open SOHELAHMED7 opened this issue 3 years ago • 0 comments

Lets say I have json fields

... other fields

message1
message2
message3
message4

... other fields

Gii/Api generation and Migrations of these fields are already applied

example:

message1:
          type: object
          x-db-type: JSON
          default: '{}'

Now if I add 3 new fields : message5, message6, message7 after message4 then alter column statement for message{1-4} fields is generated in migrations which should not be generated

public function up()
{
    $this->addColumn('{{%table}}', 'message4', 'json NOT NULL AFTER message4');
    $this->addColumn('{{%table}}', 'message5', 'json NOT NULL');
    $this->addColumn('{{%table}}', 'message6', 'json NOT NULL');

    $this->alterColumn('{{%table}}', 'message2', 'json NOT NULL');
    $this->alterColumn('{{%table}}', 'message3', 'json NOT NULL');
    $this->alterColumn('{{%table}}', 'message1', 'json NOT NULL');
    $this->alterColumn('{{%table}}', 'message4', 'json NOT NULL');
}

public function down()
{
    $this->alterColumn('{{%table}}', 'message4', 'json NOT NULL');
    $this->alterColumn('{{%table}}', 'message1', 'json NOT NULL');
    $this->alterColumn('{{%table}}', 'message3', 'json NOT NULL');
    $this->alterColumn('{{%table}}', 'message2', 'json NOT NULL');

    $this->dropColumn('{{%table}}', 'message6');
    $this->dropColumn('{{%table}}', 'message5');
    $this->dropColumn('{{%table}}', 'message4');
}

SOHELAHMED7 avatar Sep 30 '22 11:09 SOHELAHMED7