Repository navigation
fix(db): select the SQL dialect from getDatabaseProvider(), with MariaDB named - #1226
Merged
Merged
Conversation
…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.
rubenvdlinde
requested review from
Rem-Dam,
SudoThijn,
WilcoLouwerse,
bbrands02,
remko48 and
rjzondervan
as code owners
August 12, 2026 08:10
Contributor
Quality Report — ConductionNL/openconnector @
|
| 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.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SettingsServicemethods 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.SettingsService::expiresExpression()DATE_ADD(…, INTERVAL ? MICROSECOND)vs… + (? || ' microseconds')::intervalSettingsService::columnExists()SHOW COLUMNSvsinformation_schema.columnsLegacyToRegisterMigratorJSON_SETvsjsonb_setMariaDB is the risk, and it is named
instanceof AbstractMySQLPlatformcaught MySQL and MariaDB in one branch.getDatabaseProvider()reports them as two constants. Comparing only againstPLATFORM_MYSQLwould 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.testMariadbIsRecognisedRatherThanDefaultedasserts 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_MARIADBfrom 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-existingLegacyToRegisterMigratorTestcould never have covered this: it mocksgetDatabasePlatform()with a barestdClassandgetDatabaseProvider()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 getsDATE_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
Doctrine\DBAL\Platforms\*entries removed;lib/no longer names a Doctrine class anywhere.Doctrine\DBAL\Schema\Table, whichISchemaWrapper::getTable()returns throughout the migrations. The issue's "if nothing else needs them" does not hold for those.Verification
FlowConcurrency, which CI provides).[OK] No errors. PsalmNo errors found!, and the threeDeprecatedMethodfindings are gone. phpcs clean.getDatabaseProvider()returns'postgres'(matchingPLATFORM_POSTGRES, so the new branch fires) and its platform class isPostgreSQL120Platform— a subclass of thePostgreSQLPlatformthe oldinstanceofmatched. Old and new agree on a real server.