Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

json field related errors #109

Closed
SOHELAHMED7/yii2-openapi
#3
@SOHELAHMED7

Description

@SOHELAHMED7

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');
}

TODO:

  • check for default values in json e.g. '{}' and [ ]
  • add tests for x-db-type (for json): fresh, secondary with new col; secondary with edit col

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions