Skip to content

Commit

Permalink
move changes since version 2.0.x from liquibase-update-to-latest.xml …
Browse files Browse the repository at this point in the history
…to liquibase-update-2.1.xml
  • Loading branch information
WolfSchlegel committed Oct 11, 2016
1 parent 1f3727b commit 29882a5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 7 deletions.
12 changes: 6 additions & 6 deletions api/src/main/java/org/openmrs/util/DatabaseUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
/**
* This class uses Liquibase to update the database. <br>
* <br>
* See /metadata/model/liquibase-update-to-latest.xml for the changes. This class will also run
* See src/main/resources/liquibase-master.xml for the changes. This class will also run
* arbitrary liquibase xml files on the associated database as well. Details for the database are
* taken from the openmrs runtime properties.
*
Expand All @@ -68,7 +68,7 @@ public class DatabaseUpdater {

private static final Log log = LogFactory.getLog(DatabaseUpdater.class);

private static final String CHANGE_LOG_FILE = "liquibase-update-to-latest.xml";
private static final String CHANGE_LOG_FILE = "liquibase-master.xml";

private static final String CONTEXT = "core";

Expand Down Expand Up @@ -421,7 +421,7 @@ public static Connection getConnection() throws Exception {
}

/**
* Represents each change in the liquibase-update-to-latest
* Represents each change in the files referenced by liquibase-master
*/
public static class OpenMRSChangeSet {

Expand Down Expand Up @@ -539,7 +539,7 @@ public void setId(String id) {
}

/**
* Looks at the current liquibase-update-to-latest.xml file and then checks the database to see
* Looks at the current liquibase-master.xml file and then checks the database to see
* if they have been run.
*
* @return list of changesets that both have and haven't been run
Expand Down Expand Up @@ -586,7 +586,7 @@ public static List<OpenMRSChangeSet> getUnrunDatabaseChanges() throws Exception
/**
* Looks at the specified liquibase change log files and returns all changesets in the files
* that have not been run on the database yet. If no argument is specified, then it looks at the
* current liquibase-update-to-latest.xml file
* current liquibase-master.xml file
*
* @param changeLogFilenames the filenames of all files to search for unrun changesets
* @return list of change sets
Expand All @@ -602,7 +602,7 @@ public static List<OpenMRSChangeSet> getUnrunDatabaseChanges(String... changeLog
throw new IllegalArgumentException("changeLogFilenames cannot be null");
}

//if no argument, look ONLY in liquibase-update-to-latest.xml
//if no argument, look ONLY in liquibase-master.xml
if (changeLogFilenames.length == 0) {
changeLogFilenames = new String[] { CHANGE_LOG_FILE };
}
Expand Down
21 changes: 21 additions & 0 deletions api/src/main/resources/liquibase-master.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.
-->
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

<include file="liquibase-update-baseline.xml"/>
<include file="liquibase-update-to-latest.xml"/>
</databaseChangeLog>
28 changes: 28 additions & 0 deletions api/src/main/resources/liquibase-update-update-to-latest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.
-->
<!--
This file contains all changesets that have been introduced on top of the baseline exclusively.
If you intend for a changeset to be backported to older releases, you must put such a changeset in the
liquibase-update-baseline.xml, which have been used for older releases.
-->
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

<!--
See http://www.liquibase.org/manual/home#available_database_refactorings
for a list of supported elements and attributes
-->

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,12 @@ private boolean roleHasPrivilege(String role, String privilege) {
final String query = "select * from role_privilege where role='" + role + "' and privilege ='" + privilege + "'";
return DatabaseUtil.executeSQL(upgradeTestUtil.getConnection(), query, true).size() == 1;
}

@Test
public void shouldUpgradeLiquibase() throws IOException, SQLException {
upgradeTestUtil.upgrade("liquibase-master.xml");

// no explicit assertions here, this test serves to see whether the master is executed without raising an exception.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,12 @@ public void insertGlobalProperty(String globalProperty, String value) throws SQL
}

public void upgrade() throws IOException, SQLException {
upgrade("liquibase-master.xml");
}

public void upgrade(String filename) throws IOException, SQLException {
try {
Liquibase liquibase = new Liquibase("liquibase-update-to-latest.xml", new ClassLoaderResourceAccessor(getClass()
Liquibase liquibase = new Liquibase(filename, new ClassLoaderResourceAccessor(getClass()
.getClassLoader()), liqubaseConnection);
liquibase.update(null);

Expand Down

0 comments on commit 29882a5

Please sign in to comment.