<?php

use Phinx\Db\Adapter\MysqlAdapter;

class CreateCuota 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('cuota')
			->addColumn('pie', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
			->addColumn('fecha', 'date', ['null' => false])
			->addColumn('valor_$', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
			->addColumn('estado', 'boolean', ['length' => 1, 'default' => 0])
			->addColumn('banco', 'string', ['length' => 20, 'null' => false])
			->addColumn('fecha_pago', 'date', ['default' => null, 'null' => true])
			->addColumn('abonado', 'boolean', ['length' => 1, 'default' => 0])
			->addColumn('fecha_abono', 'date', ['default' => null, 'null' => true])
			->addColumn('uf', 'double', ['default' => 0])
			->addColumn('pago', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
			->addColumn('numero', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
			->addForeignKey('pago', 'pago', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
			->addForeignKey('pie', 'pie', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
			->create();
		$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
	}
}
