Hi, I’m using the liquibase maven plugin 2.0.2. Everything seems to work as advertised, except for unexpected behavior with tagging the database.
Let’s say I have three changelog xml files, and each one contains a with a single tagDatabase tag. Each tagDatabase tag is specified with tag=“1.1”, tag=“1.2”, tag=“1.3”. I run them all in sequence with mvn liquibase:update, and then inspect the database. I’d expect to see three rows in the databasechangelog table, each with a different tag. Instead what I see is three rows with id/author/etc as expected, but they ALL have a tag of 1.3, not one with 1.1, one with 1.2, and one with 1.3.
How can I specify a different tag for each changelog file so that sets of changes can be tagged and rolled back?
Thanks,
Jason
So you have just a changelog with commands in it? Or are there other change tags in there as well? If tag commands get executed too quickly in succession it can sometimes be difficult to tell the single most recent changeset to tag. There was some attempts to improve it with 2.x with the orderexecuted tag, however. What database are you using? Nathan
I have been able to partially re-create this using MySQL Here’s the main change log <?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-2.0.xsd ”> tagDB1.xml (tagDB2.xml and tagDB3.xml - are similar except the id and tag are different values. --------------- <?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-2.0.xsd ”> Here’s the debug log level messages
DEBUG 10/25/11 10:27 PM:liquibase: Connected to root@localhost@jdbc:mysql://localhost:3306/test DEBUG 10/25/11 10:27 PM:liquibase: Executing QUERY database command: SELECT LOCKED
FROM DATABASECHANGELOGLOCK
WHERE ID
=1 DEBUG 10/25/11 10:27 PM:liquibase: Lock Database DEBUG 10/25/11 10:27 PM:liquibase: Executing UPDATE database command: UPDATE DATABASECHANGELOGLOCK
SET LOCKED
= 1, LOCKEDBY
= ‘texas (192.168.1.105)’, LOCKGRANTED
= ‘2011-10-25 22:27:49.671’ WHERE ID
= 1 AND LOCKED
= 0 INFO 10/25/11 10:27 PM:liquibase: Successfully acquired change log lock DEBUG 10/25/11 10:27 PM:liquibase: Executing QUERY database command: SELECT MD5SUM FROM DATABASECHANGELOG
WHERE MD5SUM IS NOT NULL INFO 10/25/11 10:27 PM:liquibase: Reading from DATABASECHANGELOG
DEBUG 10/25/11 10:27 PM:liquibase: Executing QUERY database command: SELECT FILENAME,AUTHOR,ID,MD5SUM,DATEEXECUTED,ORDEREXECUTED,TAG,EXECTYPE FROM DATABASECHANGELOG
ORDER BY DATEEXECUTED ASC, ORDEREXECUTED ASC INFO 10/25/11 10:27 PM:liquibase: Reading from DATABASECHANGELOG
DEBUG 10/25/11 10:27 PM:liquibase: Executing QUERY database command: SELECT FILENAME,AUTHOR,ID,MD5SUM,DATEEXECUTED,ORDEREXECUTED,TAG,EXECTYPE FROM DATABASECHANGELOG
ORDER BY DATEEXECUTED ASC, ORDEREXECUTED ASC DEBUG 10/25/11 10:27 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.1” ] as d4c909b8353005cecbd0e8ed4230f9cd DEBUG 10/25/11 10:27 PM:liquibase: Computed checksum for 3:d4c909b8353005cecbd0e8ed4230f9cd: as 3c71dc51ad47d7809e4aadb9ba55849d DEBUG 10/25/11 10:27 PM:liquibase: Running Changeset:D:/eclipseworkspace/workspace/LiquibaseTest/tagDB1.xml::1315971950477-71::mmiller (generated)::(Checksum: 3:3c71dc51ad47d7809e4aadb9ba55849d) DEBUG 10/25/11 10:27 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.1” ] as d4c909b8353005cecbd0e8ed4230f9cd DEBUG 10/25/11 10:27 PM:liquibase: Computed checksum for 3:d4c909b8353005cecbd0e8ed4230f9cd: as 3c71dc51ad47d7809e4aadb9ba55849d DEBUG 10/25/11 10:27 PM:liquibase: Changeset D:/eclipseworkspace/workspace/LiquibaseTest/tagDB1.xml::1315971950477-71::mmiller (generated)::(Checksum: 3:3c71dc51ad47d7809e4aadb9ba55849d) DEBUG 10/25/11 10:27 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.1” ] as d4c909b8353005cecbd0e8ed4230f9cd DEBUG 10/25/11 10:27 PM:liquibase: Computed checksum for 3:d4c909b8353005cecbd0e8ed4230f9cd: as 3c71dc51ad47d7809e4aadb9ba55849d DEBUG 10/25/11 10:27 PM:liquibase: Reading ChangeSet: D:/eclipseworkspace/workspace/LiquibaseTest/tagDB1.xml::1315971950477-71::mmiller (generated)::(Checksum: 3:3c71dc51ad47d7809e4aadb9ba55849d) DEBUG 10/25/11 10:27 PM:liquibase: Executing Statement: liquibase.statement.core.TagDatabaseStatement@8201a7 DEBUG 10/25/11 10:27 PM:liquibase: Executing EXECUTE database command: UPDATE DATABASECHANGELOG
SET TAG
= ‘2.1’ WHERE DATEEXECUTED = (SELECT MAX(DATEEXECUTED) FROM (SELECT DATEEXECUTED FROM DATABASECHANGELOG
) AS X) DEBUG 10/25/11 10:27 PM:liquibase: Tag ‘2.1’ applied to database INFO 10/25/11 10:27 PM:liquibase: ChangeSet D:/eclipseworkspace/workspace/LiquibaseTest/tagDB1.xml::1315971950477-71::mmiller (generated) ran successfully in 46ms DEBUG 10/25/11 10:27 PM:liquibase: Executing QUERY database command: SELECT MAX(ORDEREXECUTED) FROM DATABASECHANGELOG
DEBUG 10/25/11 10:27 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.1” ] as d4c909b8353005cecbd0e8ed4230f9cd DEBUG 10/25/11 10:27 PM:liquibase: Computed checksum for 3:d4c909b8353005cecbd0e8ed4230f9cd: as 3c71dc51ad47d7809e4aadb9ba55849d DEBUG 10/25/11 10:28 PM:liquibase: Executing EXECUTE database command: INSERT INTO DATABASECHANGELOG
(AUTHOR
, COMMENTS
, DATEEXECUTED
, DESCRIPTION
, EXECTYPE
, FILENAME
, ID
, LIQUIBASE
, MD5SUM
, ORDEREXECUTED
, TAG
) VALUES (‘mmiller (generated)’, ‘’, NOW(), ‘Tag Database’, ‘EXECUTED’, ‘D:/eclipseworkspace/workspace/LiquibaseTest/tagDB1.xml’, ‘1315971950477-71’, ‘2.0.2-SNP’, ‘3:3c71dc51ad47d7809e4aadb9ba55849d’, 7, ‘2.1’) DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.1” ] as d4c909b8353005cecbd0e8ed4230f9cd DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:d4c909b8353005cecbd0e8ed4230f9cd: as 3c71dc51ad47d7809e4aadb9ba55849d DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“1.2” ] as 7974c72512547bfa3378e2de3337be5b DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:7974c72512547bfa3378e2de3337be5b: as 8cc9fd308853023cf952017be45d7a30 DEBUG 10/25/11 10:28 PM:liquibase: Running Changeset:D:/eclipseworkspace/workspace/LiquibaseTest/tagDB2.xml::1315971950477-72::mmiller (generated)::(Checksum: 3:8cc9fd308853023cf952017be45d7a30) DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“1.2” ] as 7974c72512547bfa3378e2de3337be5b DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:7974c72512547bfa3378e2de3337be5b: as 8cc9fd308853023cf952017be45d7a30 DEBUG 10/25/11 10:28 PM:liquibase: Changeset D:/eclipseworkspace/workspace/LiquibaseTest/tagDB2.xml::1315971950477-72::mmiller (generated)::(Checksum: 3:8cc9fd308853023cf952017be45d7a30) DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“1.2” ] as 7974c72512547bfa3378e2de3337be5b DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:7974c72512547bfa3378e2de3337be5b: as 8cc9fd308853023cf952017be45d7a30 DEBUG 10/25/11 10:28 PM:liquibase: Reading ChangeSet: D:/eclipseworkspace/workspace/LiquibaseTest/tagDB2.xml::1315971950477-72::mmiller (generated)::(Checksum: 3:8cc9fd308853023cf952017be45d7a30) DEBUG 10/25/11 10:28 PM:liquibase: Executing Statement: liquibase.statement.core.TagDatabaseStatement@109dcbb DEBUG 10/25/11 10:28 PM:liquibase: Executing EXECUTE database command: UPDATE DATABASECHANGELOG
SET TAG
= ‘1.2’ WHERE DATEEXECUTED = (SELECT MAX(DATEEXECUTED) FROM (SELECT DATEEXECUTED FROM DATABASECHANGELOG
) AS X) DEBUG 10/25/11 10:28 PM:liquibase: Tag ‘1.2’ applied to database INFO 10/25/11 10:28 PM:liquibase: ChangeSet D:/eclipseworkspace/workspace/LiquibaseTest/tagDB2.xml::1315971950477-72::mmiller (generated) ran successfully in 47ms DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“1.2” ] as 7974c72512547bfa3378e2de3337be5b DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:7974c72512547bfa3378e2de3337be5b: as 8cc9fd308853023cf952017be45d7a30 DEBUG 10/25/11 10:28 PM:liquibase: Executing EXECUTE database command: INSERT INTO DATABASECHANGELOG
(AUTHOR
, COMMENTS
, DATEEXECUTED
, DESCRIPTION
, EXECTYPE
, FILENAME
, ID
, LIQUIBASE
, MD5SUM
, ORDEREXECUTED
, TAG
) VALUES (‘mmiller (generated)’, ‘’, NOW(), ‘Tag Database’, ‘EXECUTED’, ‘D:/eclipseworkspace/workspace/LiquibaseTest/tagDB2.xml’, ‘1315971950477-72’, ‘2.0.2-SNP’, ‘3:8cc9fd308853023cf952017be45d7a30’, 8, ‘1.2’) DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“1.2” ] as 7974c72512547bfa3378e2de3337be5b DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:7974c72512547bfa3378e2de3337be5b: as 8cc9fd308853023cf952017be45d7a30 DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.3” ] as ce0383aa86749e0a66178ed7b1266126 DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:ce0383aa86749e0a66178ed7b1266126: as 11cb9cfa85f6f563fa740860e685c0ed DEBUG 10/25/11 10:28 PM:liquibase: Running Changeset:D:/eclipseworkspace/workspace/LiquibaseTest/tagDB3.xml::1315971950477-73::mmiller (generated)::(Checksum: 3:11cb9cfa85f6f563fa740860e685c0ed) DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.3” ] as ce0383aa86749e0a66178ed7b1266126 DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:ce0383aa86749e0a66178ed7b1266126: as 11cb9cfa85f6f563fa740860e685c0ed DEBUG 10/25/11 10:28 PM:liquibase: Changeset D:/eclipseworkspace/workspace/LiquibaseTest/tagDB3.xml::1315971950477-73::mmiller (generated)::(Checksum: 3:11cb9cfa85f6f563fa740860e685c0ed) DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.3” ] as ce0383aa86749e0a66178ed7b1266126 DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:ce0383aa86749e0a66178ed7b1266126: as 11cb9cfa85f6f563fa740860e685c0ed DEBUG 10/25/11 10:28 PM:liquibase: Reading ChangeSet: D:/eclipseworkspace/workspace/LiquibaseTest/tagDB3.xml::1315971950477-73::mmiller (generated)::(Checksum: 3:11cb9cfa85f6f563fa740860e685c0ed) DEBUG 10/25/11 10:28 PM:liquibase: Executing Statement: liquibase.statement.core.TagDatabaseStatement@11e7cc6 DEBUG 10/25/11 10:28 PM:liquibase: Executing EXECUTE database command: UPDATE DATABASECHANGELOG
SET TAG
= ‘2.3’ WHERE DATEEXECUTED = (SELECT MAX(DATEEXECUTED) FROM (SELECT DATEEXECUTED FROM DATABASECHANGELOG
) AS X) DEBUG 10/25/11 10:28 PM:liquibase: Tag ‘2.3’ applied to database INFO 10/25/11 10:28 PM:liquibase: ChangeSet D:/eclipseworkspace/workspace/LiquibaseTest/tagDB3.xml::1315971950477-73::mmiller (generated) ran successfully in 47ms DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.3” ] as ce0383aa86749e0a66178ed7b1266126 DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:ce0383aa86749e0a66178ed7b1266126: as 11cb9cfa85f6f563fa740860e685c0ed DEBUG 10/25/11 10:28 PM:liquibase: Executing EXECUTE database command: INSERT INTO DATABASECHANGELOG
(AUTHOR
, COMMENTS
, DATEEXECUTED
, DESCRIPTION
, EXECTYPE
, FILENAME
, ID
, LIQUIBASE
, MD5SUM
, ORDEREXECUTED
, TAG
) VALUES (‘mmiller (generated)’, ‘’, NOW(), ‘Tag Database’, ‘EXECUTED’, ‘D:/eclipseworkspace/workspace/LiquibaseTest/tagDB3.xml’, ‘1315971950477-73’, ‘2.0.2-SNP’, ‘3:11cb9cfa85f6f563fa740860e685c0ed’, 9, ‘2.3’) DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for tagDatabase:[ tag=“2.3” ] as ce0383aa86749e0a66178ed7b1266126 DEBUG 10/25/11 10:28 PM:liquibase: Computed checksum for 3:ce0383aa86749e0a66178ed7b1266126: as 11cb9cfa85f6f563fa740860e685c0ed DEBUG 10/25/11 10:28 PM:liquibase: Release Database Lock DEBUG 10/25/11 10:28 PM:liquibase: Executing UPDATE database command: UPDATE DATABASECHANGELOGLOCK
SET LOCKED
= 0, LOCKEDBY
= NULL, LOCKGRANTED
= NULL WHERE ID
= 1 INFO 10/25/11 10:28 PM:liquibase: Successfully released change log lock Liquibase Update Successful
In my small test case, I think the problem comes from the following statement UPDATE DATABASECHANGELOG
SET TAG
= ‘2.3’ WHERE DATEEXECUTED = (SELECT MAX(DATEEXECUTED) FROM (SELECT DATEEXECUTED FROM DATABASECHANGELOG
) AS X) because my date_executed column has the same value for all three rows, thus the all get tagged as 2.3. Using the debugger to space out the updates in time, I still get the last two change log entries tagged with ‘2.3’.
Guest
October 26, 2011, 4:05am
5
I’m getting it set up to use with an existing database, so my intent is to have one changelog with one tag command in it to tag the initial state, and subsequent changelogs with other commands (changesets) but each ending with a tag changeset. I’ve tried this with and without other changesets along with the tags. I’m using MySQL.
So there’s an “orderexecuted” tag I can use? Would that ensure that the tags are correctly inserted? Or if this is really problematic should I only run one changeset/tag per mvn liquibase:update? I’d kindof expect to be able to take an initial schema and run liquibase:update on it and have an arbitrary number of files/changesets and tags applied though.