Skip to content

fix(db): select the SQL dialect from getDatabaseProvider(), with MariaDB named - #1226

Merged
rubenvdlinde merged 1 commit into
developmentfrom
fix/oc-1183-database-platform
Aug 12, 2026
Merged

rubenvdlinde merged 1 commit into
developmentfrom
fix/oc-1183-database-platform

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

Closes #1183.

IDBConnection::getDatabasePlatform() has been deprecated since Nextcloud 30. Three call sites used its return value to choose a SQL dialect — behaviour, not typing, which is why #1174 deferred it rather than suppressing the finding.

Tests first

The two SettingsService methods had no coverage at all, so the swap could not be made safely without them. Both new test files were written and run against the unchanged code first: three cases failed (the Postgres ones), proving they discriminate rather than passing on whatever the code happened to do.

site dialects
SettingsService::expiresExpression() DATE_ADD(…, INTERVAL ? MICROSECOND) vs … + (? || ' microseconds')::interval
SettingsService::columnExists() SHOW COLUMNS vs information_schema.columns
LegacyToRegisterMigrator JSON_SET vs jsonb_set

MariaDB is the risk, and it is named

instanceof AbstractMySQLPlatform caught MySQL and MariaDB in one branch. getDatabaseProvider() reports them as two constants. Comparing only against PLATFORM_MYSQL would send every MariaDB instance down the fallback — where it would still land on 'mysql', by accident, after logging a warning about a platform that is not unknown at all. Correct by coincidence, and no longer correct the moment the fallback changes.

testMariadbIsRecognisedRatherThanDefaulted asserts the absence of the warning, not just the dialect — the dialect alone cannot distinguish "matched the MariaDB branch" from "fell through to a fallback returning the same string". A counterpart test pins that a genuinely unknown provider still warns, so "no warning" isn't satisfiable by a mapping that never warns.

Positive control: dropping PLATFORM_MARIADB from the condition turns that test red.

The migrator's three-branch mapping is extracted to platformFor() so it can be asserted without a database — resolveStartupState() goes on to query the register and schema tables. The pre-existing LegacyToRegisterMigratorTest could never have covered this: it mocks getDatabasePlatform() with a bare stdClass and getDatabaseProvider() with 'sqlite', landing on the fallback either way. Its stale comment is corrected to say so.

Fallback direction

SettingsService's test is for Postgres, deliberately: an unrecognised platform gets DATE_ADD, not ::interval, which is PostgreSQL-only syntax nothing else can parse. Inverting the test would make every unknown platform emit SQL no other server understands. Now documented in the code and asserted.

Suppressions

  • psalm — both Doctrine\DBAL\Platforms\* entries removed; lib/ no longer names a Doctrine class anywhere.
  • phpstan — the ignores stay. Removing them surfaces 390 findings on Doctrine\DBAL\Schema\Table, which ISchemaWrapper::getTable() returns throughout the migrations. The issue's "if nothing else needs them" does not hold for those.

