Skip to content

createMigration bug: if columns depending on other columns #108

@siggi-k

Description

@siggi-k

Use case:
I added a column name_index which stores a tsvector generated from another column name (similar to issue #107).

LeadBankAccount.yaml


# LeadBankAccount:
title: LeadBankAccount
x-table: lead_bank_accounts
type: object

x-indexes:
  - gin:accountOwner_index

required:
  - id
  - accountOwner
  - accountOwner_index

properties:

  id:
    type: integer
    example: 12531
    readOnly: true

  accountOwner:
    type: string
    example: 'Lukas Sarfert'
    maxLength: 128

  accountOwner_index:
    type: string
    x-db-type: |
      tsvector GENERATED ALWAYS AS (
          to_tsvector('simple', coalesce(accountOwner, ''))
      ) STORED
    readOnly: true
    x-faker: false

m251023_130000_change_table_lead_bank_accounts.php

/**
 * Table for LeadBankAccount
 */
class m251023_130000_change_table_lead_bank_accounts extends \yii\db\Migration
{
    public function safeUp()
    {
        $this->db->createCommand('ALTER TABLE {{%lead_bank_accounts}} ADD COLUMN "accountOwner_index" tsvector generated always as (
    to_tsvector(\'simple\', coalesce(accountowner, \'\'))
) stored
 NOT NULL')->execute();
        $this->createIndex('lead_bank_accounts_accountOwner_index_gin_index', '{{%lead_bank_accounts}}', 'accountOwner_index', 'gin');
    }

    public function safeDown()
    {
        $this->dropIndex('lead_bank_accounts_accountOwner_index_gin_index', '{{%lead_bank_accounts}}');
        $this->dropColumn('{{%lead_bank_accounts}}', 'accountOwner_index');
    }
}

Problem with case sensitivity in column names coalesce(accountowner, \'\')) instead of coalesce(accountOwner, \'\')).

I have tried different variants in YAML such as:

  accountOwner_index:
    type: string
    x-db-type: |
      tsvector GENERATED ALWAYS AS (
          to_tsvector('simple', coalesce(accountOwner, ''))
      ) STORED
    readOnly: true
    x-faker: false
  accountOwner_index:
    type: string
    x-db-type: |
      tsvector GENERATED ALWAYS AS (
          to_tsvector('simple', coalesce("accountOwner", ''))
      ) STORED
    readOnly: true
    x-faker: false
  accountOwner_index:
    type: string
    x-db-type: |
      tsvector GENERATED ALWAYS AS (
          to_tsvector('simple', coalesce(\"accountOwner\", ''))
      ) STORED
    readOnly: true
    x-faker: false

Unfortunately, none of these attempts were successful.

How can I define a column name here so that the generated migration also contains an uppercase letter?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions