diff --git a/bubble-server/src/main/java/db/BubbleMigration.java b/bubble-server/src/main/java/db/BubbleMigration.java index 1340a00b..06ddc6d2 100644 --- a/bubble-server/src/main/java/db/BubbleMigration.java +++ b/bubble-server/src/main/java/db/BubbleMigration.java @@ -9,7 +9,7 @@ import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.cobbzilla.wizard.spring.config.rdbms.RdbmsConfig; -import org.flywaydb.core.api.migration.JavaMigration; +import org.flywaydb.core.api.migration.BaseJavaMigration; import org.jasypt.hibernate4.encryptor.HibernatePBEStringEncryptor; /** @@ -27,7 +27,7 @@ import org.jasypt.hibernate4.encryptor.HibernatePBEStringEncryptor; * For example: V2020042301__add_account_payment_archived.sql */ @Slf4j -public abstract class BubbleMigration implements JavaMigration { +public abstract class BubbleMigration extends BaseJavaMigration { @Getter @Setter private static BubbleConfiguration configuration; diff --git a/bubble-server/src/main/java/db/BubbleValueUpdateMigration.java b/bubble-server/src/main/java/db/BubbleValueUpdateMigration.java new file mode 100644 index 00000000..e87e0c62 --- /dev/null +++ b/bubble-server/src/main/java/db/BubbleValueUpdateMigration.java @@ -0,0 +1,26 @@ +package db; + +import lombok.NonNull; +import org.flywaydb.core.api.migration.Context; + +public abstract class BubbleValueUpdateMigration extends BubbleMigration { + @Override public void migrate(@NonNull final Context context) throws Exception { + final var connection = context.getConnection(); + final var select = connection.prepareStatement("SELECT uuid, " + fieldToUpdate() + " FROM " + tableToUpdate() + + " WHERE " + condition()); + final var update = connection.prepareStatement("UPDATE " + tableToUpdate() + + " SET " + fieldToUpdate() + " = ? WHERE uuid = ?"); + + final var rows = select.executeQuery(); + while (rows.next()) { + update.setString(1, updateValues(rows.getString(2))); + update.setString(2, rows.getString(1)); + update.executeUpdate(); + } + } + + @NonNull protected abstract String tableToUpdate(); + @NonNull protected abstract String fieldToUpdate(); + @NonNull protected abstract String condition(); + @NonNull protected abstract String updateValues(@NonNull String currentValue); +} diff --git a/bubble-server/src/main/resources/models/apps/bubble_block/bubbleApp_bubbleBlock.json b/bubble-server/src/main/resources/models/apps/bubble_block/bubbleApp_bubbleBlock.json index 5222cf09..09cb6d6d 100644 --- a/bubble-server/src/main/resources/models/apps/bubble_block/bubbleApp_bubbleBlock.json +++ b/bubble-server/src/main/resources/models/apps/bubble_block/bubbleApp_bubbleBlock.json @@ -53,7 +53,7 @@ {"name": "removeList", "index": 50, "when": "item.url !== ''"}, { "name": "createList", "scope": "app", "index": 10, - "params": ["url"], + "params": [ "name", "description", "url", "tagString" ], "button": "createList" }, {