package liquibase.change.ext;

import liquibase.change.ChangeMetaData;
import liquibase.change.DatabaseChange;
import liquibase.change.core.DropNotNullConstraintChange;
import liquibase.database.Database;
import liquibase.database.ext.HanaDBDatabase;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.SetNullableStatement;

@DatabaseChange(name="dropNotNullConstraint", description = "Makes a column nullable", priority = ChangeMetaData.PRIORITY_DATABASE, appliesTo = "column", since = "3.0")
public class DropNotNullConstraintChangeHana extends
		DropNotNullConstraintChange {

	@Override
	public boolean supports(Database database) {
		return database instanceof HanaDBDatabase;
	}

	@Override
	public SqlStatement[] generateStatements(Database database) {
    	if (getSchemaName() == null) {
    		setSchemaName(database.getDefaultSchemaName());
    	}
    	String columnDataTypeName = getColumnDataType();
    	if (columnDataTypeName == null && getSchemaName() != null && database instanceof HanaDBDatabase) {
    		columnDataTypeName = ((HanaDBDatabase) database).getColumnDataTypeName(getCatalogName(), getSchemaName(), getTableName(), getColumnName());
		}
    	
    	return new SqlStatement[] { new SetNullableStatement(
                getCatalogName(),
    			getSchemaName(),
    			getTableName(), getColumnName(), columnDataTypeName, true) 
    	};

	}

}

@@ -779,32 +779,213 @@
 ) %7B%0A
-    %09if (getSchemaName()
+%09%09// local variable introduced as superclass's schemaName is used for checksum calculation%0A%09%09// TODO: is this logic also needed for the inverse?%0A%09%09String schemaToUse = getSchemaName();%0A    %09if (schemaToUse
  == 
@@ -999,29 +999,29 @@
 %0A    %09%09s
-etS
 chema
-Name(
+ToUse = 
 database
@@ -1043,17 +1043,16 @@
 maName()
-)
 ;%0A    %09%7D
@@ -1145,31 +1145,27 @@
 null && 
-getS
+s
 chema
-Name()
+ToUse
  != null
@@ -1301,31 +1301,27 @@
 Name(), 
-getS
+s
 chema
-Name()
+ToUse
 , getTab
@@ -1458,31 +1458,27 @@
 %0A    %09%09%09
-getS
+s
 chema
-Name()
+ToUse
 ,%0A    %09%09

Fix checksum failure when reexecuting changesets with dropNotNullConstraint