Files
lux/examples/schema_evolution.lux
Brandon Lucas f5fe7d5335 fix: fix examples to use working patterns
- behavioral.lux: use verifiable behavioral patterns (abs for idempotent)
- behavioral_types.lux: use simpler verified patterns, proper main invocation
- schema_evolution.lux: simplify to runtime schema ops, fix record access
- jit_test.lux: add proper main function with console output

All examples now parse and run correctly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 23:31:21 -05:00

59 lines
2.0 KiB
Plaintext

// Schema Evolution Demo
// Demonstrates version tracking using runtime Schema operations
// ============================================================
// PART 1: Runtime Schema Operations
// ============================================================
// Create versioned values at runtime
let user1 = Schema.versioned("User", 1, "Alice")
let user2 = Schema.versioned("User", 2, "Bob")
// Check versions
let v1 = Schema.getVersion(user1) // 1
let v2 = Schema.getVersion(user2) // 2
// Migrate to newer version (upgrade)
let upgraded = Schema.migrate(user1, 2)
let upgradedVersion = Schema.getVersion(upgraded) // 2
// ============================================================
// PART 2: Practical Example - API Versioning
// ============================================================
// Simulate different API response versions
fn createResponseV1(data: String): { version: Int, payload: String } =
{ version: 1, payload: data }
fn createResponseV2(data: String, timestamp: Int): { version: Int, payload: String, meta: { ts: Int } } =
{ version: 2, payload: data, meta: { ts: timestamp } }
// Version-aware processing
fn getPayload(response: { version: Int, payload: String }): String =
response.payload
let resp1 = createResponseV1("Hello")
let resp2 = createResponseV2("World", 1234567890)
let payload1 = getPayload(resp1)
let payload2 = resp2.payload
// ============================================================
// RESULTS
// ============================================================
fn main(): Unit with {Console} = {
Console.print("=== Schema Evolution Demo ===")
Console.print("")
Console.print("Part 1: Runtime schema operations")
Console.print(" User v1 version: " + toString(v1))
Console.print(" User v2 version: " + toString(v2))
Console.print(" After upgrade: " + toString(upgradedVersion))
Console.print("")
Console.print("Part 2: API versioning")
Console.print(" Response v1 payload: " + payload1)
Console.print(" Response v2 payload: " + payload2)
}
let output = run main() with {}