사용자 도구

사이트 도구


java:database:migration:liquibase

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
java:database:migration:liquibase [2020/07/16 14:08]
kwon37xi
java:database:migration:liquibase [2022/04/14 12:34] (현재)
kwon37xi
줄 15: 줄 15:
  
 // JDBC 드라이버 등 관련 의존성을 일일이 따로 걸어주거나 아래처럼 runtime에서 그대로 가져온다. // JDBC 드라이버 등 관련 의존성을 일일이 따로 걸어주거나 아래처럼 runtime에서 그대로 가져온다.
 +// 공식문서에는 runtime 을 상속하라고 돼 있지만 실제로는 runtimeClasspath 여야 작동했음. Gradle 6.5.x
 configurations { configurations {
-  liquibaseRuntime.extendsFrom runtime+  liquibaseRuntime.extendsFrom runtimeClasspath 
 } }
 +
 +// java 9 이상 버전 사용시에 jaxb 명시적 설정 필요.
 +liquibaseRuntime group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
  
 // 혹시 logback 을 안사용한다면 추가 필요. // 혹시 logback 을 안사용한다면 추가 필요.
줄 26: 줄 30:
 liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:3.6'  liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:3.6' 
 liquibaseRuntime sourceSets.main.output liquibaseRuntime sourceSets.main.output
 +
 +liquibase {
 +    activities {
 +        main {
 +            changeLogFile 'src/migration/changelog-main.xml'
 +            url "jdbc:url..."
 +            username "username"
 +            password "password"
 +        }
 +    }
 +}
 +</code>
 +===== ChangeLog 관리 =====
 +  * main changelog 관리 XML을 만들고, 거기서 각각 단일 changeset 을 가지는 다른 xml 들을 include 하는 형태로 관리하는 것이 좋다.
 +  * 하나의 chagelog 파일은 하나의 changeset 만 가지는 것이 좋다.
 +  * ''changelog-main.xml''<code 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-3.8.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> 
 +</code>
 +  * ''changelog-1.0.xml'' ... <code 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-3.8.xsd">   
 +  <changeSet  author="authorName"  id="changelog-1.0">  
 +    <createTable  tableName="TablesAndTables">  
 +      <column  name="COLUMN1"  type="TEXT">  
 +        <constraints  nullable="true"  primaryKey="false"  unique="false"/>  
 +      </column>  
 +    </createTable>  
 +  </changeSet>  
 +</databaseChangeLog> 
 +</code>
 +===== Change Set Types =====
 +==== sql ====
 +  * https://docs.liquibase.com/change-types/community/sql.html
 +  * SQL 구문을 있는 그대로 넣을 수 있다.
 +  * 기본 delimiter가 '';'' 인데, 이 경우 Stored Procedure 구문등에 '';''가 있으면 구문을 나눠서 실행해서 문법 오류가 발생한다.
 +    * ''endDelimiter'' 속성을 다른 값으로 변경하고, 해당값을 여러 구문을 구분하는 요소로 사용하도록 한다.
 +<code xml>
 +<changeSet  author="liquibase-docs"  id="sql-example">  
 +    <sql  dbms="!h2, oracle, mysql"  
 +            endDelimiter="\nGO"  
 +            splitStatements="true"  
 +            stripComments="true">
 +        <comment>What about Bob?</comment>  
 +            <![CDATA[
 +            insert into person (name) values ('Bob')
 +    ]]></sql>  
 +</changeSet>
 </code> </code>
  
 ===== 참조 ===== ===== 참조 =====
 +  * [[https://www.liquibase.org/get-started/best-practices|Getting Started | Liquibase Best Practices | Liquibase.org]]
   * [[https://www.youtube.com/watch?v=SyrjSPC8EZ8|Version based database migration with Liquibase - YouTube]]   * [[https://www.youtube.com/watch?v=SyrjSPC8EZ8|Version based database migration with Liquibase - YouTube]]
   * [[https://dzone.com/articles/managing-your-database-with-liquibase-and-gradle|Managing Your Database With Liquibase and Gradle - DZone Database]]   * [[https://dzone.com/articles/managing-your-database-with-liquibase-and-gradle|Managing Your Database With Liquibase and Gradle - DZone Database]]
   * [[https://joont92.github.io/etc/liquibase/|liquibase | 기록은 기억의 연장선]]   * [[https://joont92.github.io/etc/liquibase/|liquibase | 기록은 기억의 연장선]]
 +  * [[https://www.baeldung.com/liquibase-vs-flyway|Liquibase vs Flyway | Baeldung]]
java/database/migration/liquibase.1594876124.txt.gz · 마지막으로 수정됨: 2020/07/16 14:08 저자 kwon37xi