Skip to content

refactor: drop compound databaseId:tableId resourceId#176

Open
abnegate wants to merge 1 commit intomainfrom
feat/drop-compound-resource-id
Open

refactor: drop compound databaseId:tableId resourceId#176
abnegate wants to merge 1 commit intomainfrom
feat/drop-compound-resource-id

Conversation

@abnegate
Copy link
Copy Markdown
Member

@abnegate abnegate commented May 1, 2026

Summary

  • CSV/JSON sources and destinations now take string \$databaseId, string \$tableId directly. The colon-splitting on \$resourceId is gone.
  • Target::run / Source::run / Destination::run / Transfer::run gain a new optional \$rootResourceChildId parameter. For database roots, this scopes the transfer to a specific table within the root database. \$rootResourceId keeps its existing semantics (always matches \$rootResourceType).
  • Sources/Appwrite no longer inspects `rootResourceId` for ":" or splits it; uses `$this->rootResourceChildId` for per-table filtering.

Test plan

  • composer lint passes locally
  • composer check (PHPStan level 3) passes locally
  • CSV/JSON unit tests updated to pass separate IDs

Linked

🤖 Generated with Claude Code

The CSV/JSON sources and destinations took a single composite
"databaseId:tableId" string and split it on ':' internally. The Appwrite
source did the same trick on `rootResourceId` to scope a transfer to a
specific collection within a database. That mixed two identifiers in
one slot, broke queryability for callers, and forced consumers to
recompose the colon-form at the boundary.

This change replaces the compound with explicit fields:

- CSV/JSON Source/Destination constructors now take `string $databaseId,
  string $tableId` directly. No more `explode(':', $resourceId)`.
- Target/Source/Destination/Transfer::run gain a new optional
  `$rootResourceChildId` parameter that, for database roots, scopes the
  transfer to a specific table/collection inside the root database.
  `$rootResourceId` keeps its existing semantics — it always matches
  `$rootResourceType` (a top-level resource).
- Sources/Appwrite no longer inspects `rootResourceId` for ':' or
  splits it; it reads `$this->rootResourceChildId` when the caller wants
  per-collection filtering.

Tests updated to call the new constructor signatures.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 1, 2026

Greptile Summary

This PR replaces the compound databaseId:tableId $resourceId string with separate $databaseId / $tableId parameters across CSV/JSON sources and destinations, and introduces an explicit $rootResourceChildId parameter on the run() chain to scope per-table transfers without colon-splitting.

  • The abstract Target::run() signature is missing $rootResourceType — its 4th positional parameter is $rootResourceChildId, but both Source::run and Destination::run insert $rootResourceType as the 4th param and push $rootResourceChildId to 5th. Any caller typed against Target that passes four positional args will silently bind its $rootResourceChildId value into $rootResourceType, leaving $rootResourceChildId as ''.

Confidence Score: 3/5

Not safe to merge until the abstract Target::run signature is fixed to include $rootResourceType in the correct position.

One P1 defect: the abstract method in Target declares $rootResourceChildId as the 4th param while both concrete implementations have $rootResourceType there, making per-table scoping silently broken for any caller using the abstract interface. All other changes are clean.

src/Migration/Target.php — abstract run signature must add $rootResourceType in the correct position.

Important Files Changed

Filename Overview
src/Migration/Target.php Abstract run signature is missing $rootResourceType — 4th positional param conflicts with concrete implementations, causing silent $rootResourceChildId misrouting.
src/Migration/Source.php Adds $rootResourceChildId parameter and stores it; correctly assigns all three root-resource fields.
src/Migration/Destination.php Passes $rootResourceChildId through to the source's run; signature and delegation are correct.
src/Migration/Transfer.php Adds $rootResourceChildId to run, null-coalesces it to '', and passes it to $this->destination->run; logic is correct.
src/Migration/Sources/Appwrite.php Replaces colon-splitting on $rootResourceId with direct use of $this->rootResourceChildId; filtering logic is cleaner and correct.
src/Migration/Sources/CSV.php Splits $resourceId into $databaseId + $tableId constructor params; removes the explode call and uses the fields directly.
src/Migration/Sources/JSON.php Same split-param refactor as CSV source; exportRows now uses fields directly instead of explode.
src/Migration/Destinations/CSV.php Constructor split into $databaseId + $tableId; error messages updated accordingly.
src/Migration/Destinations/JSON.php Same constructor split as CSV destination; straightforward and correct.
tests/Migration/Unit/General/CSVTest.php All test call-sites updated to pass separate databaseId / tableId args.
tests/Migration/Unit/General/JSONTest.php Same test call-site updates as CSVTest; both destination instantiations corrected.

Reviews (1): Last reviewed commit: "refactor: drop compound `databaseId:coll..." | Re-trigger Greptile

Comment thread src/Migration/Target.php
* @param string $rootResourceChildId Optional child filter under the root resource. For database roots, this is the collection/table ID.
*/
abstract public function run(array $resources, callable $callback, string $rootResourceId = ''): void;
abstract public function run(array $resources, callable $callback, string $rootResourceId = '', string $rootResourceChildId = ''): void;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Abstract run signature is missing $rootResourceType

The abstract declares the 4th positional parameter as $rootResourceChildId, but both concrete overrides (Source::run and Destination::run) insert $rootResourceType as the 4th parameter and push $rootResourceChildId to 5th. Any caller typed as Target that passes 4 positional args will silently route their $rootResourceChildId value into $rootResourceType, leaving $rootResourceChildId as '' and making table-scoped transfers silently no-ops.

Suggested change
abstract public function run(array $resources, callable $callback, string $rootResourceId = '', string $rootResourceChildId = ''): void;
abstract public function run(array $resources, callable $callback, string $rootResourceId = '', string $rootResourceType = '', string $rootResourceChildId = ''): void;

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.

1 participant