You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »


Create a new java project

Add file liquibase.properties

liquibase.properties
 changeLogFile: dbchangelog.xml
 url: jdbc:mariadb://localhost:3306/policy
 username: policy
 password: *****


Add file dbhchangelog.xml


dbchangelog.xml
<?xml version="1.0" encoding="UTF-8"?>
 <databaseChangeLog  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"  
                    xmlns:pro="http://www.liquibase.org/xml/ns/pro"  
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
                    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">  
 
     <changeSet  id="1"  author="bob">  
         <createTable  tableName="department">  
             <column  name="id"  type="int">  
                 <constraints  primaryKey="true"  nullable="false"/>  
             </column>  
             <column  name="name"  type="varchar(50)">  
                 <constraints  nullable="false"/>  
             </column>  
             <column  name="active"  type="boolean"  defaultValueBoolean="true"/>  
         </createTable>  
    </changeSet>  
 </databaseChangeLog>


Add pox.xml

pom.xml
 <project  xmlns="http://maven.apache.org/POM/4.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
   <modelVersion>4.0.0</modelVersion>  
 
   <groupId>com.liquibase.mariadb.app</groupId>  
   <artifactId>LiquibaseMariadbp</artifactId>  
   <version>1.0-SNAPSHOT</version>  
   <build>  
       <pluginManagement>  
           <plugins>  
               <plugin>  
                   <groupId>org.liquibase</groupId>  
                   <artifactId>liquibase-maven-plugin</artifactId>  
                   <version>3.8.0</version>  
                   <configuration>  
                       <propertyFile>liquibase.properties</propertyFile>  
                   </configuration>  
                   <dependencies>  
					<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
					<dependency>
					    <groupId>org.mariadb.jdbc</groupId>
					    <artifactId>mariadb-java-client</artifactId>
					    <version>2.7.3</version>
					</dependency>					
				   <dependency>  
                       <groupId>org.hibernate</groupId>  
                       <artifactId>hibernate-core</artifactId>  
                       <version>5.4.6.Final</version>  
                   </dependency>  
                 </dependencies>  
               </plugin>  
           </plugins>  
       </pluginManagement>  
   </build>  
 </project>


From the command line in the project directory

mvn package

mvn liquibase:update

Check you database, table department has been added

mvn liquibase:rollback -Dliquibase.rollbackCount=1

table department has been dropped


  • No labels