You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.9 KiB
102 lines
3.9 KiB
<?php |
|
|
|
use Phinx\Migration\AbstractMigration; |
|
|
|
class EsMayor25SinSecundario extends AbstractMigration |
|
{ |
|
|
|
/** |
|
* @see https://phinx.readthedocs.io/en/latest/migrations.html#the-up-method |
|
* Migrate Up (Aplica cambios en la DB). |
|
*/ |
|
public function up() |
|
{ |
|
|
|
// También se puede ejecutar desde un archivo .sql |
|
//$sql = file_get_contents(realpath(dirname(__FILE__).'/../../BD/conversion/mig_3.11_a_3.12.sql')); |
|
//$this->execute($sql); |
|
|
|
$this->execute("INSERT INTO app_versiones_base (version_base, fecha_actualizacion, observaciones) VALUES ('3.12', CURRENT_TIMESTAMP, 'Versión 3.12 de la base de Preinscripción')"); |
|
|
|
$sga_preinscripcion = $this->table('sga_preinscripcion'); |
|
|
|
// Si no existe la columna 'es_mayor_25_sin_secundario' en la tabla 'sga_preinscripcion' |
|
if (!$sga_preinscripcion->hasColumn('es_mayor_25_sin_secundario')) { |
|
|
|
/** |
|
* @see https://phinx.readthedocs.io/en/latest/migrations.html#adding-a-column-after-another-column |
|
* Se agrega la columna 'es_mayor_25_sin_secundario' en la tabla 'sga_preinscripcion'. |
|
*/ |
|
$sga_preinscripcion->addColumn('es_mayor_25_sin_secundario', 'char', ['length' => 1, 'null' => false, 'default' => 'N','after' => 'estado']); |
|
$sga_preinscripcion->update(); |
|
|
|
// También se puede agregar de esta forma |
|
//$this->execute("ALTER TABLE sga_preinscripcion ADD COLUMN es_mayor_25_sin_secundario Char(1) NOT NULL DEFAULT 'N'"); |
|
|
|
// Se agrega la CONSTRAINT |
|
$this->execute("ALTER TABLE sga_preinscripcion ADD CONSTRAINT ck_sga_preinscripcion_es_mayor_25_sin_secundario CHECK (es_mayor_25_sin_secundario IN ('N', 'S'))"); |
|
|
|
/** |
|
* Se insertan datos en las tablas 'sga_campos_form' y 'sga_campos_conf' |
|
* @see https://phinx.readthedocs.io/en/latest/migrations.html#inserting-data. |
|
*/ |
|
$row = [ |
|
'columna' => 'es_mayor_25_sin_secundario', |
|
'descripcion' => 'Es mayor de 25 años y no tiene estudios secundarios' |
|
]; |
|
|
|
$sga_campos_form = $this->table('sga_campos_form'); |
|
$sga_campos_form->insert($row); |
|
$sga_campos_form->saveData(); |
|
|
|
$row = [ |
|
'propuesta_tipo' => '200', |
|
'columna' => 'es_mayor_25_sin_secundario', |
|
'visible' => 1, |
|
'obligatorio' => 1, |
|
'se_imprime' => 1 |
|
]; |
|
|
|
$sga_campos_conf = $this->table('sga_campos_conf'); |
|
$sga_campos_conf->insert($row); |
|
$sga_campos_conf->saveData(); |
|
|
|
// También se pueden insertan datos de esta forma |
|
//$this->execute("INSERT INTO sga_campos_form (columna, descripcion) VALUES ('es_mayor_25_sin_secundario', 'Es mayor de 25 años y no tiene estudios secundarios')"); |
|
//$this->execute("INSERT INTO sga_campos_conf (propuesta_tipo, columna, visible, obligatorio, se_imprime) VALUES ('200', 'es_mayor_25_sin_secundario', 1, 1, 1)"); |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
* @see https://phinx.readthedocs.io/en/latest/migrations.html#the-down-method |
|
* Migrate Down (Revierte cambios en la DB). |
|
*/ |
|
public function down() |
|
{ |
|
$this->execute("DELETE FROM app_versiones_base WHERE version_base = '3.12'"); |
|
|
|
$sga_preinscripcion = $this->table('sga_preinscripcion'); |
|
|
|
// Si existe la columna 'es_mayor_25_sin_secundario' en la tabla 'sga_preinscripcion' |
|
if ($sga_preinscripcion->hasColumn('es_mayor_25_sin_secundario')) { |
|
|
|
$this->execute("DELETE FROM sga_campos_conf WHERE columna = 'es_mayor_25_sin_secundario'"); |
|
$this->execute("DELETE FROM sga_campos_form WHERE columna = 'es_mayor_25_sin_secundario'"); |
|
|
|
// Se borra la CONSTRAINT |
|
$this->execute("ALTER TABLE sga_preinscripcion DROP CONSTRAINT ck_sga_preinscripcion_es_mayor_25_sin_secundario"); |
|
|
|
/** |
|
* @see https://phinx.readthedocs.io/en/latest/migrations.html#dropping-a-column |
|
* Se borra la columna 'es_mayor_25_sin_secundario' de la tabla 'sga_preinscripcion'. |
|
*/ |
|
$sga_preinscripcion->removeColumn('es_mayor_25_sin_secundario')->save(); |
|
|
|
// También se puede borrar de esta forma |
|
//$this->execute("ALTER TABLE sga_preinscripcion DROP COLUMN es_mayor_25_sin_secundario"); |
|
|
|
} |
|
} |
|
}
|
|
|