I have an existing spring boot application and i need to connect to Aurora DB using liquibase and create tables . I have added all the required steps as below but when application is getting deployed not seeing any logs specific to liquibase and the changeSet are not getting executed . Please help do debug the issue .
1.db.changelog-master.xml (created under resources/db/changelog )
<preConditions>
<not>
<tableExists tableName="table1"/>
</not>
</preConditions>
<changeSet id="1" author="name">
<createTable tableName="category">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(250)">
<constraints unique="true" nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>
application.properties
#Liquibase configuration
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://aws-aurora-conn-url:3306/database-name
spring.datasource.username=usename
spring.datasource.password=password
spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml
spring.liquibase.enabled=true
build.gradle added these dependencies
implementation 'org.liquibase:liquibase-core'
implementation 'mysql:mysql-connector-java'
Thanks in advance
Issue was due to precondition check failure. Added the condition check in db.changelog-master.xml and was able to connect it . this will not fail the application instance instead its logs it and proceed
<preConditions onFail="WARN">
<not>
<tableExists tableName="table1"/>
</not>
In first change set table tb_transformation is already created. Below is the 4th changeset where i insert extra column to table when precondition passes. But its not executing the changeset. When i remove precondition and execute its inserting successfully.
<changeSet id="2020-03-004-add-columns-to-tb_transformation" author="TAAS">
<preConditions onFail="CONTINUE">
<tableExists tableName="TB_TRANSFORMATION"/>
</preConditions>
<addColumn tableName="TB_TRANSFORMATION">
<column name="MARKET_INFRASTRUCTURE" type="varchar(255)">
<constraints nullable="false"/>
</column>
</addColumn>
Are there some environments where the table might not exist? If not, and everything is being 'controlled' by Liquibase, then you should just be able to remove the precondition.
I am trying to Creating New Liquibase Projects with Oracle 12c database.My oracle database is located on a remote server.This is my changelog for my project and it is saved as dbchangelog.xml on my machine where Liquibase is running
<?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"
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>
The liquibase.properties file is saved as follows
changeLogFile: /home/dbchangelog.xml
url : jdbc:oracle:thin:#<oracle_db_ip>:1521/ORCLDB
username : <user>
password : <password>
driver: oracle.jdbc.OracleDriver
classpath: /home/ojdbc6.jar
Do i need to keep tnsname.ora on my machine where liquibase is running? if yes where should i keep it ??
Liquibase uses jdbc API, so you don't need tnsname.ora, neither oracle client on your machine. ORA-12514 means that ORCLDB is probably wrong.
You can find the SID using this query:
select instance from v$thread
how can i set failOnError=“false” for all changeSet when generate changeLog with maven Liquibase:Diff
<changeSet author="aliakbarazizkhani (generated)" id="1468579261546-1" failOnError="false">
<addColumn tableName="core_feedback">
<column name="solveuser" type="bytea"/>
</addColumn>
</changeSet>
This is not an option you can set on the command line. You would need to manually edit the changelog after it was generated to add the failOnError attribute to the appropriate change sets. It would be inadvisiable to apply that to all generated change sets.
I am using Spring-Boot 1.2.1, and Liquibase to create both H2 (testing) and PostgreSQL (QA & Production) databases. I have a couple of tables that I want to seed when the db is created. However, despite trying both dataLoad and sqlFile, nothing is getting inserted. My sql file is just a bunch of insert statements such as:
INSERT INTO state (Name, Code) VALUES('Alabama','AL');
INSERT INTO state (Name, Code) VALUES('Alaska','AK');
Here is my relevant changelog-master.xml:
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
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.3.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
...
<changeSet id="3" author="me">
<createTable tableName="STATE">
<column name="code" type="VARCHAR(10)">
<constraints primaryKey="true"/>
</column>
<column name="name" type="VARCHAR(100)"/>
</createTable>
<sqlFile dbms="h2, PostgreSQL"
encoding="utf8"
endDelimiter="\nGO"
path="src/main/resources/db/changelog/data/states.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>
Here is my project structure:
When I startup my spring-boot app, I can see that the State table is created, but it has zero rows in it. I also tried taking the out of changeset 3 and using this:
<changeSet id="4" author="me">
<loadData file="data/state.csv" tablename="STATE" schemaName="edentalmanager" relativeToChangelogFile="true">
<column name="name" type="VARCHAR(100)"/>
<column name="code" type="VARCHAR(10)"/>
</loadData>
</changeSet>
The csv file is basically:
Alabama,AL
Alaska,AK
...
I dont' see any messages in the console logs that Liquibase is trying to create or insert the data into the table. Nor do I get any exceptions or error messages.
UPDATE:
If I copy off the state.sql as /resources/data.sql then spring-boot picks up the file and executes the sql just fine. Unfortunately, this means every time I startup, it will try and insert those values again, causing startup exceptions (duplicate key violations) But, rather than rely on a single file, I would prefer Liquibase to execute them as part of the changeset as data needs change.
I think there are two issues in your changeset 3:
The value of the path property directs to a not existing resource. When you define relativeToChangelogFile="true" then Liquibase will look for classpath:/db/changelog/src/main/resources/.../states.sql. The correct path should be path="../data/states.sql".
If the given path is not correct Liquibase should throw an exception. If you didn't get one means Liquibase decided to not execute that part because of other conditions. One of those conditions could be the dbms property. Your changeset should work with a H2 database. It should not work with a PostgreSQL database because of a wrong type name. Try dbms="h2, postgresql" instead.
After those changes I got a filled table based on your project structure.
This is because by default Hibernate drops the schema when initializing. So first Liquibase creates the data and when finished Hibernate drops the tables and recreates them according to the JPA entities you defined.
You can verify this by looking for the log record:
2017-01-19 11:03:48.692 INFO 15161 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
You can tell Hibernate not to do anything with the DB schema by setting this application property:
spring.jpa.hibernate.ddl-auto=none
I ran into this when upgrading to spring boot 2.4.1 from 2.2.0-RELEASE version. The 2.2.0-RELEASE version had liquibase-core:jar:3.8.0 as dependency and it was accurately taking relativeToChangelogFile="true". However the 2.4.1 version has liquibase-core:jar:3.10.3 version which breaks the loadData feature.
The csv file I was loading and the changelog.xml file were in the same class directory in my case src/main/resources/liquibase/version2/changelog.xml and src/main/resources/liquibase/version2/xref_specialty_codes.csv
Here is the snippet from my changelog.xml for loading the data which did not work with the later version of liquibase
<changeSet author="anon"
id="xref_specialty_codes_load_data"
objectQuotingStrategy="LEGACY">
<loadData catalogName="adb"
schemaName="public"
encoding="UTF-8"
file="xref_specialty_codes.csv"
relativeToChangelogFile="true"
separator=","
tableName="xref_specialty_codes"
usePreparedStatements="true">
<column name="id" type="NUMERIC"/>
...
....
</loadData>
</changeSet>
I load a hierarchy of change log files with the top one at src/main/resources/liquibase/changelog.xml with the following layout.
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<property name="now" value="now()" dbms="postgresql"/>
<include file="src/main/resources/liquibase/version1/changelog.xml" />
<include file="src/main/resources/liquibase/version2/changelog.xml" />
....
</databaseChangeLog>