postgresql - How can I use liquibase in Spring Project -
i trying learn liquibase. couldn't apply steps in samples. can tell me step step how can add table or column database , see changes ?
my project spring mvc project , use maven, hibernate, postgresql , change database programmatically.
you need liquibase , hibernate jars. consider have pojo class person id,name,gender properties. create getters , setters of these properties.
you need create liquibase file (db-changelog.xml)
for example :
<?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-2.0.xsd"> <changeset author="rover" id="123456789-1"> <createtable tablename="person"> <column autoincrement="true" name="person_id" type="bigint"> <constraints nullable="false" primarykey="true" /> </column> <column name="name" type="varchar(255)" /> <column name="gender" type="varchar(2)" /> </createtable> </changeset> </databasechangelog> don't forget add liquibase bean in bean
<bean id="liquibaseupdater" class="liquibase.integration.spring.springliquibase"> <property name="datasource" ref="datasource" /> <property name="changelog" value="classpath:db-changelog.xml" /> </bean> you need add spring/hibernate beans.
Comments
Post a Comment