One of example of upgrade schema and data
Path should be like this: app/code/Vendor/YourModule/Setup/UpgradeSchema.php
<?php
namespace Vendor\YourModule\Setup;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade( SchemaSetupInterface $setup, ModuleContextInterface $context ) {
$installer = $setup;
$installer->startSetup();
if(version_compare($context->getVersion(), '1.0.1', '<')) {
$installer->getConnection()->dropColumn(
$installer->getTable('data_example'),
'created_at'
);
}
$installer->endSetup();
}
}
Note: We have to check module version of in upgrade function. In this example we upgraded module from version 1.0.0 to 1.0.1. Drop created_at column from data_example table.
Path should be like this: app/code/Vendor/YourModule/Setup/UpgradeData.php
<?php
namespace Vendor\YourModule\Setup;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
class UpgradeData implements UpgradeDataInterface
{
protected $_exampleFactory;
public function __construct(\Magestore\DataExample\Model\ExampleFactory $exampleFactory)
{
$this->_exampleFactory = $exampleFactory;
}
public function upgrade( ModuleDataSetupInterface $setup, ModuleContextInterface $context ) {
if ( version_compare($context->getVersion(), '1.0.1', '<' )) {
$data = [
'title' => "The second example title",
'content' => "The second example content"
];
$example = $this->_exampleFactory->create();
$example>addData($dalogta)->save();
}
}
}
I hope this will help