Author: cbegin Date: Mon Aug 25 20:57:52 2008 New Revision: 688954 URL: http://svn.apache.org/viewvc?rev=688954&view=rev Log: implemented dynamic changelog table name
Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_changelog.sql ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_environment.properties Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java?rev=688954&r1=688953&r2=688954&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java Mon Aug 25 20:57:52 2008 @@ -52,7 +52,7 @@ protected List<Change> getChangelog() { AdHocExecutor executor = getAdHocExecutor(); try { - List<Map<String, Object>> changelog = executor.selectAll("select ID, APPLIED_AT, DESCRIPTION from CHANGELOG order by id"); + List<Map<String, Object>> changelog = executor.selectAll("select ID, APPLIED_AT, DESCRIPTION from "+changelogTable()+" order by id"); List<Change> changes = new ArrayList<Change>(); for (Map<String, Object> change : changelog) { String id = change.get("ID") == null ? null : change.get("ID").toString(); @@ -68,6 +68,14 @@ } } + protected String changelogTable() { + String changelog = environmentProperties().getProperty("changelog"); + if (changelog == null) { + changelog = "CHANGELOG"; + } + return changelog; + } + protected Change getLastAppliedChange() { List<Change> changelog = getChangelog(); return changelog.get(changelog.size() - 1); @@ -76,7 +84,7 @@ protected boolean changelogExists() { AdHocExecutor executor = getAdHocExecutor(); try { - executor.selectAll("select ID, DESCRIPTION from CHANGELOG"); + executor.selectAll("select ID, APPLIED_AT, DESCRIPTION from " + changelogTable()); return true; } catch (SQLException e) { return false; @@ -138,7 +146,7 @@ protected AdHocExecutor getAdHocExecutor() { lazyInitializeDrivers(); - Properties props = getEnvironmentProperties(); + Properties props = environmentProperties(); String driver = props.getProperty("driver"); String url = props.getProperty("url"); String username = props.getProperty("username"); @@ -150,7 +158,7 @@ try { lazyInitializeDrivers(); - Properties props = getEnvironmentProperties(); + Properties props = environmentProperties(); String driver = props.getProperty("driver"); String url = props.getProperty("url"); String username = props.getProperty("username"); @@ -214,7 +222,7 @@ } } - protected Properties getEnvironmentProperties() { + protected Properties environmentProperties() { try { File file = existingEnvironmentFile(); Properties props = new Properties(); Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java?rev=688954&r1=688953&r2=688954&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/BootstrapCommand.java Mon Aug 25 20:57:52 2008 @@ -19,7 +19,7 @@ if (bootstrap.exists()) { out.println(horizontalLine("Applying: bootstrap.sql", 80)); ScriptRunner runner = getScriptRunner(); - runner.runScript(new MigrationReader(new FileReader(bootstrap), false, getEnvironmentProperties())); + runner.runScript(new MigrationReader(new FileReader(bootstrap), false, environmentProperties())); } else { out.println("Error, could not run bootstrap.sql. The file does not exist."); } Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java?rev=688954&r1=688953&r2=688954&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/DownCommand.java Mon Aug 25 20:57:52 2008 @@ -22,7 +22,7 @@ if (change.getId().equals(lastChange.getId())) { out.println(horizontalLine("Undoing: " + change.getFilename(), 80)); ScriptRunner runner = getScriptRunner(); - runner.runScript(new MigrationReader(new FileReader(scriptFile(change.getFilename())), true, getEnvironmentProperties())); + runner.runScript(new MigrationReader(new FileReader(scriptFile(change.getFilename())), true, environmentProperties())); if (changelogExists()) { deleteChange(change); } else { @@ -39,7 +39,7 @@ protected void deleteChange(Change change) { AdHocExecutor executor = getAdHocExecutor(); try { - executor.delete("delete from CHANGELOG where id = ?", change.getId()); + executor.delete("delete from " + changelogTable() + " where id = ?", change.getId()); } catch (SQLException e) { throw new MigrationException("Error querying last applied migration. Cause: " + e, e); } finally { Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java?rev=688954&r1=688953&r2=688954&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/StatusCommand.java Mon Aug 25 20:57:52 2008 @@ -13,7 +13,7 @@ public void execute(String... params) { out.println("ID Applied At Description"); - out.println(horizontalLine("", 60)); + out.println(horizontalLine("", 80)); List<Change> merged = new ArrayList<Change>(); List<Change> migrations = getMigrations(); if (changelogExists()) { Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java?rev=688954&r1=688953&r2=688954&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/commands/UpCommand.java Mon Aug 25 20:57:52 2008 @@ -32,7 +32,7 @@ if (lastChange == null || change.getId().compareTo(lastChange.getId()) > 0) { out.println(horizontalLine("Applying: " + change.getFilename(), 80)); ScriptRunner runner = getScriptRunner(); - runner.runScript(new MigrationReader(new FileReader(scriptFile(change.getFilename())), false, getEnvironmentProperties())); + runner.runScript(new MigrationReader(new FileReader(scriptFile(change.getFilename())), false, environmentProperties())); insertChangelog(change); if (runOneStepOnly) { break; @@ -48,7 +48,7 @@ AdHocExecutor executor = getAdHocExecutor(); change.setAppliedTimestamp(getAppliedTimestampAsString()); try { - executor.insert("insert into CHANGELOG (ID, APPLIED_AT, DESCRIPTION) values (?,?,?)", change.getId(), change.getAppliedTimestamp(), change.getDescription()); + executor.insert("insert into " + changelogTable() + " (ID, APPLIED_AT, DESCRIPTION) values (?,?,?)", change.getId(), change.getAppliedTimestamp(), change.getDescription()); } catch (SQLException e) { throw new MigrationException("Error querying last applied migration. Cause: " + e, e); } finally { Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_changelog.sql URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_changelog.sql?rev=688954&r1=688953&r2=688954&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_changelog.sql (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_changelog.sql Mon Aug 25 20:57:52 2008 @@ -9,16 +9,16 @@ -- Be sure that ID and DESCRIPTION fields exist in -- BigInteger and String compatible fields respectively. -CREATE TABLE CHANGELOG ( +CREATE TABLE ${changelog} ( ID NUMERIC(20,0) NOT NULL, APPLIED_AT VARCHAR(25) NOT NULL, DESCRIPTION VARCHAR(255) NOT NULL ); -ALTER TABLE CHANGELOG - ADD CONSTRAINT PK_CHANGELOG +ALTER TABLE ${changelog} + ADD CONSTRAINT PK_${changelog} PRIMARY KEY (id); --//@UNDO -DROP TABLE CHANGELOG; \ No newline at end of file +DROP TABLE ${changelog}; \ No newline at end of file Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_environment.properties URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_environment.properties?rev=688954&r1=688953&r2=688954&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_environment.properties (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/migration/template_environment.properties Mon Aug 25 20:57:52 2008 @@ -3,3 +3,6 @@ url= username= password= + +# Name of the table that tracks changes to the database +changelog=CHANGELOG \ No newline at end of file