Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
siggi-k opened this issue Jun 24, 2024 · 0 comments · Fixed by #5
Closed

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

siggi-k opened this issue Jun 24, 2024 · 0 comments · Fixed by #5
Assignees

Comments

@siggi-k
Copy link

siggi-k commented Jun 24, 2024

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

@SOHELAHMED7 SOHELAHMED7 self-assigned this Jun 27, 2024
@cebe cebe closed this as completed in #5 Nov 14, 2024
cebe added a commit that referenced this issue Nov 14, 2024
…t-the-same-time-change-it-at-x-indexes

Resolve: Bug: add/remove property and at the same time change it at x-indexes: #3
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants