Split a PGPM Migration by Column and Constraint
Dan Lynch
The atomic copy put several statements inside one table change. To give those statements their own entries in pgpm.plan, keep --granularity atomic and set --change-granularity alteration:
bashpgpm transform --cwd ./packages/library --granularity atomic \ --change-granularity alteration --out ../../projections/alteration --check cat projections/atomic/library-atomic/pgpm.plan cat projections/alteration/library-atomic/pgpm.plan
In the second plan, look for separate entries for the title column and books_pkey constraint. Each entry gets its own deploy, revert, and verify script. The dependencies still ensure the table exists before its columns and constraints.
Remember the distinction: --granularity shapes the SQL statements; --change-granularity groups them into plan entries. The default object groups by database object. At the other extreme, single puts the entire module in one plan entry. Here, --check confirms that splitting the plan didn't change the catalog.

