|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<style> |
|
body { |
|
margin: 0 auto; |
|
max-width: 800px; |
|
padding: 1rem; |
|
} |
|
|
|
h1 a { |
|
color: #000; |
|
text-decoration: none; |
|
} |
|
|
|
h2 small { |
|
font-size: 0.6em; |
|
margin-left: 3rem; |
|
} |
|
|
|
p { |
|
line-height: 2rem; |
|
} |
|
|
|
img { |
|
max-width: 100%; |
|
} |
|
|
|
li { |
|
margin: 1rem 0; |
|
} |
|
|
|
ul.none { |
|
list-style: none; |
|
padding-left: 0; |
|
} |
|
|
|
small { |
|
color: grey; |
|
} |
|
|
|
code { |
|
background: #f1f1f1; |
|
font-size: 0.8rem; |
|
padding: 2px 2px; |
|
} |
|
|
|
.highlight { |
|
max-width: 100%; |
|
} |
|
|
|
.highlight pre { |
|
background-color: #f6f8fa; |
|
border-radius: 6px; |
|
padding: 1rem; |
|
white-space: pre-wrap; |
|
word-break: break-word; |
|
} |
|
|
|
pre code { |
|
background: transparent; |
|
} |
|
|
|
blockquote { |
|
color: dimgrey; |
|
font-style: italic; |
|
margin-left: 1rem; |
|
padding-left: 1em; |
|
box-shadow: #e1e1e1 3px 0 0 0 inset; |
|
} |
|
|
|
hr { |
|
margin: 1.5rem auto; |
|
} |
|
|
|
article footer { |
|
margin-top: 2rem; |
|
} |
|
|
|
footer#mastfoot { |
|
border-top: 1px solid lightgrey; |
|
margin: 2rem auto; |
|
padding: 1rem 0; |
|
} |
|
|
|
#callout { |
|
background: #e9f5db; |
|
padding: 1rem 2rem; |
|
} |
|
|
|
#callout blockquote { |
|
color: #010101; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
.chroma { background-color: #ffffff } |
|
.chroma .x { } |
|
.chroma .err { color: #a61717; background-color: #e3d2d2 } |
|
.chroma .lntd { vertical-align: top; padding: 0; margin: 0; border: 0; } |
|
.chroma .lntable { border-spacing: 0; padding: 0; margin: 0; border: 0; width: auto; overflow: auto; display: block; } |
|
.chroma .hl { display: block; width: 100%;background-color: #ffffcc } |
|
.chroma .lnt { margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f } |
|
.chroma .ln { margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f } |
|
.chroma .k { color: #000000; font-weight: bold } |
|
.chroma .kc { color: #000000; font-weight: bold } |
|
.chroma .kd { color: #000000; font-weight: bold } |
|
.chroma .kn { color: #000000; font-weight: bold } |
|
.chroma .kp { color: #000000; font-weight: bold } |
|
.chroma .kr { color: #000000; font-weight: bold } |
|
.chroma .kt { color: #445588; font-weight: bold } |
|
.chroma .n { } |
|
.chroma .na { color: #008080 } |
|
.chroma .nb { color: #0086b3 } |
|
.chroma .bp { color: #999999 } |
|
.chroma .nc { color: #445588; font-weight: bold } |
|
.chroma .no { color: #008080 } |
|
.chroma .nd { color: #3c5d5d; font-weight: bold } |
|
.chroma .ni { color: #800080 } |
|
.chroma .ne { color: #990000; font-weight: bold } |
|
.chroma .nf { color: #990000; font-weight: bold } |
|
.chroma .fm { } |
|
.chroma .nl { color: #990000; font-weight: bold } |
|
.chroma .nn { color: #555555 } |
|
.chroma .nx { } |
|
.chroma .py { } |
|
.chroma .nt { color: #000080 } |
|
.chroma .nv { color: #008080 } |
|
.chroma .vc { color: #008080 } |
|
.chroma .vg { color: #008080 } |
|
.chroma .vi { color: #008080 } |
|
.chroma .vm { } |
|
.chroma .l { } |
|
.chroma .ld { } |
|
.chroma .s { color: #dd1144 } |
|
.chroma .sa { color: #dd1144 } |
|
.chroma .sb { color: #dd1144 } |
|
.chroma .sc { color: #dd1144 } |
|
.chroma .dl { color: #dd1144 } |
|
.chroma .sd { color: #dd1144 } |
|
.chroma .s2 { color: #dd1144 } |
|
.chroma .se { color: #dd1144 } |
|
.chroma .sh { color: #dd1144 } |
|
.chroma .si { color: #dd1144 } |
|
.chroma .sx { color: #dd1144 } |
|
.chroma .sr { color: #009926 } |
|
.chroma .s1 { color: #dd1144 } |
|
.chroma .ss { color: #990073 } |
|
.chroma .m { color: #009999 } |
|
.chroma .mb { color: #009999 } |
|
.chroma .mf { color: #009999 } |
|
.chroma .mh { color: #009999 } |
|
.chroma .mi { color: #009999 } |
|
.chroma .il { color: #009999 } |
|
.chroma .mo { color: #009999 } |
|
.chroma .o { color: #000000; font-weight: bold } |
|
.chroma .ow { color: #000000; font-weight: bold } |
|
.chroma .p { } |
|
.chroma .c { color: #999988; font-style: italic } |
|
.chroma .ch { color: #999988; font-style: italic } |
|
.chroma .cm { color: #999988; font-style: italic } |
|
.chroma .c1 { color: #999988; font-style: italic } |
|
.chroma .cs { color: #999999; font-weight: bold; font-style: italic } |
|
.chroma .cp { color: #999999; font-weight: bold; font-style: italic } |
|
.chroma .cpf { color: #999999; font-weight: bold; font-style: italic } |
|
.chroma .g { } |
|
.chroma .gd { color: #000000; background-color: #ffdddd } |
|
.chroma .ge { color: #000000; font-style: italic } |
|
.chroma .gr { color: #aa0000 } |
|
.chroma .gh { color: #999999 } |
|
.chroma .gi { color: #000000; background-color: #ddffdd } |
|
.chroma .go { color: #888888 } |
|
.chroma .gp { color: #555555 } |
|
.chroma .gs { font-weight: bold } |
|
.chroma .gu { color: #aaaaaa } |
|
.chroma .gt { color: #aa0000 } |
|
.chroma .gl { text-decoration: underline } |
|
.chroma .w { color: #bbbbbb } |
|
</style> |
|
<meta charset="utf-8"> |
|
<meta content="width=device-width,initial-scale=1" name="viewport"> |
|
<meta content="interest-cohort=()" http-equiv="permissions-policy"> |
|
<meta content="Running Liquibase against and existing database using LiquibaseServletListener | Tony Wolski" property="og:title"> |
|
<meta content="I recently took on the task of integrating Liquibase into the project I’m working on at work. I’d played around with Liquibase before on small …" property="og:description"> |
|
<meta content="" property="og:url"> |
|
<meta content="Tony Wolski" property="og:site_name"> |
|
<meta content="article" property="og:type"> |
|
<meta content="summary" property="twitter:card"> |
|
<title> |
|
Running Liquibase against and existing database using LiquibaseServletListener | Tony Wolski |
|
</title> |
|
<meta content="I recently took on the task of integrating Liquibase into the project I’m working on at work. I’d played around with Liquibase before on small …" name="description"> |
|
<meta content="Tony Wolski" name="author"> |
|
<meta content="IE=edge" http-equiv="x-ua-compatible"> |
|
<meta content="no-referrer" name="referrer"> |
|
</head> |
|
<body> |
|
<header id="masthead"> |
|
<h1> |
|
<a title="Tony Wolski"> |
|
Tony Wolski |
|
</a> |
|
</h1> |
|
</header> |
|
<main> |
|
<article class="post"> |
|
<header> |
|
<h1> |
|
Running Liquibase against and existing database using LiquibaseServletListener |
|
</h1> |
|
<small> |
|
2013-10-14 |
|
</small> |
|
</header> |
|
<p> |
|
I recently took on the task of integrating |
|
<a> |
|
Liquibase |
|
</a> |
|
into the project I’m working on at work. I’d played around with Liquibase before on small personal projects, but had never faced applying it to an existing, large and in-production database. |
|
</p> |
|
<p> |
|
I ran into a few problems when using the LiquibaseServletListener after having previously run changelogSync via the command line. Basically, Liquibase was trying to execute the changesets in my changelog files even though they had already been executed during changelogSync. |
|
</p> |
|
<p> |
|
I had executed Liquibase’s changelogSync from the command line in the same directory as the file generated by generateChangeLog, something along these lines: |
|
</p> |
|
<div class="highlight"> |
|
<pre class="chroma"><code class="language-shell" data-lang="shell">liquibase --driver<span class="o">=</span>com.mysql.jdbc.Driver <span class="se">\ |
|
</span><span class="se"></span> --classpath<span class="o">=</span>mysql-connector-java-5.1.13-bin.jar <span class="se">\ |
|
</span><span class="se"></span> --changeLogFile<span class="o">=</span>accounts-changelog-schema.xml <span class="se">\ |
|
</span><span class="se"></span> --url<span class="o">=</span><span class="s2">"jdbc:mysql://localhost:3306/accounts"</span> <span class="se">\ |
|
</span><span class="se"></span> --username<span class="o">=</span>user --password<span class="o">=</span>password changelogSync |
|
</code></pre> |
|
</div> |
|
<p> |
|
Afterwards, the rows in Liquibase’s DATABASECHANGELOG table indicated everything had worked, and each of the changesets had an EXECTYPE of EXECUTED, which should have meant when the servlet listener started up the changesets would be skipped over. But Liquibase was trying to execute the changesets and I was getting a log full of errors. |
|
</p> |
|
<p> |
|
Turns out that because I had defined my changelog file in a subdirectory: |
|
</p> |
|
<div class="highlight"> |
|
<pre class="chroma"><code class="language-xml" data-lang="xml"><span class="nt"><context-param></span> |
|
<span class="nt"><param-name></span>liquibase.changelog<span class="nt"></param-name></span> |
|
<span class="nt"><param-value></span>db/changelog/accounts-changelog-schema.xml<span class="nt"></param-value></span> |
|
<span class="nt"></context-param></span> |
|
</code></pre> |
|
</div> |
|
<p> |
|
And had run changelogSync from the same directory as the generated changelog (which meant the FILENAME field for each changeset was ‘accounts-changelog-schema.xml’), the FILENAME field didn’t match. Hence Liquibase’s attempts to re-run the changesets. |
|
</p> |
|
<p> |
|
Fixing the problem was simply a matter of updating the database |
|
</p> |
|
<div class="highlight"> |
|
<pre class="chroma"><code class="language-sql" data-lang="sql"><span class="k">update</span> <span class="n">DATABASASECHANGELOG</span> <span class="k">set</span> <span class="n">FILENAME</span> <span class="o">=</span> <span class="s1">'db/changelog/accounts-changelog-schema.xml'</span><span class="p">;</span> |
|
</code></pre> |
|
</div> |
|
<footer> |
|
« |
|
<a> |
|
Previous |
|
</a> |
|
|| |
|
<a> |
|
Next |
|
</a> |
|
» |
|
</footer> |
|
<br> |
|
<p> |
|
<strong> |
|
Your thoughts? |
|
</strong> |
|
I'd love to hear them. Please get in |
|
<a> |
|
contact |
|
</a> |
|
. |
|
</p> |
|
</article> |
|
</main> |
|
<footer id="mastfoot"> |
|
<nav> |
|
<a title="Contact"> |
|
Contact |
|
</a> |
|
</nav> |
|
</footer> |
|
</body> |
|
</html> |
|
|