php-openapi / yii2-openapi

REST API application generator for Yii2, openapi 3.0 YAML -> Yii2
MIT License
5 stars 1 forks source link

Bug: add/remove property and at the same time change it at x-indexes: #3

Open siggi-k opened 3 months ago

siggi-k commented 3 months ago

GIVEN

title: Company
x-table: companies
type: object
description: Database schema of a Company.
x-indexes:
  - 'unique:shortName,postalCode'

properties:

  id:
    type: integer
    readOnly: true

  name:
    type: string
    maxLength: 64

  shortName:
    type: string

  postalCode:
    type: string

EXECUTE

rename "postalCode" to "postCode"

new schema

title: Company
x-table: companies
type: object
description: Database schema of a Company.
x-indexes:
  - 'unique:shortName,postCode'

properties:

  id:
    type: integer
    readOnly: true

  name:
    type: string
    maxLength: 64

  shortName:
    type: string

  postCode:
    type: string

execute

./yii gii/api

ACTUAL

class m240624_100002_change_table_companies extends \yii\db\Migration
{
    public function safeUp()
    {
        $this->addColumn('{{%companies}}', 'postCode', $this->text()->null()->defaultValue(null));
        $this->dropColumn('{{%companies}}', 'postalCode');
        $this->dropIndex('companies_shortName_postalCode_key', '{{%companies}}');
        $this->createIndex('companies_shortName_postCode_key', '{{%companies}}', ["shortName", "postCode"], true);
    }

    public function safeDown()
    {
        $this->dropIndex('companies_shortName_postCode_key', '{{%companies}}');
        $this->createIndex('companies_shortName_postalCode_key', '{{%companies}}', ["shortName", "postalCode"], true);
        $this->addColumn('{{%companies}}', 'postalCode', $this->text()->null()->defaultValue(null));
        $this->dropColumn('{{%companies}}', 'postCode');
    }
}

EXPECTED


class m240624_100002_change_table_companies extends \yii\db\Migration
{
    public function safeUp()
    {
        $this->dropIndex('companies_shortName_postalCode_key', '{{%companies}}');
        $this->addColumn('{{%companies}}', 'postCode', $this->text()->null()->defaultValue(null));
        $this->dropColumn('{{%companies}}', 'postalCode');
        $this->createIndex('companies_shortName_postCode_key', '{{%companies}}', ["shortName", "postCode"], true);
    }

    public function safeDown()
    {
        $this->dropIndex('companies_shortName_postCode_key', '{{%companies}}');
        $this->addColumn('{{%companies}}', 'postalCode', $this->text()->null()->defaultValue(null));
        $this->dropColumn('{{%companies}}', 'postCode');
        $this->createIndex('companies_shortName_postalCode_key', '{{%companies}}', ["shortName", "postalCode"], true);
    }
}

BUG

safeUp: first dropIndex , and only then dropColumn safeDown: first addColumn , and only then createIndex