0
votes

Why When i run my project which is with Java 8, Spring Boot, Liquibase and Postgresql, i do not see any new table in my postgres database? I installed PostgreSQL 11.6,

This is changelog-master.xml:

<?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:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<include file="/db/changelog/changes/create-table-changelog-1.xml"/>

</databaseChangeLog>

This is create-table-changelog-1.xml

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet author="admin" id="1">
<createTable tableName="person11">
<column autoIncrement="true" name="id" type="INT">
<constraints primaryKey="true"/>
</column>
<column name="name" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="address" type="VARCHAR(255)"/>
</createTable>
<!-- <rollback>
<dropTable tableName="person11"/>
</rollback>-->
</changeSet>
</databaseChangeLog>

This is application.properties:

spring.liquibase.changeLog = classpath:/db/changelog/changelog-master.xml

spring.datasource.url= jdbc:postgresql://localhost:5432/
spring.datasource.username=postgres
spring.datasource.password=postgres

This is pom.xml file:

<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.8.9</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.14</version>
<scope>compile</scope>
</dependency>
3

3 Answers

1
votes

I think you should also specify the database name at the end of your datasource url, like this jdbc:postgresql://localhost:5432/DB_NAME

You must ensure to have an implementation of JPA in order for JPA to interact with the database. I usually use the dependency spring-boot-starter-data-jpa which comes with hibernate, add the dependency in the pom file.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
1
votes

You may need to add the following dependency in your pom.xml as well:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

And if you are using Spring Boot 2, then you would also need to change the property name to spring.liquibase.change-log in your application.properties file.

0
votes

Thank you all for your answers, When i followed this link, my issue is solved. In this link there is an example for integrating Spring-Boot, JPA and Liquibase: https://auth0.com/blog/integrating-spring-data-jpa-postgresql-liquibase/