Skip to content

Commit

Permalink
DAT-220 Mods to the standard services for DATABASECHANGELOG and DATAB…
Browse files Browse the repository at this point in the history
…ASECHANGELOGLOCK

tables to allow them to be removed on DB2z
  • Loading branch information
wwillard7800 committed May 17, 2018
1 parent b10ef2d commit 7fa3d53
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import liquibase.Contexts;
import liquibase.LabelExpression;
import liquibase.Labels;
import liquibase.change.Change;
import liquibase.change.CheckSum;
import liquibase.change.ColumnConfig;
import liquibase.database.Database;
import liquibase.database.core.MSSQLDatabase;
import liquibase.database.core.DB2Database;
import liquibase.database.core.MSSQLDatabase;
import liquibase.database.core.SQLiteDatabase;
import liquibase.datatype.core.VarcharType;
import liquibase.diff.output.DiffOutputControl;
import liquibase.diff.output.changelog.ChangeGeneratorFactory;
import liquibase.exception.DatabaseException;
import liquibase.exception.DatabaseHistoryException;
import liquibase.exception.LiquibaseException;
Expand All @@ -24,6 +26,7 @@
import liquibase.sqlgenerator.SqlGeneratorFactory;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.*;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.Column;
import liquibase.structure.core.DataType;
import liquibase.structure.core.Table;
Expand Down Expand Up @@ -63,7 +66,7 @@ public String getLiquibaseCatalogName() {
return getDatabase().getLiquibaseCatalogName();
}

public boolean canCreateChangeLogTable() throws DatabaseException {
public boolean canCreateChangeLogTable() {
return true;
}

Expand All @@ -73,7 +76,7 @@ public void reset() {
this.hasDatabaseChangeLogTable = null;
}

public boolean hasDatabaseChangeLogTable() throws DatabaseException {
public boolean hasDatabaseChangeLogTable() {
if (hasDatabaseChangeLogTable == null) {
try {
hasDatabaseChangeLogTable = SnapshotGeneratorFactory.getInstance().hasDatabaseChangeLogTable(getDatabase());
Expand Down Expand Up @@ -415,8 +418,14 @@ public void clearAllCheckSums() throws LiquibaseException {
public void destroy() throws DatabaseException {
Database database = getDatabase();
try {
if (SnapshotGeneratorFactory.getInstance().has(new Table().setName(database.getDatabaseChangeLogTableName()).setSchema(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName()), database)) {
ExecutorService.getInstance().getExecutor(database).execute(new DropTableStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName(), false));
DatabaseObject example =
new Table().setName(database.getDatabaseChangeLogTableName()).setSchema(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName());
if (SnapshotGeneratorFactory.getInstance().has(example, database)) {
DatabaseObject table = SnapshotGeneratorFactory.getInstance().createSnapshot(example, database);
DiffOutputControl diffOutputControl = new DiffOutputControl(true, true, false, null);
Change[] change = ChangeGeneratorFactory.getInstance().fixUnexpected(table, diffOutputControl, database, database);
SqlStatement[] sqlStatement = change[0].generateStatements(database);
ExecutorService.getInstance().getExecutor(database).execute(sqlStatement[0]);
}
reset();
} catch (InvalidExampleException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package liquibase.lockservice;

import liquibase.change.Change;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.database.ObjectQuotingStrategy;
import liquibase.database.core.DerbyDatabase;
import liquibase.database.core.MSSQLDatabase;
import liquibase.diff.output.DiffOutputControl;
import liquibase.diff.output.changelog.ChangeGeneratorFactory;
import liquibase.exception.DatabaseException;
import liquibase.exception.LiquibaseException;
import liquibase.exception.LockException;
Expand All @@ -19,6 +22,7 @@
import liquibase.sqlgenerator.SqlGeneratorFactory;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.*;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.Table;

import java.text.DateFormat;
Expand Down Expand Up @@ -348,9 +352,14 @@ public void reset() {
@Override
public void destroy() throws DatabaseException {
try {
if (SnapshotGeneratorFactory.getInstance().has(new Table().setName(database.getDatabaseChangeLogLockTableName()).setSchema(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName()), database)) {
ExecutorService.getInstance().getExecutor(database).execute(new DropTableStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogLockTableName(), false));
hasDatabaseChangeLogLockTable = null;
DatabaseObject example =
new Table().setName(database.getDatabaseChangeLogLockTableName()).setSchema(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName());
if (SnapshotGeneratorFactory.getInstance().has(example, database)) {
DatabaseObject table = SnapshotGeneratorFactory.getInstance().createSnapshot(example, database);
DiffOutputControl diffOutputControl = new DiffOutputControl(true, true, false, null);
Change[] change = ChangeGeneratorFactory.getInstance().fixUnexpected(table, diffOutputControl, database, database);
SqlStatement[] sqlStatement = change[0].generateStatements(database);
ExecutorService.getInstance().getExecutor(database).execute(sqlStatement[0]);
}
reset();
} catch (InvalidExampleException e) {
Expand Down

0 comments on commit 7fa3d53

Please sign in to comment.