Skip to content

chore: absorb utopia-php/mongo and utopia-php/database into packages/ - #14242

Closed
ChiragAgg5k wants to merge 6511 commits into
mainfrom
chore/absorb-database
Closed

ChiragAgg5k wants to merge 6511 commits into
mainfrom
chore/absorb-database

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Wave 6 of #13828: moves utopia-php/mongo and utopia-php/database into packages/ in one PR, because they share the MariaDB/PostgreSQL/MongoDB compose, following the playbook in rfc/monorepo.md. migration comes next in its own PR. After this, Appwrite's lock still vendors only utopia-php/migration.

Six commits, plus review fixes and a merge of main:

  1. Add 'packages/mongo/' from commit '34ccfd6…': subtree import of the mirror with its full history, at 1.5.4, which Appwrite already locks.
  2. chore(mongo): mirror plumbing: mirror.yml, the README banner, the root-canonical QA files removed (pint.json, .coderabbit.yaml, the mirror's workflows), and the mirror ruleset with the split app as bypass.
  3. Add 'packages/database/' from commit '7b750be…': subtree import of the mirror's main. That is 7.4.1 (locked here) plus one unreleased fix, c5fc677 fix(postgres): let distanceLessThan use the spatial index (fix(postgres): let distanceLessThan use the spatial index utopia-php/database#1001). Per the RFC's step 3, Appwrite runs that head from now on.
  4. chore(database): mirror plumbing: as for mongo, and also drops psalm.xml, .gitpod.yml, the issue templates and the per-repository Dockerfile.
  5. refactor(database): reshape mongo and database for packages/: step A for both.
  6. refactor: load mongo and database from packages/: root wiring, lock, CI rule and RFC.

Step A (commit 5)

  • Layout:
    • database: src/Database/* → src/; tests/unit/* → tests/, tests/e2e → tests/E2E; tests move from Tests\Unit\ / Tests\E2E\ to Utopia\Database\Tests\ / Utopia\Database\Tests\E2E\.
    • mongo: tests move from Utopia\Tests\ to Utopia\Mongo\Tests\; MongoTest and TransactionTest, which need a live server, move to tests/E2E.
    • phpunit.xml in each now has unit and e2e suites.
  • src/ is byte-for-byte the import. git diff between the subtree import and HEAD is empty for both packages' src, including whitespace; Pint changes nothing there.
  • E2E tier: both packages' suites reach services by compose name, and database's GeneralTests also stop and start containers by name to exercise the cache/mirror failover. Rather than rewrite them for the host, tests/e2e.sh (composer test:e2e) runs them inside the compose network.
    • The tests service now uses appwrite/base:2.1.0 (PHP 8.5 with pdo_mysql, pdo_pgsql, pdo_sqlite, mongodb, redis, swoole and the Docker CLI). It mounts the package (with vendor/ already installed by bin/monorepo test), the root toolchain's vendor/ for phpunit, and, for database, the Docker socket. This replaces the per-repository Dockerfiles that compiled those extensions.
    • database's Adminer and mongo-express move to a debug profile.
    • database's test:e2e disables Composer's process timeout, as its old test script did: the tier is 10,708 tests.
  • PHPUnit 12 and cache 5.1: the suites were written for PHPUnit 9 and locked cache 5.0. Against the root toolchain and packages/cache they fataled or errored, so the tests (not src) change as follows:
    • @depends / @dataProvider / @test docblocks → attributes: 95 in total, including the scope traits, which Rector's set skips.
    • addMethods(['inTransaction']) → stub the wrapper's __call.
    • withConsecutive → record the executed statements and assert them in order.
    • onConsecutiveCalls(throwException(…), …) → a counting callback.
    • DateTimeTest sets its fixtures in setUp(), since TestCase::__construct is final in PHPUnit 12.
    • invalidDefaultValues becomes a static data provider.
    • The four cache test doubles (HashAwareMemoryCache, HashMemoryCache, JsonHashMemoryCache, LeasableMemoryCache) accept save()'s int $ttl = 0. Without it they fatal against cache 5.1.x even when resolved from Packagist, so this was already broken on the mirror for anything newer than the 5.0.0 it locked.
  • PHPStan: standalone phpstan.neon at level max, with baselines for what the packages arrived with:
    • database: 4,865 findings, 2,348 in src (752 in Database.php) and 2,517 in the tests. It had only Psalm before.
    • mongo: 420 findings. Its own repository ran level 5.
    • mongo's tests/ClientTest.php is excluded: its transport doubles narrow the parameters of Swoole client methods that the stubs type as mixed, which PHPStan reports as non-ignorable.
    • Both baselines are listed in the RFC's phase 8 burn-down.
  • Rector: a standalone rector.php that skips both packages' src and tests. Run as-is it rewrites released code (types added, isset() turned into === null, docblocks removed). Absorbing moves code, so that waits for the burn-down.

Root wiring (commit 6)

  • bin/monorepo autoload adds both packages to the root autoload, autoload-dev and replace. "utopia-php/database": "^7.4.1" leaves require. replace also satisfies the still-vendored migration's requirement on database.
  • Hoisted into require: ramsey/uuid: 4.9.* (mongo's) and ext-mongodb: * (both packages'; Appwrite only had it transitively). No other third-party requirement needed hoisting.
  • Lock diff: drops utopia-php/database 7.4.1 and utopia-php/mongo 1.5.4, nothing else. ramsey/uuid stays at 4.9.4.
  • CI: the e2e matrix used to widen (all of MariaDB, PostgreSQL and MongoDB, dedicated and shared) when utopia-php/database's lock version changed. It now widens when the PR's files touch packages/database/ or packages/mongo/, as the RFC planned. The Tests / Matrix job gains pull-requests: read for that. This PR itself therefore runs the full matrix.
  • rfc/monorepo.md: phase 5 notes and both baselines.

Review and CI fixes after opening

  • 3dfbed0 (Hansi):
    • the e2e runners pin COMPOSE_FILE=docker-compose.yml, because CI exports the root override and exec failed before any suite ran;
    • mongo requires ext-swoole, because Client constructs Swoole's clients unconditionally;
    • database's CONTRIBUTING points at bin/monorepo and tests/e2e.sh.
  • 3869d5d: invalidDefaultValues becomes a static data provider. PHPUnit 10+ rejects instance providers, so 16 adapter suites errored.
  • 9f26684: database suggests ext-swoole. Connection::hasError() calls Swoole's DetectsLostConnections, which the extension's bundled library provides; the package job installs only the extensions a manifest names, so PHPStan there could not see the class.
  • CI: all 260 checks pass. That includes the full MariaDB/PostgreSQL/MongoDB × dedicated/shared matrix that the new path rule triggers, and Packages / database (477 unit tests plus the 11,092-test e2e tier in about 42 minutes).
    • On the first full run, MariaDB (shared) / Account (testUpdateAccountEmailSearch) and MongoDB (shared) / Realtime (testIndexesTablesAPI) each failed once. Both passed on the next run without changes.
    • MongoDB (dedicated) / Functions failed pulling its image, and Packages / config hit a Rector worker crash ("Child process error", no finding). Both passed on rerun.

Validation

  • bin/monorepo validate: all packages valid.
  • bin/monorepo check mongo and bin/monorepo check database: Rector, Pint and PHPStan level max (with baselines) pass.
  • bin/monorepo test mongo: unit tier 35 tests; e2e tier (in the compose network) 27 tests, all passing.
  • bin/monorepo test database:
    • The unit tier passes: 477 tests.
    • The e2e tier ran in full locally: 10,708 tests, 141,471 assertions, 195 skipped. The only errors were 16 from one non-static data provider (invalidDefaultValues), which PHPUnit 10+ rejects; 3869d5d fixes it, and a rerun of the affected tests passes on all 16 adapter suites (448 tests).
    • Two Redis testKeywords runs are risky (no assertions on that adapter), as released.
  • Root packages suite filtered to Utopia\(Database|Mongo), in appwrite/base:2.1.0: 512 tests pass.
  • Appwrite unit suite in appwrite/base:2.1.0 with .env: 1,406 tests pass.
  • composer lint, composer refactor:check and composer analyze pass.
  • bin/monorepo split mongo --dry-run → 66b3afc and split database --dry-run → 2caf9b0; both fast-forward from the mirror heads.
  • git diff --check reports trailing whitespace only in imported files: database's README, CONTRIBUTING and docs (Markdown hard breaks) and SQL strings inside src. These are kept as released; nothing new adds whitespace.

Open issues and PRs on the mirrors, for triage after merge

mirror-redirect closes anything new; these predate the move.

utopia-php/mongo (3 PRs, 2 issues). All three PRs carry live ideas and would need re-opening against packages/mongo:

Issues #45 (retryable writes outside transactions) and #39 (handshake client metadata) are feature requests to carry over.

utopia-php/database (56 PRs, 4 issues):

Merge and follow-up

Merge with a merge commit. A squash drops the git-subtree-* annotations and orphans both packages from their mirrors.

After merge:

  • Confirm Split pushes to utopia-php/mongo and utopia-php/database, and that each mirror's tree matches packages/<name>.
  • There is no monorepo retire step: both were standalone repositories.
  • Triage the mirror PRs and issues above.
  • Next: migration (wave 6, second PR).

Related: #13828
Related: #14255

fogelito and others added 30 commits June 29, 2026 15:01
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
…max-param2

# Conflicts:
#	src/Database/Adapter/MariaDB.php
3.1.* excluded the 3.2.0 release (purge-tombstone lease, backward-compatible and
opt-in). ^3.1 keeps the 3.1 floor the query/getDocument lease needs while
accepting compatible minors, matching the ^3.0 constraint the rest of the
ecosystem (server-ce, domains, vcs) already uses. Unblocks consumers that need
cache 3.2.0.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
chore(deps): widen utopia-php/cache constraint to ^3.1 (accept 3.2.x)
HarshMN2345 and others added 13 commits October 7, 2026 14:16
…Unique

SQLite::createIndex() let the PDOException escape unclassified, so a
unique index over duplicate rows surfaced as a raw PDOException instead
of UniqueException. It now goes through processException() like the
other SQL adapters.
…ry adapter

Each adapter must reject a unique index on a string or integer attribute
whose rows already share a value with UniqueException, and leave the
index out of the collection metadata.
…tion

fix(indexes): fail unique index creation over duplicate rows
ST_Distance(a, b) < d cannot be served by a GIST index, so radius queries
filtered every row while walking the primary key.

Without meters, distanceLessThan now leads with ST_DWithin on the geometry
column. With meters on a point column and a point value, it leads with a
degree box (&& ST_Expand) that holds every point within range on the WGS84
spheroid. Lines and polygons, and boxes that would reach a pole or the
antimeridian, keep the exact geography comparison only. The exact
ST_Distance check stays in every case, so the boundary remains exclusive.
A document stored before an attribute became required holds null for it,
and updates validate the merged document, so every update of that
document failed with "Missing required attribute". When the current
document already holds null, the attribute may stay null on update.
Creating a document without it, or clearing a stored value, still fails.
…b9ce88'

git-subtree-dir: packages/mongo
git-subtree-mainline: 6ee062c
git-subtree-split: 34ccfd6
…590bbb245'

git-subtree-dir: packages/database
git-subtree-mainline: ec342fd
git-subtree-split: 7b750be
Step A of the monorepo shape for both packages: flat src/, tests under
Utopia\Mongo\Tests\ and Utopia\Database\Tests\ with the service suites in
tests/E2E/, unit and e2e testsuites, level-max PHPStan with a baseline for
the findings they arrived with, and a Rector config that leaves released code
alone until the burn-down.

Their e2e suites reach services by compose name, and database's stop and start
containers by name, so tests/e2e.sh runs them inside the compose network on
appwrite/base instead of the removed per-repository Dockerfiles.

The suites were written for PHPUnit 9 and cache 5.0. Annotations become
attributes, addMethods/withConsecutive/onConsecutiveCalls are replaced, and
the cache test doubles accept save()'s $ttl, which otherwise fatals against
cache 5.1.
Drops utopia-php/database 7.4.1 and utopia-php/mongo 1.5.4 from the lock;
packages/ provides both through autoload and replace, which also satisfies
migration's requirement on database. ramsey/uuid and ext-mongodb, which mongo
and database required, are now root requirements.

The rule that widens the e2e database matrix compared database's lock version;
it now looks for packages/database/ or packages/mongo/ in the PR's files.
@ChiragAgg5k ChiragAgg5k added the absorb History-preserving package absorption; merge commit required label Oct 7, 2026
@luxor-code-review

luxor-code-review Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


The diff for this PR is empty: no changed files were reported and the patch file is zero lines. No review findings were produced.

Reviewed commit: 9928160

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 7, 2026
@ghost

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental change accurately documents the existing Swoole usage and introduces no new defect.

Imports Mongo and Database into packages/ and wires Appwrite to load them directly instead of installing their Composer distributions. Separates unit and E2E suites, adapts tests to PHPUnit 12 and cache compatibility, and adds package QA configurations and mirror plumbing. Updates Compose-based test launchers and CI matrix selection, and documents Swoole's role in connection-error detection.

Latest changes: The newest commit adds an ext-swoole Composer suggestion explaining its use by Connection::hasError().

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 12
File Change
.github/workflows/ci.yml Widens the integration matrix for Database or Mongo package edits and grants PR-file read access.
composer.json, composer.lock Wires package autoloading and replacements, hoists dependencies, and removes vendored distributions.
packages/database/src/**, packages/mongo/src/** Imports library source and flattens Database's source layout.
packages/database/tests/**, packages/mongo/tests/** Imports and renames tests, separates E2E suites, and adapts PHPUnit and cache compatibility.
packages/database/tests/e2e.sh, packages/mongo/tests/e2e.sh Runs E2E suites inside Compose services with targeted PHPUnit argument forwarding.
packages/database/composer.json, packages/mongo/composer.json, packages/*/phpunit.xml Defines dependencies, autoload mappings, and test tiers; documents Database's Swoole connection-detection dependency.
packages/database/docker-compose.yml, packages/database/postgres.dockerfile, packages/mongo/docker-compose.yml Provides database services and test containers mounting the root PHPUnit toolchain.
packages/database/phpstan*.neon, packages/database/rector.php, packages/mongo/phpstan*.neon, packages/mongo/rector.php Adds standalone analysis configurations and imported-code baselines.
packages/database/.github/**, packages/mongo/.github/**, packages/database/.gitignore, packages/mongo/.gitignore Adds mirror redirection workflows and package ignore rules.
packages/database/CONTRIBUTING.md Replaces obsolete testing instructions with monorepo commands and targeted adapter-suite examples.
packages/database/bin/**, packages/database/docs/**, packages/database/*.md, packages/database/LICENSE, packages/database/architecture.drawio.svg, packages/mongo/README.md Imports library tools, documentation, and assets, and adds mirror banners.
rfc/monorepo.md Records absorption progress and analysis baseline burn-down.

Reviewed the commits since 3869d5d · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Tier B · 2 blocking findings to address. Summary

Comment thread packages/database/tests/e2e.sh Resolved
Comment thread packages/mongo/composer.json Resolved
Comment thread packages/database/CONTRIBUTING.md Resolved
CI exports COMPOSE_FILE with the root override, which the packages do not
have, so exec failed before any suite ran; the runners pin the package
compose file as bin/monorepo does for up and down. mongo's Client uses
Swoole's clients unconditionally, so it now declares ext-swoole, which is
also what makes the package job install it. database's CONTRIBUTING points
at bin/monorepo and tests/e2e.sh instead of the removed in-container setup.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → chore/absorb-database (after).

Metric Before After Change
🚀 Requests/sec 177.6 190.37 🟢 +7.2%
⏱️ Latency P50 97.81 ms 90.3 ms 🟢 -7.7%
⏱️ Latency P95 231.38 ms 219.17 ms 🟢 -5.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 90.3 219.17 11,799 190.37 -12.2
Account 164.19 343.71 621 10.31 -43.43
TablesDB 86.48 171.16 6,417 105.36 -8.48
Storage 84.62 184.27 3,105 52.68 -14.19
Functions 130.57 272.5 1,656 28.93 -8.72

Top API waits (after)

API request Max wait (ms)
account.name.update 490.23
functions.create 483.58
functions.variables.update 420.92
tablesdb.rows.decrement 413.06
functions.variables.create 411.89

PHPUnit 10 and later reject instance data providers, so
testInvalidDefaultValues errored on all 16 adapter suites under the
root toolchain.
Connection::hasError() calls Swoole's DetectsLostConnections, which the
extension's bundled library provides. The package job installs only the
extensions a manifest names, so PHPStan there could not see the class;
database now suggests ext-swoole, which the job reads.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

Closing for now; this is scheduled for next week and tracked in #14255. The branch chore/absorb-database (head 9f26684, green and approved on 2026-10-08) stays as it is, so this can be reopened or re-opened from the branch after merging main in.

@ChiragAgg5k ChiragAgg5k closed this Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

absorb History-preserving package absorption; merge commit required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants