databaseChangeLog 文件 标签

 1.changelog文件的<changeset>标签

一个<changeSet>标签对应一个变更集, 由属性id、name,以及changelog的文件路径唯一标识。
changelog在执行的时候并不是按照change log的id的顺序,而是按照changeSet在changelog中出现的顺序

changelog中的一个changeSet对应一个事务,在changeSet执行完后commit,如果出现错误则rollback;

<changeSet>标签的 runAlways属性:即使已经执行过,仍然每次都执行;
<changeSet>标签的 runOnChange 属性: 由于DATABASECHANGELOG表中还记录了changeSet的MD5校验值MD5SUM,如果changeSet的id和name没变,而内容变了,则由于MD5值变了,即使runAlways的值为True,执行也是失败的,会报错。这种情况应该使用。
 

 2.常用到的一些 changeset

建表的changeset

<changeSet author="ds" id="201908091500_T_TABLE_NAME_DDL-1">
	<preConditions onFail="MARK_RAN">
		<not>
			<tableExists tableName="T_TABLE_NAME" />
		</not>
	</preConditions>
	<createTable tableName="T_TABLE_NAME">
		<column name="ID" remarks="pk" type="NUMBER(19)">
			<constraints nullable="false" />
		</column>			
		<column name="LOCK_TYPE" type="NUMBER(2)" />
 		<column name="INSERT_TIME" type="date" /> 
	</createTable>
</changeSet>

 建主键的changeset 

<changeSet author="ds" id="201908091500_T_TABLE_NAME_DDL-2">
	<preConditions onFail="MARK_RAN">
		<not>
			<primaryKeyExists tableName="T_TABLE_NAME" primaryKeyName="ID" />
		</not>
	</preConditions>
	<addPrimaryKey columnNames="ID" tableName="T_TABLE_NAME" />
</changeSet>

加字段的changeset 

<changeSet author="ds" id="201908091500_T_TABLE_NAME_DDL-3">
	<preConditions onFail="MARK_RAN">
		<not>
			<columnExists tableName="T_TABLE_NAME" columnName="CODE" />
		</not>
	</preConditions>
	<addColumn tableName="T_TABLE_NAME">
		<column name="CODE" remarks="" type="VARCHAR2(40)" />
	</addColumn>
</changeSet>

 删字段的changeset

 <changeSet author="ds" id="201908091500_T_TABLE_NAME_DDL-4">
	<dropColumn columnName="code1" tableName="T_TABLE_NAME" />
</changeSet>

 更新数据的changeset

<changeSet author="ds" id="201908091500_T_TABLE_NAME_DDL-5" dbms="oracle"failOnError="false">
	<sql splitStatements="false" stripComments="true">
		update t_table_name s set s.code=s.code1  
	</sql>
</changeSet>

 建sequence的changeset 

<changeSet author="ds" id="201908091500_T_TABLE_NAME_DDL-6">
	<preConditions onFail="MARK_RAN">
		<not>
			<sequenceExists sequenceName="S_TABLE_NAME" />
		</not>
	</preConditions>
	<createSequence cacheSize="20" cycle="false"
			incrementBy="1" maxValue="999999999999" minValue="1" ordered="false"
			sequenceName="S_TABLE_NAME" startValue="1" />
	</changeSet>

 

posted on 2019-08-09 15:58  dreamstar  阅读(547)  评论(0编辑  收藏  举报