Package su.onno.ui.migration
Class Ui2MigrationTool
java.lang.Object
su.onno.ui.migration.Ui2MigrationTool
One-time conversion support for applications moving legacy UI values and authored metadata to
the 2.0 contracts.
Create this inside an AppMigration from its MigrationContext. Column helpers
scan non-null values and apply changed rows in prepared batches inside the migration's existing
transaction. Identifiers are strictly validated before being interpolated into SQL. A malformed
or ambiguous legacy value aborts the migration with its table/column/row id in the error rather
than leaving a partially guessed conversion.
public void migrate(MigrationContext context) throws Exception {
var tool = new Ui2MigrationTool(context, mediaStorage);
tool.migrateEnumNames("catalog_orders", "_id", "status", OrderStatus.class);
tool.migrateDataUrlImages("catalog_people", "_id", "avatar_url");
tool.migrateGeoPoints("catalog_sites", "_id", "location");
}
The source-only helpers are deliberately explicit. In particular, a bare
"currency" has no safe universal replacement, so callers must supply their ISO 4217
currency. They can use these helpers from a small source/config codemod or to verify replacements
before upgrading.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCounts from a completed table-column conversion. -
Constructor Summary
ConstructorsConstructorDescriptionUi2MigrationTool(MigrationContext context) A tool for enum/geo/source-metadata migrations only.Ui2MigrationTool(MigrationContext context, MediaStorage mediaStorage) A tool with media migration enabled.Ui2MigrationTool(MigrationContext context, MediaStorage mediaStorage, int batchSize) Constructor with an explicit update batch size, primarily for large application tables. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcanonicalCurrencyFormat(String format, String defaultCurrency) Make a field-format hint explicit.canonicalEnumId(Class<E> enumType, String constantName) Convert one legacy enum constant name to its deterministic UUID.static StringcanonicalGeoJson(String value) Convert a legacy point string to canonical GeoJSON.static StringcanonicalIcon(String icon) Return the current Lucide name for a formerly accepted alias; current names pass through.static StringRewrite the old dashboard/list map config key to the canonical GeoJSON key.canonicalMediaValue(String value) Store one legacy data-URL value (or every item of a newline-joined gallery) and return canonical stored-media URL(s).static StringcanonicalWidget(String widget) Rewrite a legacy point-widget name to the canonical GeoJSON editor name.migrateDataUrlImages(String table, String idColumn, String valueColumn) Decode every legacy base64data:image/...URL in an image/gallery column, store it throughMediaStorage, and replace it with the returned URL.<E extends Enum<E>>
Ui2MigrationTool.MigrationResultmigrateEnumNames(String table, String idColumn, String valueColumn, Class<E> enumType) Replace legacy Java enum constant names with their deterministic stored UUIDs.migrateGeoPoints(String table, String idColumn, String valueColumn) Replace a legacy"lat,lng"point string with a GeoJSON FeatureCollection in the same column.
-
Constructor Details
-
Ui2MigrationTool
A tool with media migration enabled. The supplied storage is the application's configuredMediaStorage, so converted data URLs land in the same backend as new uploads. -
Ui2MigrationTool
A tool for enum/geo/source-metadata migrations only. Calling an image conversion fails fast with an explanation that aMediaStoragemust be supplied. -
Ui2MigrationTool
Constructor with an explicit update batch size, primarily for large application tables.
-
-
Method Details
-
migrateEnumNames
public <E extends Enum<E>> Ui2MigrationTool.MigrationResult migrateEnumNames(String table, String idColumn, String valueColumn, Class<E> enumType) throws Exception Replace legacy Java enum constant names with their deterministic stored UUIDs. Already-canonical UUID values are left unchanged; unknown names abort the migration.- Throws:
Exception
-
migrateDataUrlImages
public Ui2MigrationTool.MigrationResult migrateDataUrlImages(String table, String idColumn, String valueColumn) throws Exception Decode every legacy base64data:image/...URL in an image/gallery column, store it throughMediaStorage, and replace it with the returned URL. Newline-joined galleries are converted item by item; already-stored URLs are unchanged.- Throws:
Exception
-
migrateGeoPoints
public Ui2MigrationTool.MigrationResult migrateGeoPoints(String table, String idColumn, String valueColumn) throws Exception Replace a legacy"lat,lng"point string with a GeoJSON FeatureCollection in the same column. Existing JSON is unchanged. Afterward, change authored metadata fromwidget("map")/map().field(...)towidget("geojson")/map().geoJson(...).- Throws:
Exception
-
canonicalEnumId
Convert one legacy enum constant name to its deterministic UUID. -
canonicalMediaValue
Store one legacy data-URL value (or every item of a newline-joined gallery) and return canonical stored-media URL(s). Values that contain no data URL pass through unchanged.- Throws:
IOException
-
canonicalGeoJson
Convert a legacy point string to canonical GeoJSON. An existing object with a recognized GeoJSONtypepasses through unchanged; malformed JSON/coordinates and out-of-range points fail fast. -
canonicalCurrencyFormat
Make a field-format hint explicit. A barecurrencyis rewritten with the caller's ISO 4217 code; an existingcurrency:xxxis validated and normalized to uppercase. -
canonicalIcon
Return the current Lucide name for a formerly accepted alias; current names pass through. -
canonicalWidget
Rewrite a legacy point-widget name to the canonical GeoJSON editor name. -
canonicalMapConfigKey
Rewrite the old dashboard/list map config key to the canonical GeoJSON key.
-