Changing database from sqlite to mariadb failed

… and still happening with Nextcloud Hub 9 (30.0.2).

As a workaround I first checked the issue at fix(db): Prevent data loss by temporarily disabling `db:convert-type` · nextcloud/server@59dc6b4 · GitHub with the related bug. And patched 2 nextcloud files according to [Bug]: `occ db:convert-type` broken since `PrimaryReadReplicaConnection` support added · Issue #45257 · nextcloud/server · GitHub :

# diff lib/private/DB/ConnectionFactory.orig.php lib/private/DB/ConnectionFactory.php
111c111
< 		$connectionParams = $this->createConnectionParams('', $additionalConnectionParams);
---
> 		$connectionParams = $this->createConnectionParams('', $additionalConnectionParams, $type);
182,183c182,185
< 	public function createConnectionParams(string $configPrefix = '', array $additionalConnectionParams = []) {
< 		$type = $this->config->getValue('dbtype', 'sqlite');
---
> 	public function createConnectionParams(string $configPrefix = '', array $additionalConnectionParams = [], $type = '') {
> 		if ($type === '') {
> 			$type = $this->config->getValue('dbtype', 'sqlite');
> 		}
215c217
< 		if ($this->config->getValue('mysql.utf8mb4', false)) {
---
> 		if ($this->config->getValue('mysql.utf8mb4', false) && $type==="mysql") {
# diff core/Command/Db/ConvertType.orig.php core/Command/Db/ConvertType.php
158,160c158,160
< 		throw new \InvalidArgumentException(
< 			'This command is temporarily disabled (until the next maintenance release).'
< 		);
---
> 		// throw new \InvalidArgumentException(
> 		// 	'This command is temporarily disabled (until the next maintenance release).'
> 		// );
229c229
< 		$connectionParams = $this->connectionFactory->createConnectionParams();
---
> 		$connectionParams = $this->connectionFactory->createConnectionParams('', [], $type);

Then I installed postgresql with an empty database as I wanted to move from MariaDB to PostgreSQL:

apt install -y php8.3-pgsql postgresql
sudo -u postgres psql
# DROP DATABASE nextcloud;
# DROP USER nextcloud;
CREATE USER nextcloud WITH PASSWORD 'nextcloud';
CREATE DATABASE nextcloud TEMPLATE template0 ENCODING 'UNICODE';
ALTER DATABASE nextcloud OWNER TO nextcloud;
GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextcloud;

Conversion from MariaDB to PostgreSQL finally.
If this step fails for some db table corruption: fix the problem and repeat the last step with “DROP DATABASSE nextcloud; …”

# sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --off
sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ db:convert-type --password="nextcloud" --port=5432 pgsql nextcloud 127.0.0.1 nextcloud
1 Like