Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NC update from 12.0.3 to 13.0.0 database scheme issue #8362

Closed
hubertkn opened this issue Feb 14, 2018 · 1 comment
Closed

NC update from 12.0.3 to 13.0.0 database scheme issue #8362

hubertkn opened this issue Feb 14, 2018 · 1 comment

Comments

@hubertkn
Copy link

Hello,
as I described some time ago, during updating process from version 12.0.0 to some higher version I had database schema error. Please see the following issue for more details:
#6039

As I expected, during update process from NC 12.0.3 to NC13.0.0 I had this same problem too (it must be some server configuration issue which I cannot resolve - I am not a server administrator). But in NC13 the file structure is slightly different - there is no db_structure.xml file for instance. So, in order to apply the same solution (varchar(255)->varchar(191)) I had to search all NC server files :) looking for each problematic variables like:

  • migrations
  • personal_settings
  • personal_sections
  • trusted_servers

I have found and modified the following files (content of the files is below):

  • core
    • INVALID_HASH
      • lib/private/DB/MigrationService.php
      • core/Migrations/Version13000Date20170705121758.php
      • core/Migrations/Version13000Date20170718121200.php
  • federation
    • INVALID_HASH
      • appinfo/database.xml

Then I rerun the web updater again, and ... update process was sucessfull passed. :)
Next, I replace the modified files with the originals, and rerun the code integrity check again to remove the annoying message about code integrity error.

I am writing this to help people who have similar problem with database scheme, you may close this issue.

Best regards,
Hubert

MigrationService.php (part)

private function createMigrationTable() { if ($this->migrationTableCreated) { return false; }
	$schema = new SchemaWrapper($this->connection);

	/**
	 * We drop the table when it has different columns or the definition does not
	 * match. E.g. ownCloud uses a length of 177 for app and 14 for version.
	 */
	try {
		$table = $schema->getTable('migrations');
		$columns = $table->getColumns();

		if (count($columns) === 2) {
			try {
				$column = $table->getColumn('app');
				$schemaMismatch = $column->getLength() !== 191;

				if (!$schemaMismatch) {
					$column = $table->getColumn('version');
					$schemaMismatch = $column->getLength() !== 191;
				}
			} catch (SchemaException $e) {
				// One of the columns is missing
				$schemaMismatch = true;
			}

			if (!$schemaMismatch) {
				// Table exists and schema matches: return back!
				$this->migrationTableCreated = true;
				return false;
			}
		}

		// Drop the table, when it didn't match our expectations.
		$this->connection->dropTable('migrations');

		// Recreate the schema after the table was dropped.
		$schema = new SchemaWrapper($this->connection);

	} catch (SchemaException $e) {
		// Table not found, no need to panic, we will create it.
	}

	$table = $schema->createTable('migrations');
	$table->addColumn('app', Type::STRING, ['length' => 191]);
	$table->addColumn('version', Type::STRING, ['length' => 191]);
	$table->setPrimaryKey(['app', 'version']);

	$this->connection->migrateToSchema($schema->getWrappedSchema());

	$this->migrationTableCreated = true;

	return true;
}

Version13000Date20170705121758.php & Version13000Date20170718121200.php (part)

if (!$schema->hasTable('personal_sections')) { $table = $schema->createTable('personal_sections');
		$table->addColumn('id', Type::STRING, [
			'notnull' => false,
			'length' => 64,
		]);
		$table->addColumn('class', Type::STRING, [
			'notnull' => true,
			'length' => 191,
		]);
		$table->addColumn('priority', Type::INTEGER, [
			'notnull' => true,
			'length' => 6,
			'default' => 0,
		]);

		$table->setPrimaryKey(['id'], 'personal_sections_id_index');
		$table->addUniqueIndex(['class'], 'personal_sections_class');
	}

	if (!$schema->hasTable('personal_settings')) {
		$table = $schema->createTable('personal_settings');

		$table->addColumn('id', Type::INTEGER, [
			'autoincrement' => true,
			'notnull' => true,
			'length' => 20,
		]);
		$table->addColumn('class', Type::STRING, [
			'notnull' => true,
			'length' => 191,
		]);
		$table->addColumn('section', Type::STRING, [
			'notnull' => false,
			'length' => 64,
		]);
		$table->addColumn('priority', Type::INTEGER, [
			'notnull' => true,
			'length' => 6,
			'default' => 0,
		]);

		$table->setPrimaryKey(['id'], 'personal_settings_id_index');
		$table->addUniqueIndex(['class'], 'personal_settings_class');
		$table->addIndex(['section'], 'personal_settings_section');
	}

database.xml (part)

 			<field>
 				<name>url_hash</name>
 				<type>text</type>
 				<default></default>
 				<notnull>true</notnull>
 				<length>191</length>
 				<comments>sha1 hash of the url without the protocol</comments>
 			</field>
@MorrisJobke
Copy link
Member

So, in order to apply the same solution (varchar(255)->varchar(191)) I had to search all NC server files :) looking for each problematic variables like:

We do not support changing the schema manually. You need to keep the schema as it is.

Please apply the UTF8MB4 character set first: https://docs.nextcloud.com/server/13/admin_manual/configuration_database/mysql_4byte_support.html

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

No branches or pull requests

2 participants