Skip to content

2.1.16

Choose a tag to compare

@vzakharchenko vzakharchenko released this 07 Dec 21:56
· 85 commits to master since this release

🔧 Improved Migration Engine & CLI Stability

This release focuses on making schema evolution more predictable and strengthening the CLI, especially around complex Drizzle-based diff generation and safe NOT NULL transitions.

✨ What’s New

  1. Refined forge-sql-orm-cli Behavior

1.1 Removed Dynamic Imports During Diff Generation
The CLI no longer relies on dynamic imports when resolving schema diffs between the reference database and Drizzle models.

1.2 Safe NOT NULL Field Introduction (3-Step Migration)
When adding a new field that is NOT NULL in the reference schema, the CLI now generates a deterministic 3-migration sequence:
• Migration 1 — create the field as nullable
• Migration 2 — populate the field with a default value (if the default is not defined in schema, it must be provided manually)
• Migration 3 — convert the field to NOT NULL

This avoids runtime failures and ensures smooth transitions in production schemas.

1.3 Converting Nullable → NOT NULL (2-Step Migration)
When updating an existing column from nullable to not null, the CLI now generates:
• Migration 1 —update all existing rows with a default value (if the default is not defined in the schema, it must be provided manually) where the field is NULL
• Migration 2 — apply the NOT NULL constraint

This prevents TiDB errors and enforces predictable schema tightening.

  1. Improved Table Extraction Logic (Regex as Fallback)

The mechanism for extracting table names from SQL queries has been redesigned:
• The new parser avoids regex entirely for the primary extraction logic
• Regex is used only as a fallback for unusual or nested SQL structures

This improvement is essential for the caching layer:
by reliably detecting which tables a query touches, the ORM can precisely determine which cache entries should be invalidated — without over-invalidating or missing dependencies.