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

Wrong migration for Pgsql is generated for string/varchar datatype #149

Closed
SOHELAHMED7/yii2-openapi
#26
@SOHELAHMED7

Description

@SOHELAHMED7

Consider a OpenAPI field

name:
    type: string
    example: desc
    maxLength: 150

Now change maxLength as

name:
    type: string
    example: desc
    maxLength: 151

Now run $ ./yii gii/api --ignoreSpecErrors

you will see wrong migrations generated as

<?php

/**
 * Table for CompanyPaymentMethod
 */
class m230530_130000_change_table_table_name extends \yii\db\Migration
{
    public function safeUp()
    {
        $this->alterColumn('{{%table_name}}', 'name', 'string(151) NOT NULL USING "name"::string');
    }

    public function safeDown()
    {
        $this->alterColumn('{{%table_name}}', 'name', 'varchar(150) NOT NULL USING "name"::varchar');
    }
}

By applying this migration, we get below error:

> alter column name in table {{%table_name}} to string(151) NOT NULL USING "name"::string ...Exception: SQLSTATE[42704]: Undefined object: 7 ERROR:  type "string" does not exist at character 91
The SQL being executed was: ALTER TABLE "table_name" ALTER COLUMN "name" TYPE varchar(151) USING "name"::string, ALTER COLUMN "name" DROP DEFAULT, ALTER COLUMN "name" SET NOT NULL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions