/** * Settings of `ownerId` that are not in `existingPairs` (`":"`) * yet. This is what keeps the IAM baseline seed idempotent: `organization_settings` * and `unit_settings` have no unique index on (owner, key), so a plain re-insert * — or the package seeder's upsert-on-id, which never supplies an id — silently * duplicates every row. * * `value: null` becomes `undefined` so the column default applies on insert. */ export function missingSettings< TSetting extends { key: string; value?: string | null }, >( defaults: TSetting[], existingPairs: Set, ownerId: string, ): (Omit & { value?: string })[] { return defaults .filter((setting) => !existingPairs.has(`${ownerId}:${setting.key}`)) .map((setting) => ({ ...setting, value: setting.value ?? undefined })); }