namespace Yoast\WP\Lib\Migrations;
abstract class Migration {
* The plugin this migration belongs to.
public static $plugin = 'unknown';
* Performs the migration.
abstract public function up();
abstract public function down();
* Creates a new migration.
* @param Adapter $adapter The current adapter.
public function __construct( Adapter $adapter ) {
$this->set_adapter( $adapter );
* @param Adapter $adapter The adapter to set.
public function set_adapter( $adapter ) {
if ( ! $adapter instanceof Adapter ) {
$this->adapter = $adapter;
* Returns the current adapter.
public function get_adapter() {
* @param string $name The name of the database.
* @param array|null $options The options.
public function create_database( $name, $options = null ) {
return $this->adapter->create_database( $name, $options );
* @param string $name The name of the database.
public function drop_database( $name ) {
return $this->adapter->drop_database( $name );
* @param string $table_name The name of the table.
public function drop_table( $table_name ) {
return $this->adapter->drop_table( $table_name );
* @param string $name The name of the table.
* @param string $new_name The new name of the table.
public function rename_table( $name, $new_name ) {
return $this->adapter->rename_table( $name, $new_name );
* @param string $table_name The name of the table.
* @param string $column_name The column name.
* @param string $new_column_name The new column name.
public function rename_column( $table_name, $column_name, $new_column_name ) {
return $this->adapter->rename_column( $table_name, $column_name, $new_column_name );
* @param string $table_name The name of the table.
* @param string $column_name The column name.
* @param string $type The column type.
* @param array|string $options The options.
public function add_column( $table_name, $column_name, $type, $options = [] ) {
return $this->adapter->add_column( $table_name, $column_name, $type, $options );
* @param string $table_name The name of the table.
* @param string $column_name The column name.
public function remove_column( $table_name, $column_name ) {
return $this->adapter->remove_column( $table_name, $column_name );
* @param string $table_name The name of the table.
* @param string $column_name The column name.
* @param string $type The column type.
* @param array|string $options The options.
public function change_column( $table_name, $column_name, $type, $options = [] ) {
return $this->adapter->change_column( $table_name, $column_name, $type, $options );
* @param string $table_name The name of the table.
* @param array|string $column_name The column name.
* @param array|string $options The options.
public function add_index( $table_name, $column_name, $options = [] ) {
return $this->adapter->add_index( $table_name, $column_name, $options );
* @param string $table_name The name of the table.
* @param array|string $column_name The column name.
* @param array|string $options The options.
public function remove_index( $table_name, $column_name, $options = [] ) {
return $this->adapter->remove_index( $table_name, $column_name, $options );
* @param string $table_name The name of the table.
* @param string $created_column_name Created at column name.
* @param string $updated_column_name Updated at column name.
public function add_timestamps( $table_name, $created_column_name = 'created_at', $updated_column_name = 'updated_at' ) {
return $this->adapter->add_timestamps( $table_name, $created_column_name, $updated_column_name );
* @param string $table_name The name of the table.
* @param string $created_column_name Created at column name.
* @param string $updated_column_name Updated at column name.
public function remove_timestamps( $table_name, $created_column_name = 'created_at', $updated_column_name = 'updated_at' ) {
return $this->adapter->remove_timestamps( $table_name, $created_column_name, $updated_column_name );
* @param string $table_name The name of the table.
* @param array|string $options The options.
public function create_table( $table_name, $options = [] ) {
return $this->adapter->create_table( $table_name, $options );
* Execute a query and return the first result.
* @param string $sql The query to run.
public function select_one( $sql ) {
return $this->adapter->select_one( $sql );
* Execute a query and return all results.
* @param string $sql The query to run.
public function select_all( $sql ) {
return $this->adapter->select_all( $sql );
* @param string $sql The query to run.
public function query( $sql ) {
return $this->adapter->query( $sql );
* Returns a quoted string.
* @param string $str The string to quote.
public function quote_string( $str ) {
return $this->adapter->quote_string( $str );