2016-10-17 15 views
0

스프링 부트 및 liquibase를 사용하여 개념 증명 신청을하려고합니다. 기본적으로 컨텍스트라는 changeset 속성을 사용하여 liquibase 변경 집합을 관리 할 수있는 스프링 부팅 응용 프로그램을 만들려고합니다. 컨텍스트가없는 변경 집합은 특정 컨텍스트 (예 : context = "dev")가있는 변경 집합은 모든 스프링 부팅 프로필에 적용될 수 있습니다. 해당 유형의 스프링 부트 프로파일이 활성화 된 경우에만 적용됩니다 (예 : spring.profiles.active = dev).changset 범위를 관리하기 위해 liquibase changeset 컨텍스트 속성을 가진 스프링 부트 프로파일 사용

내 응용 프로그램에는 다음과 같은 스프링 프로필이 있습니다 -> dev, prod (프로필 아래에 지정된 relavant 프로필 db 자격 증명이있는 응용 프로그램 yaml 파일에 올바르게 지정됨). 이 작업을하려면 무엇을해야합니까? 아래에있는 내 application.yaml

spring: 
    application: 
    name: liquibase-spring-jpa-postgres-example 
liquibase: 
    change-log: db.changelog/db.changelog-master.xml 

spring: 
    profiles: dev 
    datasource: 
    url: jdbc:postgresql://localhost:5432/dev 
    username: postgres 
    password: password 
    driver-class-name: org.postgresql.Driver 

spring: 
    profiles: ci 
    datasource: 
     url: jdbc:postgresql://localhost:5432/ci 
     username: postgres 
     password: password 
     driver-class-name: org.postgresql.Driver 

spring: 
    profiles: qa 
    datasource: 
     url: jdbc:postgresql://localhost:5432/qa 
     username: postgres 
     password: password 
     driver-class-name: org.postgresql.Driver 

spring: 
    profiles: production 
    datasource: 
     url: jdbc:postgresql://localhost:5432/prod 
     username: postgres 
     password: password 
     driver-class-name: org.postgresql.Driver 

이며, 아래 현재 databaseChangeLog 파일입니다 (내 봄 프로파일이 자극되는 경우, 두 번째 변경 세트가 실행되지해야한다).

<changeSet id="20161016_my_first_change" author="fike" context="dev, qa, ci, production"> 
    <sql> 
     CREATE TABLE customer 
     (
     id BIGSERIAL PRIMARY KEY, 
     firstname character varying NOT NULL, 
     lastname character varying NOT NULL 
     ); 
    </sql> 
    <rollback> 
     drop table customer; 
    </rollback> 
</changeSet> 

<changeSet id="20161016_my_first_change2" author="krudland" context="dev"> 
    <sql> 
     insert into customer (firstname, lastname) values ('Franklin','Ike'); 
    </sql> 
    <rollback> 
     delete from customer where firstname = 'Franklin' and lastname = 'Ike'; 
    </rollback> 
</changeSet> 

나는 기본적으로 내 봄 프로파일을 사용하여, 내 liquibase 컨텍스트를 관리 할 수 ​​있어야합니다. 이것이 가능한가?

답변

1

yaml 파일에 'liquibase.contexts'속성을 정의해야합니다. 아래처럼.

spring: 
    profiles: dev 
    datasource: 
    url: jdbc:postgresql://localhost:5432/dev 
    username: postgres 
    password: password 
    driver-class-name: org.postgresql.Driver 
liquibase: 
    contexts: dev 

로컬 프로파일 "디바이스"인 경우 아래의 변경 세트를 추가 만하면 실행된다 (즉 스프링 부트 : 실행 -Dspring.profiles.active = DEV)

<changeSet id="20161016_my_first_change2" author="krudland" context="dev"> 
    <sql> 
     insert into customer (firstname, lastname) values ('Franklin','Ike'); 
    </sql> 
    <rollback> 
     delete from customer where firstname = 'Franklin' and lastname = 'Ike'; 
    </rollback> 
</changeSet>