Skip to content

fix(appconfig,userconfig): restore pre-migration fallback for ownCloud migration#59677

Merged
miaulalala merged 1 commit into
masterfrom
fix/57340/owncloud-migration-appconfig-userconfig
May 28, 2026
Merged

fix(appconfig,userconfig): restore pre-migration fallback for ownCloud migration#59677
miaulalala merged 1 commit into
masterfrom
fix/57340/owncloud-migration-appconfig-userconfig

Conversation

@miaulalala
Copy link
Copy Markdown
Contributor

@miaulalala miaulalala commented Apr 16, 2026

Summary

ownCloud → Nextcloud migration broke in NC31+ because AppConfig and UserConfig unconditionally query columns (type, lazy, flags, indexed) that were added by Nextcloud and don't exist in ownCloud's database schema. These columns are only created by migration steps that can't run until the app config system is already functional — a chicken-and-egg problem that caused the entire upgrade to fail with an invalid field name error.

Root cause: A pre-existing try/catch fallback in AppConfig::loadConfig() was removed in a572a5c without a replacement. UserConfig never had an equivalent guard.

Fix: Restore the fallback pattern in both classes:

  • On first loadConfig() call, if a DBException with REASON_INVALID_FIELD_NAME is thrown, set $migrationCompleted = false and retry selecting only the columns present in ownCloud's schema (appid, configkey, configvalue / userid)
  • When $migrationCompleted = false, INSERT and UPDATE statements also omit the NC-only columns (type, lazy, flags, indexed) so writes don't fail either
  • All other exceptions are re-thrown unchanged

This allows the migration infrastructure to boot successfully so the schema migration steps can run and add the missing columns.

Fixes: #57340

Test plan

  • AppConfigMigrationFallbackTest — unit tests for AppConfig:
    • fallback triggered on REASON_INVALID_FIELD_NAME
    • non-matching exceptions are re-thrown
    • INSERT omits NC-only columns in fallback mode
  • UserConfigMigrationFallbackTest — same three cases for UserConfig

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

AI-Assisted-By: Claude Sonnet 4.6 noreply@anthropic.com

@miaulalala miaulalala added this to the Nextcloud 34 milestone Apr 16, 2026
@miaulalala miaulalala self-assigned this Apr 16, 2026
@miaulalala miaulalala marked this pull request as ready for review May 19, 2026 11:55
@miaulalala miaulalala requested a review from a team as a code owner May 19, 2026 11:55
@miaulalala miaulalala requested review from Altahrim, ArtificialOwl, CarlSchwan and leftybournes and removed request for a team May 19, 2026 11:55
@miaulalala miaulalala modified the milestones: Nextcloud 34, Nextcloud 35 May 19, 2026
@miaulalala miaulalala force-pushed the fix/57340/owncloud-migration-appconfig-userconfig branch from 50e03d9 to a4d8e29 Compare May 19, 2026 12:03
@susnux susnux added the bug label May 19, 2026
@Robert-Riedl
Copy link
Copy Markdown

This works ! Please merge it soon, if possible :)

@miaulalala miaulalala requested a review from sorbaugh May 26, 2026 15:28
@miaulalala
Copy link
Copy Markdown
Contributor Author

/backport to stable34

@miaulalala
Copy link
Copy Markdown
Contributor Author

/backport to stable33

@miaulalala
Copy link
Copy Markdown
Contributor Author

/backport to stable32

@miaulalala miaulalala requested a review from blizzz May 27, 2026 12:57
Comment thread lib/private/Config/UserConfig.php
Comment thread lib/private/AppConfig.php
@miaulalala miaulalala force-pushed the fix/57340/owncloud-migration-appconfig-userconfig branch 2 times, most recently from 4aca08b to 343ceb5 Compare May 27, 2026 16:10
@miaulalala miaulalala enabled auto-merge May 27, 2026 16:15
…d migration

AppConfig and UserConfig unconditionally queried NC-only columns (type,
lazy, flags, indexed) that don't exist in ownCloud's database schema,
breaking ownCloud → Nextcloud upgrades entirely before the schema
migration steps could run.

Restore the fallback pattern in both classes: on first loadConfig() call,
if a DBException with REASON_INVALID_FIELD_NAME is thrown, set
$migrationCompleted = false and retry selecting only the columns present
in ownCloud's schema. INSERT and UPDATE statements also omit NC-only
columns when $migrationCompleted is false.

The catch block also guards against infinite recursion: if $migrationCompleted
is already false when the exception fires, the exception is re-thrown
instead of triggering another recursive call.

Fixes: #57340

