Notes/ForgeSchema

ForgeSchema Second Alpha Reads Defaults, Identity Columns and Foreign Keys

ForgeSchema’s first alpha could only read a PostgreSQL schema with no defaults, no identity columns, no unique constraints and no foreign keys. Most real app schemas have all four, so it mostly answered “unsupported”. The second alpha, 0.2.0-alpha.1, went out on 18 October as a prerelease on GitHub and reads them.

Inspect, plan, apply and verify now handle varchar, char and numeric columns, defaults such as now() and gen_random_uuid(), identity columns, unique constraints and indexes, and foreign keys with their delete and update actions. Plans can add a required column that has a default, widen a varchar or numeric column, change nullability or a default, and add constraints and foreign keys to tables already holding data. Each step says what happens to existing rows. If the data doesn’t fit, say a NULL where the plan asks for NOT NULL, the whole migration rolls back with PostgreSQL’s own error. Drops and most type conversions stay blocked.

Apply got easier on a live database too. It used to lock every table in the schema; now it locks only the tables a plan changes, and plan --explain lists them first. Slow steps get adjustable timeouts.

The studio’s independent review before release found a real bug: on a server with standard_conforming_strings off, a text default holding a backslash could slip SQL into a migration. It was fixed before the release, along with defaults that verify would have wrongly called a match. CI passed on PostgreSQL 16.10 and 17.6, and plans saved with the first alpha still apply unchanged. The code is open source under Apache 2.0.