Verification

  • PHPUnit 2,210 green, 0 failures, 0 errors (43 excluded locally — they need openregister's real FlowConcurrency, which CI provides).
  • PHPStan [OK] No errors. Psalm No errors found!, and the three DeprecatedMethod findings are gone. phpcs clean.
  • Live Postgres, not only mocks: getDatabaseProvider() returns 'postgres' (matching PLATFORM_POSTGRES, so the new branch fires) and its platform class is PostgreSQL120Platform — a subclass of the PostgreSQLPlatform the old instanceof matched. Old and new agree on a real server.

Coverage boundary, stated plainly: MySQL and MariaDB were not exercised against live servers — no such instance is available here. They are covered by the unit tests plus getDatabaseProvider()'s own declared return contract (@return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE|self::PLATFORM_MARIADB), and both constants are handled explicitly. The issue's acceptance item asking for a real MySQL/MariaDB run is not met by this PR.

⚠️ The PHPUnit (PHP 8.3, NC stable32) leg is red on development already — the coverage ratchet cannot measure its merge base. See #1224 for the full diagnosis.

…aDB named

`IDBConnection::getDatabasePlatform()` has been deprecated since Nextcloud 30.
Three call sites used its return value to choose a SQL dialect, so this is
behaviour rather than typing — which is why #1174 deferred it rather than
suppressing the finding.

Tests first, per the plan on the issue. The two `SettingsService` methods had
NO coverage at all, so the swap could not have been made safely without them:

- `expiresExpression()` — `DATE_ADD(…, INTERVAL ? MICROSECOND)` vs
  `… + (? || ' microseconds')::interval`
- `columnExists()` — `SHOW COLUMNS` vs an `information_schema.columns` probe
- `LegacyToRegisterMigrator` — `jsonb_set` vs `JSON_SET`

MARIADB IS THE RISK, and it is now named explicitly. `instanceof
AbstractMySQLPlatform` caught MySQL and MariaDB in ONE branch, while
`getDatabaseProvider()` reports them as two distinct constants. Comparing only
against `PLATFORM_MYSQL` would send every MariaDB instance down the fallback —
where it would still land on `'mysql'`, by accident, after logging a warning
about a platform that is not unknown at all. Correct by coincidence, and no
longer correct the moment the fallback changes.

That is exactly what the tests pin. `testMariadbIsRecognisedRatherThanDefaulted`
asserts the absence of the warning, not just the dialect — the dialect alone
cannot tell "matched the MariaDB branch" from "fell through to a fallback that
returns the same string". Dropping `PLATFORM_MARIADB` from the condition turns
it red; a counterpart test pins that a genuinely unknown provider still warns.

The migrator's three-branch mapping is extracted to `platformFor()` so it can
be asserted without a database — `resolveStartupState()` goes on to query the
register and schema tables. The pre-existing `LegacyToRegisterMigratorTest`
could never have covered this: it mocks `getDatabasePlatform()` with a bare
`stdClass` AND `getDatabaseProvider()` with `'sqlite'`, so it lands on the
fallback either way. Its stale comment is corrected to say so.

`SettingsService`'s fallback direction is load-bearing and now documented: the
test is FOR Postgres, so an unrecognised platform gets `DATE_ADD` rather than
`::interval`, which is PostgreSQL-only syntax that nothing else can parse.

Psalm's two `Doctrine\DBAL\Platforms\*` suppressions are removed — `lib/` no
longer names a Doctrine class. The phpstan ignores STAY: removing them surfaces
390 findings on `Doctrine\DBAL\Schema\Table`, which `ISchemaWrapper::getTable()`
returns throughout the migrations. The issue's "if nothing else needs them"
does not hold for those.

Verified on the live Postgres instance, not only on mocks:
`getDatabaseProvider()` returns `'postgres'` (matching `PLATFORM_POSTGRES`), and
its platform class is `PostgreSQL120Platform` — a subclass of the
`PostgreSQLPlatform` the old `instanceof` matched, so old and new agree there.

Closes #1183.
@github-actions

Copy link
Copy Markdown
Contributor

Quality Report — ConductionNL/openconnector @ e3113ca

Check PHP Vue Security License Tests
lint ✅
phpcs ✅
phpmd ✅
psalm ✅
phpstan ✅
phpmetrics ✅
eslint ✅
stylelint ✅
build ✅
build ✅
check-specs ✅
test-l10n ✅
composer ✅ ✅ 152/152
npm ✅ ✅ 551/551
PHPUnit ✅
Newman ✅
Playwright ✅
Hydra gates ✅

Quality workflow — 2026-08-12 08:28 UTC

Download the full PDF report from the workflow artifacts.

@rubenvdlinde
rubenvdlinde merged commit 9f6dd2b into development Aug 12, 2026
34 checks passed
@rubenvdlinde
rubenvdlinde deleted the fix/oc-1183-database-platform branch August 12, 2026 08:38
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