Class SchemaGenerator

java.lang.Object
su.onno.schema.SchemaGenerator

public class SchemaGenerator extends Object
Renders CREATE TABLE IF NOT EXISTS DDL for everything in the metadata registry. Table layouts come from SchemaModelBuilder, the shared source of truth also used by SchemaDiffEngine/SchemaUpgrader for evolving existing databases.

execute(Jdbi) is a fresh-database bootstrap convenience. Existing database evolution belongs exclusively to SchemaUpgrader, which handles additions, renames, type changes, history, and destructive-change gating.

  • Constructor Details

  • Method Details

    • generateSequenceTableDDL

      public static String generateSequenceTableDDL()
    • generateOutboxTableDDL

      public static String generateOutboxTableDDL()
    • generateDDL

      public List<String> generateDDL()
    • generateDDL

      public List<String> generateDDL(SqlDialect dialect)
    • execute

      public void execute(org.jdbi.v3.core.Jdbi jdbi)
    • generateIndexDDL

      public List<String> generateIndexDDL()
      Index statements for every generated table, covering the columns the framework itself queries by: ref columns (auto-joins and reference expansion), catalog hierarchy parents, document dates, tabular-section owners, register periods, document refs, and dimensions. Statements use IF NOT EXISTS; the SchemaUpgrader re-asserts them after applying its migration plan so existing databases pick them up on next boot.
    • generateSearchIndexDDL

      public List<String> generateSearchIndexDDL(SqlDialect dialect)
      PostgreSQL trigram (GIN) indexes that turn the list/search LOWER(CAST(col AS VARCHAR)) LIKE '%term%' scan into an index lookup — the single biggest win for substring search on a large table. The indexed expression is byte-for-byte the one the query services emit, so the planner actually uses it. Empty on any non-PostgreSQL dialect (H2 has no pg_trgm; it falls back to the LIKE scan), and applied best-effort by applySearchIndexes(org.jdbi.v3.core.Jdbi, su.onno.schema.SqlDialect) since CREATE EXTENSION may require privileges the app role lacks.
    • applySearchIndexes

      public void applySearchIndexes(org.jdbi.v3.core.Jdbi jdbi, SqlDialect dialect)
      Apply the trigram search indexes best-effort: a missing pg_trgm extension (or a role without rights to create it) logs a warning and the app keeps running on LIKE scans rather than failing to boot. A no-op on non-PostgreSQL dialects.
    • sqlType

      public static String sqlType(Class<?> javaType, int length, int precision, int scale)
    • sqlType

      public static String sqlType(Class<?> javaType, int length, int precision, int scale, String fieldContext)