Signed-off-by: Anna Larch <anna@nextcloud.com>
AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@miaulalala miaulalala force-pushed the fix/57340/owncloud-migration-appconfig-userconfig branch from 343ceb5 to b2c9273 Compare May 28, 2026 07:46
@miaulalala miaulalala merged commit e290384 into master May 28, 2026
252 of 272 checks passed
@miaulalala miaulalala deleted the fix/57340/owncloud-migration-appconfig-userconfig branch May 28, 2026 18:42
@MichaIng MichaIng added the pending documentation This pull request needs an associated documentation update label May 28, 2026
@MichaIng
Copy link
Copy Markdown
Member

MichaIng commented May 28, 2026

Awesome @miaulalala, I highly appreciate the efforts to restore a seamless ownCloud 10 => Nextcloud migration! ❤️

The respective documentation page needs to be updated, to reflect a supported upgrade path to latest Nextcloud, right? https://docs.nextcloud.com/server/latest/admin_manual/maintenance/migrating_owncloud.html

I can open a PR, if confirmed.

EDIT: Ah, I did not think about the conflicting PHP version requirements, which would at least require some explanation in the docs. The preferred migration path IMO would be still to latest Nextcloud directly. But one needs to upgrade PHP first.

@miaulalala
Copy link
Copy Markdown
Contributor Author

Awesome @miaulalala, I highly appreciate the efforts to restore a seamless ownCloud 10 => Nextcloud migration! ❤️

The respective documentation page needs to be updated, to reflect a supported upgrade path to latest Nextcloud, right? docs.nextcloud.com/server/latest/admin_manual/maintenance/migrating_owncloud.html

I can open a PR, if confirmed.

EDIT: Ah, I did not think about the conflicting PHP version requirements, which would at least require some explanation in the docs. The preferred migration path IMO would be still to latest Nextcloud directly. But one needs to upgrade PHP first.

If you want to give the documentation a shot, that would be lovely! Ping me on the PR and if you're unsure about anything, I can help you or do the rest, whatever you prefer. I appreciate it 😃

@MichaIng
Copy link
Copy Markdown
Member

MichaIng commented May 30, 2026

I opened nextcloud/documentation#15048, and indeed there are some open questions. It is currently half way: migration to latest Nextcloud, but still keeping the table and conditional migration steps, in case latest Nextcloud removes support for migration from older ownCloud versions at some point. But IMO, in that case, upgrading from that ownCloud version should not be supported (and hence not documented) at all. No one will and can guarantee it works, and admins should always be able to upgrade to a supported ownCloud version first. I discussed this in the PR, anyone please let me know what you think, as the page could be simplified/compacted in case.

MichaIng added a commit to nextcloud/documentation that referenced this pull request May 30, 2026
nextcloud/server#59677 fixes direct migration from ownCloud to latest Nextcloud.

It does not change something about the fact that latest ownCloud 10 does not support any PHP version supported by Nextcloud. But while keeping PHP 7.4 during the migration to Nextcloud 25 makes it easier to revert to ownCloud in case of an issue, that path requires manually patching `version.php`, a lot of major version upgrades, and intermediate PHP upgrade steps. Overall the efforts are a lot higher than migration directly to latest Nextcloud, and upgrade PHP only once prior to that.

Another reason to prefer direct migration to latest Nextcloud is, that Nextcloud 25 migrations are not maintained anymore. There is hence a chance that some recent ownCloud 10 version introduces a change that causes a major or subtil issue during the migration, that is fixed only in Nextcloud versions which are not EOL.

The migration steps have been adjusted to reflect the direct migration path to the upcoming Nextcloud 34.0.0.

The table itself, to in case list different migration paths for different ownCloud versions, has been left in place, including the optional/conditional migration steps to further upgrade Nextcloud and in case PHP afterwards. However, to reduce maintenance efforts and simplify/clarify things, I'd vote for removing support for migration to any older Nextcloud versions entirely, and remove the target version and post-migration upgrade steps from the docs. Once latest Nextcloud removes support for migrations from ownCloud 10.13.x, it is probably better to simply remove this migration path from the docs, and require admins to upgrade ownCloud first. IMO, keeping support for (and documenting) migrations to Nextcloud versions, which themselves are not supported, and hence do not get possibly needed fixes for migration scripts and `version.php`, does not make sense.

Let me know if you agree to the last point, then I'll adjust the commit accordingly.

Signed-off-by: MichaIng <micha@dietpi.com>

Signed-off-by: MichaIng <micha@dietpi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Migration from ownCloud not possible since NC31

6 participants