maven使用liqubase管理数据库

本文记录了如何利用Maven的Liubase插件在Eclipse环境下,实现项目启动时自动创建数据库表的操作。通过配置changelog.xml和pom.xml文件,可以便捷地管理数据库变更。

第二次使用maven的liqubase插件在项目启动的时候自动建表,记录一下,备忘:


使用eclipse的maven插件:


changelog.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.0.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
	<changeSet id="xxx-2015-6-30-1" author="jiangyu">
		 <sqlFile path="city_table_struct.sql" encoding="UTF-8"	relativeToChangelogFile="true" />
	</changeSet>
	<changeSet id="xxx-2015-6-30-2" author="jiangyu">
		 <sqlFile path="city_init_data.sql" encoding="UTF-8"	relativeToChangelogFile="true" />
	</changeSet>
</databaseChangeLog>

pom文件配置:

<plugin>
				<groupId>org.liquibase</groupId>
				<artifactId>liquibase-maven-plugin</artifactId>
				<version>3.0.5</version>
				<configuration>
					<changeLogFile>src/main/resources/city/cityinit.changelog.xml</changeLogFile>
					<driver>${dataSource.project.driverClass}</driver>
					<url>${dataSource.project.jdbcURL}</url>
					<username>${dataSource.project.user}</username>
					<password>${dataSource.project.password}</password>
				</configuration>
				<executions>
					<execution>
						<phase>process-resources</phase>
						<goals>
							<goal>update</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
<pre name="code" class="html"><pluginManagement>
			<plugins>
				<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on 
					the Maven build itself. -->
				<plugin>
					<groupId>org.eclipse.m2e</groupId>
					<artifactId>lifecycle-mapping</artifactId>
					<version>1.0.0</version>
					<configuration>
						<lifecycleMappingMetadata>
							<pluginExecutions>
								<pluginExecution>
									<pluginExecutionFilter>
										<groupId>org.liquibase</groupId>
										<artifactId>liquibase-maven-plugin</artifactId>
										<versionRange>[3.0.5,)</versionRange>
										<goals>
											<goal>update</goal>
										</goals>
									</pluginExecutionFilter>
									<action>
										<ignore></ignore>
									</action>
								</pluginExecution>
							</pluginExecutions>
						</lifecycleMappingMetadata>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值