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

json field related errors #109

Closed
2 tasks done
SOHELAHMED7 opened this issue Sep 30, 2022 · 2 comments · Fixed by SOHELAHMED7/yii2-openapi#3
Closed
2 tasks done

json field related errors #109

SOHELAHMED7 opened this issue Sep 30, 2022 · 2 comments · Fixed by SOHELAHMED7/yii2-openapi#3

Comments

@SOHELAHMED7
Copy link
Contributor

SOHELAHMED7 commented Sep 30, 2022

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
@SOHELAHMED7
Copy link
Contributor Author

This issue can be closed. Fixed by #112 / SOHELAHMED7#2

@SOHELAHMED7
Copy link
Contributor Author

Reopening as the PR is not yet merged in origin repo

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant