Skip to content

Conversation

@rogerpadilla
Copy link
Owner

@rogerpadilla rogerpadilla commented Jan 8, 2026

Summary

This PR implements a comprehensive, graph-based schema synchronization system for UQL. By introducing Schema AST as the core foundation, we now have a unified, dialect-agnostic representation of database schemas where relationships and indexes are first-class citizens. This architecture enables reliable schema diffing, smart relation detection, and powerful synchronization workflows.

Key Features

  • Schema AST Foundation: A unified graph representation of tables, columns, relationships, and indexes. Supports topological sorting for deterministic CREATE/DROP ordering and built-in circular dependency detection.
  • Unified SQL Generation: Refactored the multi-class generator hierarchy into a single, high-performance SqlSchemaGenerator parameterized by dialect-specific configurations.
  • Type-Safe Migration Builder: A new fluent API for defining migrations with complete type safety and automatic foreign key handling.
  • Database-First Codegen: Ability to generate clean, decorated TypeScript entities directly from an existing database schema, including intelligent relation inference (e.g., detecting junction tables for Many-to-Many).
  • Schema Sync & Drift Detection:
    • autoSync: Safely push entity changes to the database.
    • DriftDetector: Identify and report discrepancies between entities and production storage.
    • EntityMerger: Safely update existing entity files with new database changes using the TypeScript compiler API.
  • Standardized Introspection: All SQL database introspection now produces a common SchemaAST, significantly reducing implementation logic in specific drivers.

Documentation & CLI

Updated CLI with new powerful commands:

  • generate:from-db: Create entities from an existing database.
  • sync:entities: Keep entities in sync with database changes.
  • drift:check: Verify if the database schema matches your entity definitions.

Quality & Refactoring

  • Removed dozens of as any type assertions across migration and schema modules.
  • Refactored BaseSqlIntrospector to reduce cognitive complexity.
  • 100% clean biome check and tsc --noEmit validation.
  • 602 tests passing with high coverage across all 8 supported database engines.

Closes #80

…ces between implicit and explicit default foreign key actions (e.g., undefined vs 'NO ACTION').

Total Type Safety: I've expanded the cleanup to fully eliminate as any and non-null assertions from schemaGenerator-advanced.spec.ts as well, ensuring the entire core schema logic is now 100% type-safe.
Consolidated Logic: All generators, builders, and config objects now share the same source of truth for foreign key defaults.
@rogerpadilla rogerpadilla merged commit 965bd75 into main Jan 8, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify ORM schema synchronization system via Schema AST

1 participant