namespace Yoast\WP\Lib\Migrations;
* Yoast migrations column class.
* Creates an instance of a column.
* @param Adapter $adapter The current adapter.
* @param string $name The name of the column.
* @param string $type The type of the column.
* @param array $options The column options.
* @throws Exception If invalid arguments provided.
public function __construct( $adapter, $name, $type, $options = [] ) {
if ( ! $adapter instanceof Adapter ) {
throw new Exception( 'Invalid Adapter instance.' );
if ( empty( $name ) || ! \is_string( $name ) ) {
throw new Exception( "Invalid 'name' parameter" );
if ( empty( $type ) || ! \is_string( $type ) ) {
throw new Exception( "Invalid 'type' parameter" );
$this->adapter = $adapter;
$this->options = $options;
* Returns the SQL of this column.
public function to_sql() {
$column_sql = \sprintf( '%s %s', $this->adapter->identifier( $this->name ), $this->sql_type() );
$column_sql .= $this->adapter->add_column_options( $this->type, $this->options );
* The SQL string version.
public function __toString() {
private function sql_type() {
return $this->adapter->type_to_sql( $this->type, $this->options );