How to alter a database table?

There are ready methods for some popular alterations:

If you need a custom alteration then use the query() and resetDdlCache() methods of the \Magento\Framework\DB\Adapter\AdapterInterface:

An example from the core:

By default the \Magento\Framework\DB\Adapter\AdapterInterface interface is implemented by the \Magento\Framework\DB\Adapter\Pdo\Mysql class:

When you have a \Magento\Framework\DB\Adapter\Pdo\Mysql instance you can also use rawQuery() method instead of query() (rawQuery() method is absent in the \Magento\Framework\DB\Adapter\AdapterInterface):

See also: