Skip to content

Build-time declarative schema generation #1010

@willgriffin

Description

@willgriffin

Problem

Schema generation currently happens at runtime by walking inheritance chains, merging fields from parent→child, and computing column definitions on the fly. This requires:

  1. All parent classes to be registered
  2. Correct inheritance chain resolution
  3. Runtime field merging with conflict handling

This is the root cause of many issues — if the inheritance chain is wrong (#1001), the schema is wrong, and the migration crashes.

Proposed Solution

Move schema generation to build time:

  1. During vite build (or smrt-prebuild), after AST scanning produces the manifest, also compute the fully resolved schema for each class
  2. The resolved schema includes all inherited fields already merged (no runtime merging needed)
  3. Store as resolvedSchema alongside the manifest entry
  4. At runtime, getSchemaForClass() simply reads the pre-computed schema — no inheritance walking, no field merging, no parent lookups

Manifest Extension

{
  "objects": {
    "VideoShot": {
      "className": "VideoShot",
      "extends": "Content",
      "fields": { ... },
      "resolvedSchema": {
        "tableName": "contents",
        "columns": {
          "id": { "type": "TEXT", "primaryKey": true },
          "title": { "type": "TEXT" },
          "scriptText": { "type": "TEXT" },
          ...
        },
        "indexes": [...],
        "dependencies": ["video_sequences", "scenes"]
      }
    }
  }
}

Benefits

  • Runtime schema generation becomes a simple lookup
  • No dependency on correct inheritance chain resolution at runtime
  • Build-time errors catch schema conflicts before deployment
  • Significant startup performance improvement

Part of epic #1003.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions