src/Driver/Postgres/Schema/PostgresColumn.php
public function alterOperations(DriverInterface $driver, AbstractColumn $initial): array
    {
        $operations = [];

        //To simplify comparation
        $currentType = [$this->type, $this->size, $this->precision, $this->scale];
        $initialType = [$initial->type, $initial->size, $initial->precision, $initial->scale];

        $identifier = $driver->identifier($this->getName());

        /*
         * This block defines column type and all variations.
         */
        if ($currentType != $initialType) {
            if ($this->getAbstractType() == 'enum') {
                //Getting longest value
                $enumSize = $this->size;
                foreach ($this->enumValues as $value) {
                    $enumSize = max($enumSize, strlen($value));
                }

                $type = "ALTER COLUMN {$identifier} TYPE character varying($enumSize)";
                $operations[] = $type;
            } else {
                $type = "ALTER COLUMN {$identifier} TYPE {$this->type}";

                if (!empty($this->size)) {
                    $type .= "($this->size)";
                } elseif (!empty($this->precision)) {
                    $type .= "($this->precision, $this->scale)";
                }

                //Required to perform cross conversion
                $operations[] = "{$type} USING {$identifier}::{$this->type}";
            }
        }

        //Dropping enum constrain before any operation
        if ($initial->getAbstractType() == 'enum' && $this->constrained) {
            $operations[] = 'DROP CONSTRAINT ' . $driver->identifier($this->enumConstraint());
        }

        //Default value set and dropping
        if ($initial->defaultValue != $this->defaultValue) {
            if (is_null($this->defaultValue)) {
                $operations[] = "ALTER COLUMN {$identifier} DROP DEFAULT";
            } else {
                $operations[] = "ALTER COLUMN {$identifier} SET DEFAULT {$this->quoteDefault($driver)}";
            }
        }

        //Nullable option
        if ($initial->nullable != $this->nullable) {
            $operations[] = "ALTER COLUMN {$identifier} " . (!$this->nullable ? 'SET' : 'DROP') . ' NOT NULL';
        }

        if ($this->getAbstractType() == 'enum') {
            $enumValues = [];
            foreach ($this->enumValues as $value) {
                $enumValues[] = $driver->quote($value);
            }

            $operations[] = "ADD CONSTRAINT {$driver->identifier($this->enumConstraint())} "
                . "CHECK ({$identifier} IN (" . implode(', ', $enumValues) . '))';
        }

        return $operations;
    }
public function alterOperations(DriverInterface $driver, AbstractColumn $initial): array
    {
        $operations = [];

        //To simplify comparation
        $currentType = [$this->type, $this->size, $this->precision, $this->scale];
        $initialType = [$initial->type, $initial->size, $initial->precision, $initial->scale];

        $identifier = $driver->identifier($this->getName());

        /*
         * This block defines column type and all variations.
         */
        if ($currentType != $initialType) {
            if ($this->getAbstractType() == 'enum') {
                //Getting longest value
                $enumSize = $this->size;
                foreach ($this->enumValues as $value) {
                    $enumSize = max($enumSize, strlen($value));
                }

                $type = "ALTER COLUMN {$identifier} TYPE character varying($enumSize)";
                $operations[] = $type;
            } else {
                $type = "ALTER COLUMN {$identifier} TYPE {$this->type}";

                if (!empty($this->size)) {
                    $type .= "($this->size)";
                } elseif (!empty($this->precision)) {
                    $type .= "($this->precision, $this->scale)";
                }

                //Required to perform cross conversion
                $operations[] = "{$type} USING {$identifier}::{$this->type}";
            }
        }

        //Dropping enum constrain before any operation
        if ($initial->getAbstractType() == 'enum' && $this->constrained) {
            $operations[] = 'DROP CONSTRAINT ' . $driver->identifier($this->enumConstraint());
        }

        //Default value set and dropping
        if ($initial->defaultValue != $this->defaultValue) {
            if (is_null($this->defaultValue)) {
                $operations[] = "ALTER COLUMN {$identifier} DROP DEFAULT";
            } else {
                $operations[] = "ALTER COLUMN {$identifier} SET DEFAULT {$this->quoteDefault($driver)}";
            }
        }

        //Nullable option
        if ($initial->nullable != $this->nullable) {
            $operations[] = "ALTER COLUMN {$identifier} " . (!$this->nullable ? 'SET' : 'DROP') . ' NOT NULL';
        }

        if ($this->getAbstractType() == 'enum') {
            $enumValues = [];
            foreach ($this->enumValues as $value) {
                $enumValues[] = $driver->quote($value);
            }

            $operations[] = "ADD CONSTRAINT {$driver->identifier($this->enumConstraint())} "
                . "CHECK ({$identifier} IN (" . implode(', ', $enumValues) . '))';
        }

        return $operations;
    }
public function alterOperations ( DriverInterface $ driver , AbstractColumn $ initial ) : array { $ operations = [ ] ; //To simplify comparation $ currentType = [ $ this -> type , $ this -> size , $ this -> precision , $ this -> scale ] ; $ initialType = [ $ initial -> type , $ initial -> size , $ initial -> precision , $ initial -> scale ] ; $ identifier = $ driver -> identifier ( $ this -> getName ( ) ) ; /*
         * This block defines column type and all variations.
         */ if ( $ currentType != $ initialType ) { if ( $ this -> getAbstractType ( ) == 'enum' ) { //Getting longest value $ enumSize = $ this -> size ; foreach ( $ this -> enumValues as $ value ) { $ enumSize = max ( $ enumSize , strlen ( $ value ) ) ; } $ type = "ALTER COLUMN {$identifier} TYPE character varying($enumSize)" ; $ operations [ ] = $ type ; } else { $ type = "ALTER COLUMN {$identifier} TYPE {$this->type}" ; if ( ! empty ( $ this -> size ) ) { $ type .= "($this->size)" ; } elseif ( ! empty ( $ this -> precision ) ) { $ type .= "($this->precision, $this->scale)" ; } //Required to perform cross conversion $ operations [ ] = "{$type} USING {$identifier}::{$this->type}" ; } } //Dropping enum constrain before any operation if ( $ initial -> getAbstractType ( ) == 'enum' && $ this -> constrained ) { $ operations [ ] = 'DROP CONSTRAINT ' . $ driver -> identifier ( $ this -> enumConstraint ( ) ) ; } //Default value set and dropping if ( $ initial -> defaultValue != $ this -> defaultValue ) { if ( is_null ( $ this -> defaultValue ) ) { $ operations [ ] = "ALTER COLUMN {$identifier} DROP DEFAULT" ; } else { $ operations [ ] = "ALTER COLUMN {$identifier} SET DEFAULT {$this->quoteDefault($driver)}" ; } } //Nullable option if ( $ initial -> nullable != $ this -> nullable ) { $ operations [ ] = "ALTER COLUMN {$identifier} " . ( ! $ this -> nullable ? 'SET' : 'DROP' ) . ' NOT NULL' ; } if ( $ this -> getAbstractType ( ) == 'enum' ) { $ enumValues = [ ] ; foreach ( $ this -> enumValues as $ value ) { $ enumValues [ ] = $ driver -> quote ( $ value ) ; } $ operations [ ] = "ADD CONSTRAINT {$driver->identifier($this->enumConstraint())} " . "CHECK ({$identifier} IN (" . implode ( ', ' , $ enumValues ) . '))' ; } return $ operations ; }
Generate set of operations need to change column.

@param DriverInterface $driver
@param AbstractColumn  $initial
@return array
Generate set of operations need to change column .