-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliquibase.advanced.flowfile.yaml
147 lines (109 loc) · 4.81 KB
/
liquibase.advanced.flowfile.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
########## LIQUIBASE FLOW FILE ##########
########## learn more http://docs.liquibase.com/flow ##########
## NOTE: This is an advanced example flowfile, compared to the other sample at examples/liquibase.flowfile.yaml
#### HOW TO USE THIS FILE:
#### example for CLI: liquibase flow --flow-file=liquibase.advanced.flowfile.yaml
#### example for ENV Var: LIQUIBASE_FLOW_FLOW_FILE=liquibase.advanced.flowfile.yaml
## Advanced options show in this file include:
#### non-default name of 'liquibase.advanced.flowfile.yaml' (use by setting flowfile property to this name)
#### use of 'include' to inject namespaced yaml files of key: val variables
#### use of globalVariables and stageVariables
#### use of globalArgs and cmdArgs
#### use of property substitution
#### use of a nested flowfile (in this case in the endStage, but could be elsewhere)
#### use of if: conditional which allows a -type: shell or -type: liquibase command to run
###### In the example below, we set an environment variable LIQUIBASE_CURRENT_TARGET, such as 'export LIQUIBASE_CURRENT_TARGET=dev'
###### This could be determined dynamically, of course, from the build tools, bu tthis is simpler for this example "if:" conditional
#### use of shell commands in a -type: shell block.
###### command: bash -c "the shell command || and its chained commands && go in the quotes"
########
#### POTENTIAL use of environment variables:
###### DATETIME STAMP
######## In this file, you could replace ${FLOWVARS.THISDATE} with an env var, such as ${LIQUIBASE_THISDATE} set via .bash_profile
######## for example 'export LIQUIBASE_THISDATE=$( date +'%Y-%m-%dT%H-%M-%S' )'
## Bring in and namespace an external file with yaml 'key: val' pairs for use in this file
## The variables will be used as ${namespace.variablename}, seen in this example as ${FLOWVARS.PROJNAME}
include:
FLOWVARS: liquibase.flowvariables.yaml
## Set up some global variables for property substitution in ANY stage
globalVariables:
DIRNAME: "./${FLOWVARS.PROJNAME}_${FLOWVARS.THISDATE}"
STATUSFILE: "status.txt"
UPDATELOG: "update.log"
HISTORYFILE: "history.txt"
## Start of the stages.
stages:
## A prep stage. There can be more than one stage if desired.
stage-prep:
actions:
- type: shell
command: bash -c "mkdir -p ${DIRNAME}"
## Another stage.
stage-dowork:
## set up vars for property substitution in THIS stage only
stageVariables:
VERBOSESTATE: TRUE
actions:
#
# Do a validate command
#
- type: liquibase
command: validate
#
# Tell me what is pending a deployment
#
- type: shell
command: bash -c "liquibase --show-banner false --outputfile ./${DIRNAME}/${STATUSFILE} status --verbose ${VERBOSESTATE}"
# This is the structured way to setup a liquibase command, if you dont want to run it as one 'bash -c' command
#- type: liquibase
# command: status
# globalArgs:
# outputfile: "${DIRNAME}/${STATUSFILE}"
# showbanner: false
# cmdArgs: {verbose: "${VERBOSESTATE}"
#
# And then save a version in detail, if env var LIQUIBASE_FILE_OUTPUT == 1
#
- type: shell
command: bash -c "echo 'LIQUIBASE_ env vars ' && env | grep 'LIQUIBASE_' "
- type: liquibase
## if this var LIQUIBASE_CURRENT_TARGET is "dev", then the updatesql will run
if: "${LIQUIBASE_CURRENT_TARGET} == dev"
command: updatesql
globalArgs: {outputfile: "${DIRNAME}/${UPDATELOG}"}
- type: shell
## if this var LIQUIBASE_CURRENT_TARGET is not "dev", then the message will be displayed
if: "${LIQUIBASE_CURRENT_TARGET} != dev"
command: echo "No output files created. Set env var LIQUIBASE_CURRENT_TARGET to dev to trigger file creation."
#
# Quality Checks for changelog
#
- type: liquibase
command: checks run
cmdArgs: {checks-scope: changelog}
#
# Run update
#
- type: liquibase
command: update
#
# Quality Checks for database
#
- type: liquibase
command: checks run
cmdArgs: {checks-scope: database}
#
# Create a history file
#
- type: liquibase
command: history
globalArgs: {outputfile: "${DIRNAME}/${HISTORYFILE}"}
## The endStage ALWAYS RUNS.
## So put actions here which you desire to perform whether previous stages' actions succeed or fail.
## If you do not want any actions to ALWAYS RUN, simply delete the endStage from your flow file.
endStage:
actions:
- type: liquibase
## Notice this is a flow command in a flow file, and it called a 'nested' flowfile, which in this case lives in the same dir, but could be elsewhere
command: flow
cmdArgs: {flowfile: liquibase.endstage.flow}