Add support for @Schema and @Migrate annotations to declare storage record schema versions and migrations.

This commit is contained in:
Overlord committed 2026-10-07 14:47:57 +02:00
1 parent 1664bb6f28
commit b10504e9af
8 files changed
+326 -10

No files matched your search

+17
View File
@@ -399,6 +399,23 @@ Table<Balance> balances = this.storage().define("balances", Balance.class)
.open();
```
The same on the record (`dev.overlord.zomboidforge.api.annotations`), so `table(...)` is enough:
```java
@Schema(version = 2)
record Balance(long coins, @Nullable Instant lastPaid)
{
@Migrate(from = 1)
static Balance fromV1(Row row) { return new Balance(row.getLong("coins"), null); }
}
Table<Balance> balances = this.storage().table("balances", Balance.class);
```
A `@Migrate` method is static, takes a `Row`, returns the record, and may be private. `define`
starts from the annotations: `version(...)` replaces the `@Schema` version, and `migrate(...)`
adds migrations. Each version has one migration at most; a second one throws.
Things to know:
1. Storage calls block. On the main thread they are only allowed during `onLoad`; once the