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

fix: Add check, so it can be backported [DHIS2-18020] #19235

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,35 @@ public class V2_42_21__Add_new_column_into_visualization_and_migrate_relative_pe
}

public void migrate(Context context) throws SQLException {
step1(context);
step2(context);
if (!isMigrationAlreadyApplied(context)) {
step1(context);
step2(context);
}
}

private boolean isMigrationAlreadyApplied(Context context) {
String schema = null;
try {
schema = context.getConnection().getSchema();
} catch (SQLException e) {
log.error("Schema check: ", e);
}

final String checkColumnExists =
"select exists (select 1 from information_schema.columns where "
+ (schema != null ? "table_schema='" + schema + "' and " : "")
+ "table_name='eventvisualization' and column_name='relativeperiods')";

try (Statement statement = context.getConnection().createStatement();
ResultSet rs = statement.executeQuery(checkColumnExists)) {
while (rs.next()) {
return rs.getBoolean(1);
}
} catch (SQLException e) {
log.error("Check failed: ", e);
}

return false;
}

/**
Expand Down Expand Up @@ -213,7 +240,7 @@ private static void copyPeriodsToJsonColumn(
ps.setLong(2, parentTableId);
ps.executeUpdate();

// Clear the list of periods so it can be reused in the next iteration.
// Clear the list of periods, so it can be reused in the next iteration.
periodList.clear();
}
}
Expand Down
Loading