Skip to content

fix(import,migrate): prevent destructive blueprint relation and scorecard updates#77

Merged
EricFernandezPort merged 4 commits into
port-experimental:mainfrom
bgilleran-port:fix/blueprint-relation-scorecard-safety
Jun 11, 2026
Merged

fix(import,migrate): prevent destructive blueprint relation and scorecard updates#77
EricFernandezPort merged 4 commits into
port-experimental:mainfrom
bgilleran-port:fix/blueprint-relation-scorecard-safety

Conversation

@bgilleran-port

@bgilleran-port bgilleran-port commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two safety issues in port import and port migrate that could silently destroy production data:

1. Blueprint relation stripping destroys entity relation data

When importing blueprints, Phase 1 strips relation fields to handle circular dependencies. The subsequent PUT replaces the entire blueprint, permanently removing all relation definitions — and with them, every entity-level relation value.

Fix: createOrUpdateBlueprint now fetches the existing blueprint before updating and merges incoming fields on top, preserving any fields not present in the import payload (including stripped relations).

2. Scorecard updates via non-existent PATCH endpoint (404)

On conflict during scorecard creation, the CLI attempted PATCH /blueprints/{bp}/scorecards/{id} which does not exist in the Port API, producing 404 errors.

Fix: On conflict, the CLI now fetches the full scorecard set for the blueprint, merges in the updated scorecards (preserving sibling scorecards), and performs a single bulk PUT /blueprints/{bp}/scorecards. This is additive — existing scorecards not in the import payload are preserved.

Test plan

  • TestImportScorecards_ConflictUsesFetchMergePUT — verifies fetch-merge-bulk-PUT flow on conflict
  • TestImportScorecards_BulkPutFailureRecordsError — verifies error recording on bulk PUT failure
  • Existing blueprint relation tests continue to pass
  • Full go test ./... passes

BGilleran522 and others added 2 commits June 9, 2026 12:30
Use fetch-and-merge on the 409 update path in both import and migrate
so that a Phase 1 PUT (which strips relations for dependency ordering)
never removes existing relation definitions from the target. Phase 2a
then restores the import file's relations as the final state.

This is a single structural safeguard that covers all scenarios:
--skip-entities, --include blueprints, circular deps, and normal imports.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ng deletion

The scorecard conflict/update path used UpdateScorecards (bulk PUT to
/blueprints/:id/scorecards) which replaces the entire scorecard
collection. When only a subset of scorecards were sent, all other
scorecards on that blueprint were deleted.

Switch both import and migrate to use UpdateScorecard (singular PATCH to
/blueprints/:id/scorecards/:id) for updates, consistent with the
additive semantics used by teams, users, pages, and integrations.

Co-authored-by: Cursor <cursoragent@cursor.com>
@bgilleran-port bgilleran-port changed the title fix(import,migrate): use PATCH for scorecard updates to prevent sibling deletion fix(import,migrate): prevent destructive blueprint relation and scorecard updates Jun 9, 2026
The Port API has no PATCH endpoint for individual scorecards, causing
404 errors on update. Instead, fetch the existing scorecard set, merge
in the updates (preserving sibling scorecards), and bulk PUT the result.

Applies to both import and migrate modules.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread port-cli Outdated
Comment thread internal/modules/import_module/import.go
@bgilleran-port bgilleran-port force-pushed the fix/blueprint-relation-scorecard-safety branch from 76b84d8 to 298d581 Compare June 10, 2026 20:04
GetBlueprint returns audit fields (createdAt, updatedAt, createdBy,
updatedBy, id) that were being forwarded to UpdateBlueprint unchanged.
Strip these before every blueprint PUT in both import and migrate to
prevent breakage if the API tightens validation.

Also removes accidentally committed port-cli binary.

Co-authored-by: Cursor <cursoragent@cursor.com>
@bgilleran-port bgilleran-port force-pushed the fix/blueprint-relation-scorecard-safety branch from 298d581 to 4f438d6 Compare June 10, 2026 20:04
@EricFernandezPort EricFernandezPort merged commit 813a86e into port-experimental:main Jun 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants