When you install or upgrade a module, you may need to change the database structure or add some new data in current table. Magento 2 provide you some classes which you can do all of them.

  • InstallSchema – This class will execute when the module is installed to setup the database structure.
  • InstallData – This class will execute when the module is installed to initial the data for database table.
  • UpgradeSchema – This class will execute when the module is upgraded to setup the database structure.
  • UpgradeData – This class will execute when the module is upgraded to add/remove data from table.

Now we want to add new column in Magento Structure. For this we need to create the InstallSchema file.

Create the InstallSchema.php in the path app/code/[Vendor Name]/[Module Name]/Setup/InstallSchema.php

namespace [Vendor Name]\[Module Name]\Setup;

use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;


class InstallSchema implements InstallSchemaInterface
{
    
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        
        $connection = $setup->getConnection();
 
            $column = [
                'type' => Table::TYPE_SMALLINT,
                'length' => 6,
                'nullable' => false,
                'comment' => 'Gift Charge Enable',
                'default' => '0'
            ];
            $connection->addColumn($setup->getTable('sales_order'), 'giftcharge_enable', $column);
        }
}

After adding this column in the setup file, run the following command:
php bin/magento setup:upgrade

After installing the module, you can see the field in the Sales_order table.