<?php

use Phinx\Db\Adapter\MysqlAdapter;

class CreateUnidad extends Phinx\Migration\AbstractMigration
{
	public function change(): void
	{
		$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
		$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
		$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");

		$this->table('unidad')
			->addColumn('proyecto', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
			->addColumn('tipo', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
			->addColumn('subtipo', 'string', ['length' => 20, 'default' => null, 'null' => true])
			->addColumn('piso', 'integer', ['length' => 11, 'null' => false])
			->addColumn('descripcion', 'string', ['length' => 30, 'null' => false])
			->addColumn('abreviacion', 'string', ['length' => 10, 'null' => false])
			->addColumn('m2', 'float', ['default' => null, 'null' => true])
			->addColumn('terraza', 'float', ['default' => null, 'null' => true])
			->addColumn('cubierta', 'float', ['default' => 0])
			->addColumn('logia', 'float', ['default' => null, 'null' => true])
			->addColumn('orientacion', 'char', ['length' => 2, 'default' => null, 'null' => true])
			->addColumn('costo_inmobiliaria', 'float', ['default' => 0])
			->addColumn('pt', 'integer', ['length' => 11, 'null' => false, 'signed' => false])
			->addColumn('valor', 'float', ['default' => null, 'null' => true])
			->addForeignKey('proyecto', 'proyecto', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
			->addForeignKey('pt', 'proyecto_tipo_unidad', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
			->create();
		$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
	}
}
