0% found this document useful (0 votes)
12 views6 pages

LIQUIBASE

Uploaded by

andresweb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

LIQUIBASE

Uploaded by

andresweb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

https://www.liquibase.

com
INSTALACIÓN

LINUX MINT

Instalar java

sudo apt update


sudo apt install default-jre
java --version

Descargar liquibase
https://www.liquibase.com/download

descomprimir y mover a la carpeta /home/usuario

ejecutar:
nano ~/.bashrc

agregar al final de las lineas, reemplazando <ruta_a_liquibase> con la ruta al directorio


donde descomprimiste Liquibase

export PATH=$PATH:<ruta_a_liquibase>

quedando

export PATH=$PATH:/home/ususario/carpeta_liquibase

cerrar terminal y volver a abrir


verificar si se instaló liquibase

liquibase --version

ESTRUCTURA DE DIRECTORIOS ORIENTADO A LANZAMIENTOS

migraciones/
liquibase.properties
changelog.xml
changelogs/
changelog-1.0.xml
changelog-1.1.xml
CONFIGURACIÓN XML

Configurar liquibase.properties

# Enter the path for your changelog file.


changeLogFile=changelog.xml

#### Enter the Target database 'url' information ####


liquibase.command.url=jdbc:mariadb://localhost:3306/20600142608

# Enter the username for your Target database.


liquibase.command.username: root

# Enter the password for your Target database.


liquibase.command.password: 123456

Generar changelog.xml

liquibase generateChangeLog

Contenido del changelog (sin changeset)

<?xml version="1.0" encoding="UTF-8"?>


<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd
">
<includeAll path="changelogs/" />
</databaseChangeLog>
Estructura de una changeset
<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd
">

<!-- Cambios para crear la tabla 'area' -->


<changeSet id="US001-1" author="Juan">
<createTable tableName="area">
<column name="are_id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="are_descripcion" type="varchar(20)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<!-- Cambios para crear la tabla 'personal' -->


<changeSet id="US001-2" author="Juan">
<createTable tableName="personal">
<column name="pers_id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="pers_nombre" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="are_id" type="int">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<!-- Cambio para agregar la columna 'pers_salario' a la tabla 'personal' -->


<changeSet id="US001-3" author="Juan">
<addColumn tableName="personal">
<column name="pers_salario" type="decimal(10,2)">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>

<!-- Cambio para agregar la columna 'are_alias' a la tabla 'area' -->


<changeSet id="US001-4" author="Juan">
<addColumn tableName="area">
<column name="are_alias" type="varchar(10)">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>

<!-- Cambio para agregar la columna 'pers_apellido' a la tabla 'personal' -->


<changeSet id="US001-5" author="Juan">
<addColumn tableName="personal">
<column name="pers_apellido" type="varchar(50)">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>

<!-- definir una clave foranea -->


<changeSet id="US001-6" author="Juan">
<addForeignKeyConstraint baseColumnNames="are_id" baseTableName="personal"
constraintName="are_id" referencedColumnNames="are_id" referencedTableName="area"/>
</changeSet>

</databaseChangeLog>

COMANDOS

Iniciar un proyecto (crea la estructura)

liquibase init project

Actualizar cambios

liquibase update
SINTAXIS DE NOMBRE DEL ARCHIVO

yymmdd.version_NroHistoriaUsuario.sql

240501.0_US001.sql
240501.1_US001.sql

--liquibase formatted sql

--changeset andres:240501.0_US001

ALTER TABLE nombre_tabla ADD nombre_campo int(11) NULL

You might also like