-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: kbirk <[email protected]>
- Loading branch information
Showing
3 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
packages/server/src/main/java/db/migration/V13__NotificationEventProgress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package db.migration; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.util.UUID; | ||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
|
||
public class V13__NotificationEventProgress extends BaseJavaMigration { | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private String mapToString(final int progress) { | ||
switch (progress) { | ||
case 0: | ||
return "CANCELLED"; | ||
case 1: | ||
return "COMPLETE"; | ||
case 2: | ||
return "ERROR"; | ||
case 3: | ||
return "FAILED"; | ||
case 4: | ||
return "QUEUED"; | ||
case 5: | ||
return "RETRIEVING"; | ||
case 6: | ||
return "RUNNING"; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void migrate(final Context context) throws Exception { | ||
try (var statement = context.getConnection().createStatement()) { | ||
|
||
// Rename transform to transform_old | ||
statement.execute("ALTER TABLE notification_event RENAME COLUMN state TO state_old;"); | ||
|
||
// Create new json column transform | ||
statement.execute("ALTER TABLE notification_event ADD COLUMN state varchar(255);"); | ||
|
||
// Select all rows from the simulation_result_files table | ||
final ResultSet resultSet = statement.executeQuery( | ||
"SELECT id, state_old FROM notification_event WHERE state_old IS NOT NULL ORDER BY id;"); | ||
|
||
// Prepare the update statement for the simulation table | ||
final PreparedStatement preparedStatement = | ||
context.getConnection().prepareStatement("UPDATE notification_event SET state = ? WHERE id = ?;"); | ||
|
||
// Iterate through the result set | ||
while (resultSet.next()) { | ||
// Get the id and result_files | ||
final UUID id = (UUID) resultSet.getObject("id"); | ||
final int state = resultSet.getInt("state_old"); | ||
|
||
// Set the parameters for the update statement | ||
preparedStatement.setString(1, mapToString(state)); | ||
preparedStatement.setObject(2, id); | ||
|
||
// Execute the update statement | ||
preparedStatement.executeUpdate(); | ||
} | ||
|
||
// Create new json column transform | ||
statement.execute("ALTER TABLE notification_event DROP COLUMN state_old"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters