Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backwards compatibility for procedureBody in createProcedureChange #5583

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,27 @@
assertEquals(tableList.size(), 1);
assertEquals(tableList.iterator().next().getName(), "permissiondeniedtable");
}

@Test
public void runYamlChangelog() throws Exception {
if (getDatabase() == null) {
return;
}

Liquibase liquibase = createLiquibase(completeChangeLog);
clearDatabase();

//run again to test changelog testing logic
liquibase = createLiquibase("changelogs/yaml/create.procedure.back.compatibility.changelog.yaml");
liquibase.setChangeLogParameter("loginuser", testSystem.getUsername());

try {
liquibase.update(this.contexts);
Dismissed Show dismissed Hide dismissed
} catch (ValidationFailedException e) {
e.printDescriptiveError(System.out);
throw e;
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
databaseChangeLog:
- changeSet:
id: 1
author: user
dbms: postgresql
changes:
- createProcedure:
procedureBody: |-
CREATE OR REPLACE PROCEDURE testHello()
LANGUAGE plpgsql
AS $$
BEGIN
raise notice 'this is test';
END $$
procedureName: MyProc
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ private ChangeParameterMetaData createChangeParameterMetadata(PropertyDescriptor
);
String[] requiredForDatabase = createRequiredDatabasesMetaData(parameterName, changePropertyAnnotation);
String[] supportsDatabase = createSupportedDatabasesMetaData(parameterName, changePropertyAnnotation);
String[] alternatePropertyNames = createAlternateParameterNames(changePropertyAnnotation);

return new ChangeParameterMetaData(this, parameterName, displayName, description, examples, since,
type, requiredForDatabase, supportsDatabase, mustEqualExisting, serializationType).withAccessors(readMethod, property.getWriteMethod());
type, requiredForDatabase, supportsDatabase, mustEqualExisting, serializationType, alternatePropertyNames).withAccessors(readMethod, property.getWriteMethod());
} catch (UnexpectedLiquibaseException e) {
throw e;
}
Expand Down Expand Up @@ -313,6 +314,14 @@ protected String[] createSupportedDatabasesMetaData(

}

protected String[] createAlternateParameterNames(DatabaseChangeProperty changePropertyAnnotation) {
if (changePropertyAnnotation == null) {
return new String[]{};
} else {
return changePropertyAnnotation.alternatePropertyNames();
}
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -775,14 +784,22 @@ public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throw
}
}
} else {
Object childValue = parsedNode.getChildValue(
null, param.getParameterName(), param.getDataTypeClass()
);
if ((childValue == null) && (param.getSerializationType() == SerializationType.DIRECT_VALUE)) {
childValue = parsedNode.getValue();
List<String> parameterNamesToCheck = new ArrayList<>();
parameterNamesToCheck.add(param.getParameterName());
if (param.getAlternateParameterNames() != null) {
parameterNamesToCheck.addAll(Arrays.asList(param.getAlternateParameterNames()));
}
if(null != childValue) {
param.setValue(this, childValue);
for (String paramName : parameterNamesToCheck) {
Object childValue = parsedNode.getChildValue(
null, paramName, param.getDataTypeClass()
);
if ((childValue == null) && (param.getSerializationType() == SerializationType.DIRECT_VALUE)) {
childValue = parsedNode.getValue();
}
if(null != childValue) {
param.setValue(this, childValue);
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import liquibase.statement.SqlStatement;
import liquibase.util.ObjectUtil;
import liquibase.util.StringUtil;
import lombok.Getter;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -48,11 +49,21 @@ public class ChangeParameterMetaData {
private final String[] supportedDatabasesArg;
private Optional<Method> readMethodRef = Optional.empty();
private Optional<Method> writeMethodRef = Optional.empty();
@Getter
private final String[] alternateParameterNames;

public ChangeParameterMetaData(Change change, String parameterName, String displayName, String description,
Map<String, Object> exampleValues, String since, Type dataType,
String[] requiredForDatabase, String[] supportedDatabases, String mustEqualExisting,
LiquibaseSerializable.SerializationType serializationType) {
this(change, parameterName, displayName, description, exampleValues, since, dataType, requiredForDatabase,
supportedDatabases, mustEqualExisting, serializationType, null);
}

public ChangeParameterMetaData(Change change, String parameterName, String displayName, String description,
Map<String, Object> exampleValues, String since, Type dataType,
String[] requiredForDatabase, String[] supportedDatabases, String mustEqualExisting,
LiquibaseSerializable.SerializationType serializationType, String[] alternateParameterNames) {
if (parameterName == null) {
throw new UnexpectedLiquibaseException("Unexpected null parameterName");
}
Expand Down Expand Up @@ -92,6 +103,7 @@ public ChangeParameterMetaData(Change change, String parameterName, String displ

this.supportedDatabasesArg = supportedDatabases;
this.requiredForDatabaseArg = requiredForDatabase;
this.alternateParameterNames = alternateParameterNames;
}

public ChangeParameterMetaData withAccessors(Method readMethod, Method writeMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ LiquibaseSerializable.SerializationType serializationType() default LiquibaseSer
* is requested, the second annotation is used.
*/
ChecksumVersion[] version() default {};

String[] alternatePropertyNames() default {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public void setProcedureBody(String procedureText) {
isChangeProperty = false, version = {ChecksumVersion.V8})
@DatabaseChangeProperty(
description = procedureTextDescription,
serializationType = SerializationType.DIRECT_VALUE)
serializationType = SerializationType.DIRECT_VALUE,
alternatePropertyNames = {"procedureBody"})
public String getProcedureText() {
return procedureText;
}
Expand Down