使用带有liquibase changeset上下文属性的spring boot配置文件来管理changset范围 [英] using spring boot profiles with liquibase changeset context attribute to manage changset scope

查看:727
本文介绍了使用带有liquibase changeset上下文属性的spring boot配置文件来管理changset范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Spring Boot和liquibase进行概念验证应用程序.我基本上想创建一个Spring Boot应用程序,该应用程序可以通过利用称为context的changeset属性来管理liquibase变更集,这样,没有上下文的变更集可以应用于任何spring boot配置文件,而具有特定上下文的变更集(例如context ="dev")仅在该类型的Spring Boot配置文件处于活动状态(例如spring.profiles.active = dev)时才会应用.

I am trying to do a proof of concept application with spring boot and liquibase. I basically want to create a spring boot app that can manage liquibase changesets by utilizing the changeset attribute called context, so that changesets with no context can be applied to any spring boot profile, whereas changesets with specific context (e.g context="dev" ) will only be applied if spring boot profiles of that type, is active (e.g spring.profiles.active=dev).

在我的应用程序中,我具有以下春季配置文件-> dev,prod(每个配置文件都在应用程序yaml文件中正确指定,并且在配置文件下也指定了相关的配置文件db凭据).我需要做些什么才能使这项工作.下面是我的application.yaml

In my app, i have the following spring profiles -> dev, prod (each specified correctly in the application yaml file with the relavant profile db credentials also specified under the profile). What do I need to do to make this work. below is my 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文件(如果我的spring配置文件为prod,则第二个更改集不应运行).

and below is the current databaseChangeLog file (the second change set shouldn't run if my spring profile is prod).

<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>

我基本上需要能够使用自己的spring档案来管理我的liquibase上下文.这可能吗?

I basically need to be able to manage my liquibase context, using my spring profile. Is this possible?

推荐答案

您需要在yaml文件中定义"liquibase.contexts"属性.像下面这样.

You need to define 'liquibase.contexts' property into your yaml file. Something like below.

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

添加此更改后,以下更改集仅在本地配置文件为'dev'时执行(即spring-boot:run -Dspring.profiles.active = dev)

After adding this the below change set will only execute when your local profile is 'dev' (i.e. spring-boot:run -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>

这篇关于使用带有liquibase changeset上下文属性的spring boot配置文件来管理changset范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