[Bug]: DB conversion from MySQL to PgSQL fails when migrating oc_calresources_rooms, as oc_calresources_stories isn't copied first
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
⚠️ This issue respects the following points: ⚠️
- This is a bug, not a question or a configuration/webserver/proxy issue.
- This issue is not already reported on Github OR Nextcloud Community Forum (I've searched it).
- Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
- I agree to follow Nextcloud's Code of Conduct.
Bug description
Running the command:
occ db:convert-type --all-apps pgsql user_nextcloud pgsql-prod --port=5433 db_nextcloud -vv
on an NC 31.05 instance aborts while transferring calendar data. After the schema is fully built and the first tables are transferred, the conversion stops with an error.
- oc_authtoken
72/72 [============================] 100% < 1 sec/< 1 sec
- oc_bruteforce_attempts
0 [>---------------------------] < 1 sec
- oc_calendar_appt_bookings
0 [>---------------------------] < 1 sec
- oc_calendar_appt_configs
0 [>---------------------------] < 1 sec
- oc_calendar_invitations
19/19 [============================] 100% < 1 sec/< 1 sec
- oc_calendar_reminders
693/693 [============================] 100% 7 secs/7 secs
- oc_calendar_resources
0 [>---------------------------] < 1 sec
- oc_calendar_resources_md
0 [>---------------------------] < 1 sec
- oc_calendar_rooms
5/5 [============================] 100% < 1 sec/< 1 sec
- oc_calendar_rooms_md
17/17 [============================] 100% < 1 sec/< 1 sec
- oc_calendarchanges
chunked query, 4 chunks
3512/3512 [============================] 100% 31 secs/31 secs
- oc_calendarobjects
chunked query, 2 chunks
1500/1500 [============================] 100% 16 secs/16 secs
- oc_calendarobjects_props
chunked query, 5 chunks
4545/4545 [============================] 100% 44 secs/44 secs
- oc_calendars
35/35 [============================] 100% 1 sec/1 sec
- oc_calendarsubscriptions
8/8 [============================] 100% < 1 sec/< 1 sec
- oc_calresources_buildings
1/1 [============================] 100% < 1 sec/< 1 sec
- oc_calresources_resources
0 [>---------------------------] < 1 sec
- oc_calresources_restricts
0 [>---------------------------] < 1 sec
- oc_calresources_rooms
0/5 [>---------------------------] 0% < 1 sec/< 1 sec
In ExceptionConverter.php line 50:
[Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException (7)]
An exception occurred while executing a query: SQLSTATE[23503]: Foreign key violation: 7 ERROR: insert or update on table "oc_calresources_rooms" violates foreign key constraint "fk_75864578aa5d4036"
DETAIL: Key (story_id)=(2) is not present in table "oc_calresources_stories".
Exception trace:
at /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/API/PostgreSQL/ExceptionConverter.php:50
Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter->convert() at /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php:1976
Doctrine\DBAL\Connection->handleDriverException() at /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php:1918
Doctrine\DBAL\Connection->convertExceptionDuringQuery() at /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php:1218
Doctrine\DBAL\Connection->executeStatement() at /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connections/PrimaryReadReplicaConnection.php:292
Doctrine\DBAL\Connections\PrimaryReadReplicaConnection->executeStatement() at /var/www/html/nextcloud/lib/private/DB/Connection.php:466
OC\DB\Connection->executeStatement() at /var/www/html/nextcloud/lib/private/DB/ConnectionAdapter.php:67
OC\DB\ConnectionAdapter->executeStatement() at /var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php:306
OC\DB\QueryBuilder\QueryBuilder->executeStatement() at /var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php:268
OC\DB\QueryBuilder\QueryBuilder->execute() at /var/www/html/nextcloud/core/Command/Db/ConvertType.php:355
OC\Core\Command\Db\ConvertType->copyTable() at /var/www/html/nextcloud/core/Command/Db/ConvertType.php:401
OC\Core\Command\Db\ConvertType->convertDB() at /var/www/html/nextcloud/core/Command/Db/ConvertType.php:195
OC\Core\Command\Db\ConvertType->execute() at /var/www/html/nextcloud/3rdparty/symfony/console/Command/Command.php:326
Symfony\Component\Console\Command\Command->run() at /var/www/html/nextcloud/3rdparty/symfony/console/Application.php:1078
Symfony\Component\Console\Application->doRunCommand() at /var/www/html/nextcloud/3rdparty/symfony/console/Application.php:324
Symfony\Component\Console\Application->doRun() at /var/www/html/nextcloud/3rdparty/symfony/console/Application.php:175
Symfony\Component\Console\Application->run() at /var/www/html/nextcloud/lib/private/Console/Application.php:187
OC\Console\Application->run() at /var/www/html/nextcloud/console.php:87
require_once() at /var/www/html/nextcloud/occ:33
I do see the oc_calresources_buildings table being copied, but not the oc_calresources_stories table, leading to the foreign key error.
Steps to reproduce
- NC 31.05 running on MySQL 8
- add a calendar resource building, floor and room
- migrate
Expected behavior
the oc_calresources_stories table should be copied before the oc_calresources_rooms table.
Nextcloud Server version
31
Operating system
RHEL/CentOS
PHP engine version
PHP 8.2
Web server
Apache (supported)
Database engine version
MySQL
Is this bug present after an update or on a fresh install?
Upgraded to a MAJOR version (ex. 31 to 32)
Are you using the Nextcloud Server Encryption module?
Encryption is Disabled
What user-backends are you using?
- Default user-backend (database)
- LDAP/ Active Directory
- SSO - SAML
- Other
Configuration report
List of activated Apps
Nextcloud Signing status
Nextcloud Logs
Additional info
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with core/Command/Db/ConvertType.php, especially convertDB() and copyTable(), and reproduce the reported occ db:convert-type command with calendar resource data. Trace how source tables are selected and ordered. Done means oc_calresources_stories is copied before oc_calresources_rooms and the MySQL-to-PostgreSQL migration completes without the foreign-key violation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, php, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100