目录
数据库配置
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot_blog
spring.datasource.username=root
spring.datasource.password=root
Liquibase配置
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
目录结构
com/
example/
db/
changelog/
db.changelog-master.xml
db.changelog-1.0.xml
db.changelog-1.1.xml
db.changelog-2.0.xml
db.changelog-master.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"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
<include file="com/example/db/changelog/db.changelog-1.0.xml"/>
<include file="com/example/db/changelog/db.changelog-1.1.xml"/>
<include file="com/example/db/changelog/db.changelog-2.0.xml"/>
</databaseChangeLog>
db.changelog-1.0.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"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
<changeSet id="202110201812" author="huoxiaoqiang">
<createTable tableName="house">
<column name="id" type="bigint">
<constraints primaryKey="true" primaryKeyName="house_id_pk" />
</column>
<column name="owner" type="varchar(250)">
<constraints unique="true" uniqueConstraintName="house_owner_unq" />
</column>
<column name="fully_paid" type="boolean" defaultValueBoolean="false"></column>
</createTable>
<createTable tableName="item">
<column name="id" type="bigint">
<constraints primaryKey="true" primaryKeyName="item_id_pk" />
</column>
<column name="name" type="varchar(250)" />
<column name="house_id" type="bigint">
<constraints nullable="false" notNullConstraintName="item_house_id_nn" />
</column>
</createTable>
<addAutoIncrement tableName="house" columnName="id" columnDataType="bigint" startWith="1" incrementBy="1" />
<addAutoIncrement tableName="item" columnName="id" columnDataType="bigint" startWith="1" incrementBy="1" />
<createSequence sequenceName="hibernate_sequence" incrementBy="1" startValue="1" />
<addForeignKeyConstraint baseTableName="item" baseColumnNames="house_id" constraintName="item_house_id_fk" referencedTableName="house" referencedColumnNames="id" />
</changeSet>
</databaseChangeLog>
原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/java/spring-data-jpa/8681.html