/** * Adds the cross-reference foreign keys between Quotes, Client * Registrations and Contracts that were deliberately left as plain * nullable UUIDs when each table was created in parallel (see the header * comments in 1788445280742_quotes.cjs, 1788447739229_client-registrations.cjs * and 1788447802216_contracts.cjs). All three tables now exist on `main`, * so this closes that gap. * * ON DELETE RESTRICT everywhere: none of these aggregates has a DELETE * route today (quotes/client_registrations/contracts are only ever * status-transitioned, never removed), and a business document silently * losing its link to another business document on an unrelated delete * would be a worse failure mode than the delete itself being blocked. */ exports.up = (pgm) => { pgm.addConstraint("quotes", "fk_quotes_client_registration", { foreignKeys: { columns: "client_registration_id", references: "client_registrations(id)", onDelete: "RESTRICT", }, }); pgm.addConstraint("client_registrations", "fk_client_registrations_quote", { foreignKeys: { columns: "quote_id", references: "quotes(id)", onDelete: "RESTRICT", }, }); pgm.addConstraint("contracts", "fk_contracts_quote", { foreignKeys: { columns: "quote_id", references: "quotes(id)", onDelete: "RESTRICT", }, }); pgm.addConstraint("contracts", "fk_contracts_client_registration", { foreignKeys: { columns: "client_registration_id", references: "client_registrations(id)", onDelete: "RESTRICT", }, }); }; exports.down = (pgm) => { pgm.dropConstraint("contracts", "fk_contracts_client_registration"); pgm.dropConstraint("contracts", "fk_contracts_quote"); pgm.dropConstraint("client_registrations", "fk_client_registrations_quote"); pgm.dropConstraint("quotes", "fk_quotes_client_registration"); };