0

I have created a patch in the "Vendor/Module/Setup/Patch/Schema" path We have to use two things :

  • 1st is to update the existing table schema from apply function

  • And 2nd schema once the module is uninstalled.

We observer that on the installation(setup:upgrade) everything is going good

But it not working correctly at the time of Uninstall(module:uninstall Prince_PatchExample) the module

    ?php
namespace Prince\PatchExample\Setup\Patch\Schema;

use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class MyNewPatchFile implements SchemaPatchInterface, PatchRevertableInterface
{
    protected $moduleDataSetup;

    public function __construct(ModuleDataSetupInterface $moduleDataSetup)
    {
        $this->moduleDataSetup = $moduleDataSetup;
    }

    public function apply()
    {
        $connection = $this->moduleDataSetup->getConnection();
        $tableName = $this->moduleDataSetup->getTable('my_custom_table');

        $connection->addColumn(
            $tableName,
            'my_status',
            [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => 255,
                'nullable' => false,
                'comment' => 'New Column'
            ]
        );
    }

    public function revert()
    {
        $connection = $this->moduleDataSetup->getConnection();
        $tableName = $this->moduleDataSetup->getTable('my_custom_table');
        $connection->dropColumn($tableName, 'my_status');
    }

    public function getAliases()
    {
        return [];
    }

    public static function getDependencies()
    {
        return [];
    }
}

Would you please help me?

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.