Description
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