找不到生成参数化循环的方法,因此使用了temopary列来存储引用的id。
<changeSet id="add temp_column to Entities" author="">
<addColumn tableName="Entities">
<column name="temp_id" type="BIGINT"></column>
</addColumn>
</changeSet>
<changeSet author="" id="insert Existing_table keys into Entities">
<sql>
INSERT INTO Entities(type_id, temp_id)
select 1, id
from Existing_table;
</sql>
</changeSet>
<changeSet author="" id="insert entity keys into Existing_table">
<sql>
UPDATE Existing_table d set entity_id = ent.id
FROM (select id, temp_id
from Entities) ent
where ent.temp_id = d.id;
</sql>
</changeSet>
<changeSet id="drop temp_column to Entities" author="">
<dropColumn tableName="Entities"
columnName="temp_id"/>
</changeSet>
<changeSet author="" id="addNotNullConstraint Existing_table-Entities">
<addNotNullConstraint columnDataType="BIGINT"
columnName="entity_id"
tableName="Existing_table"/>
</changeSet>