Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Bug: safeDown - addForeignKey #2

Closed
siggi-k opened this issue Jun 17, 2024 · 1 comment · Fixed by SOHELAHMED7/yii2-openapi#29 · May be fixed by #4
Closed

Bug: safeDown - addForeignKey #2

siggi-k opened this issue Jun 17, 2024 · 1 comment · Fixed by SOHELAHMED7/yii2-openapi#29 · May be fixed by #4
Assignees
Labels
bug Something isn't working

Comments

@siggi-k
Copy link

siggi-k commented Jun 17, 2024

GIVEN

# Company:
title: Company
x-table: companies
type: object
description: Database schema of a Company.
x-indexes:
  - 'unique:shortName'
required:
  - id
properties:
  id:
    type: integer
    readOnly: true



title: User
x-table: users
type: object
description: Database schema of a User.

properties:

  id:
    type: integer
    readOnly: true
    example: 1337

  username:
    type: string
    example: 'max'
    description: User name for technical purpose
    minLength: 3
    maxLength: 32

  current_company:
    $ref: '../openapi.yaml#/components/schemas/Company'

EXECUTE

remove from code

  current_company:
    $ref: '../openapi.yaml#/components/schemas/Company'

execute

./yii gii/api

EXPECTED


/**
 * Table for User
 */
class m240605_070000_change_table_users extends \yii\db\Migration
{
    public function safeUp()
    {
        $this->dropForeignKey('fk_users_current_company_id_companies_id', '{{%users}}');
        $this->dropColumn('{{%users}}', 'current_company_id');
    }

    public function safeDown()
    {
        $this->addColumn('{{%users}}', 'current_company_id', $this->integer()->null()->defaultValue(null));
        $this->addForeignKey('fk_users_current_company_id_companies_id', '{{%users}}', 'current_company_id', 'companies', 'id');
    }
}

ACTUAL


/**
 * Table for User
 */
class m240605_070000_change_table_users extends \yii\db\Migration
{
    public function safeUp()
    {
        $this->dropForeignKey('fk_users_current_company_id_companies_id', '{{%users}}');
        $this->dropColumn('{{%users}}', 'current_company_id');
    }

    public function safeDown()
    {
        $this->addColumn('{{%users}}', 'current_company_id', $this->integer()->null()->defaultValue(null));
        $this->addForeignKey('fk_users_current_company_id_companies_id', '{{%users}}', 'id', 'companies', 'current_company_id');
    }
}

BUG

The columns of the tables are swapped in the safeDown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment