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

External storage tables are now created in a migration #26923

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions core/Migrations/Version20170111103310.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

namespace OC\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Initial DB creation for external storages
*/
class Version20170111103310 extends AbstractMigration {
/**
* @param Schema $schema
*/
public function up(Schema $schema) {
$prefix = $this->connection->getPrefix();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 $this->connection is an instance of \Doctrine\DBAL\Connection and has no method getPrefix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's the ownCloud connection. Else this PR would not work at all at setup time. Try it 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 I was kicked in the a** by @DeepDiver1975 several times for exactly that kind of magic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very aware of this - thanks for fighting me with my own weapons 🔪 .... maybe we need to come up with our own AbstractMigration class to allow proper handling of things like this .... let's keep this out of this pr for now.

if (!$schema->hasTable("${prefix}external_mounts")) {
$table = $schema->createTable("${prefix}external_mounts");
$table->addColumn('mount_id', 'bigint', [
'autoincrement' => true,
'notnull' => true,
'length' => 20,
]);
$table->addColumn('mount_point', 'string', [
'notnull' => true,
'length' => 128,
]);
$table->addColumn('storage_backend', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('auth_backend', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('priority', 'integer', [
'notnull' => true,
'length' => 4,
'default' => 100,
]);
// admin = 1, personal = 2
$table->addColumn('type', 'integer', [
'notnull' => true,
'length' => 4,
]);
$table->setPrimaryKey(['mount_id']);
}

if (!$schema->hasTable("${prefix}external_applicable")) {
$table = $schema->createTable("${prefix}external_applicable");
$table->addColumn('applicable_id', 'bigint', [
'autoincrement' => true,
'notnull' => true,
'length' => 20,
]);
// foreign key: external_mounts.mount_id
$table->addColumn('mount_id', 'bigint', [
'notnull' => true,
'length' => 20,
]);
// possible mount types: global = 1, group = 2, user = 3
$table->addColumn('type', 'integer', [
'notnull' => true,
'length' => 4,
]);
$table->addColumn('value', 'string', [
'notnull' => false,
'length' => 64,
]);
$table->setPrimaryKey(['applicable_id']);
$table->addIndex(['mount_id'], 'applicable_mount');
$table->addIndex(['type', 'value'], 'applicable_type_value');
$table->addUniqueIndex(['type', 'value', 'mount_id'], 'applicable_type_value_mount');
}

if (!$schema->hasTable("${prefix}external_config")) {
$table = $schema->createTable("${prefix}external_config");
$table->addColumn('config_id', 'bigint', [
'autoincrement' => true,
'notnull' => true,
'length' => 20,
]);
// foreign key: external_mounts.mount_id
$table->addColumn('mount_id', 'bigint', [
'notnull' => true,
'length' => 20,
]);
$table->addColumn('key', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('value', 'string', [
'notnull' => true,
'length' => 4096,
]);
$table->setPrimaryKey(['config_id']);
$table->addIndex(['mount_id'], 'config_mount');
$table->addUniqueIndex(['mount_id', 'key'], 'config_mount_key');
}

if (!$schema->hasTable("${prefix}external_options")) {
$table = $schema->createTable("${prefix}external_options");
$table->addColumn('option_id', 'bigint', [
'autoincrement' => true,
'notnull' => true,
'length' => 20,
]);
// foreign key: external_mounts.mount_id
$table->addColumn('mount_id', 'bigint', [
'notnull' => true,
'length' => 20,
]);
$table->addColumn('key', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('value', 'string', [
'notnull' => true,
'length' => 256,
]);
$table->setPrimaryKey(['option_id']);
$table->addIndex(['mount_id'], 'option_mount');
$table->addUniqueIndex(['mount_id', 'key'], 'option_mount_key');
}
}

/**
* @param Schema $schema
*/
public function down(Schema $schema) {
// this down() migration is auto-generated, please modify it to your needs

}
}
221 changes: 0 additions & 221 deletions db_structure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1884,225 +1884,4 @@

</table>

<!-- External storage definition -->
<table>
<name>*dbprefix*external_mounts</name>
<declaration>
<field>
<name>mount_id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<length>6</length>
</field>
<field>
<name>mount_point</name>
<type>text</type>
<length>128</length>
<notnull>true</notnull>
</field>
<field>
<name>storage_backend</name>
<type>text</type>
<length>64</length>
<notnull>true</notnull>
</field>
<field>
<name>auth_backend</name>
<type>text</type>
<length>64</length>
<notnull>true</notnull>
</field>
<field>
<name>priority</name>
<type>integer</type>
<default>100</default>
<length>4</length>
<notnull>true</notnull>
</field>
<!-- admin = 1, personal = 2-->
<field>
<name>type</name>
<type>integer</type>
<length>4</length>
<notnull>true</notnull>
</field>
</declaration>
</table>
<table>
<name>*dbprefix*external_applicable</name>
<declaration>
<field>
<name>applicable_id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<length>6</length>
</field>
<field>
<!--foreign key: external_mounts.mount_id-->
<name>mount_id</name>
<type>integer</type>
<notnull>true</notnull>
<length>6</length>
</field>
<field>
<!-- possible mount types: global = 1, group = 2, user = 3 -->
<name>type</name>
<type>integer</type>
<length>4</length>
<notnull>true</notnull>
</field>
<field>
<!-- user_id, group_id or null for global mounts -->
<name>value</name>
<type>text</type>
<length>64</length>
</field>

<index>
<name>applicable_mount</name>
<field>
<name>mount_id</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>applicable_type_value</name>
<field>
<name>type</name>
<sorting>ascending</sorting>
</field>
<field>
<name>value</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>applicable_type_value_mount</name>
<unique>true</unique>
<field>
<name>type</name>
<sorting>ascending</sorting>
</field>
<field>
<name>value</name>
<sorting>ascending</sorting>
</field>
<field>
<name>mount_id</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>

<table>
<name>*dbprefix*external_config</name>
<declaration>
<field>
<name>config_id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<length>6</length>
</field>
<field>
<!--foreign key: external_mounts.mount_id-->
<name>mount_id</name>
<type>integer</type>
<notnull>true</notnull>
<length>6</length>
</field>
<field>
<name>key</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>value</name>
<type>text</type>
<notnull>true</notnull>
<length>4096</length>
</field>

<index>
<name>config_mount</name>
<field>
<name>mount_id</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>config_mount_key</name>
<unique>true</unique>
<field>
<name>mount_id</name>
<sorting>ascending</sorting>
</field>
<field>
<name>key</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>

<table>
<name>*dbprefix*external_options</name>
<declaration>
<field>
<name>option_id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<length>6</length>
</field>
<field>
<!--foreign key: external_mounts.mount_id-->
<name>mount_id</name>
<type>integer</type>
<notnull>true</notnull>
<length>6</length>
</field>
<field>
<name>key</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>value</name>
<type>text</type>
<notnull>true</notnull>
<length>256</length>
</field>

<index>
<name>option_mount</name>
<field>
<name>mount_id</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>option_mount_key</name>
<unique>true</unique>
<field>
<name>mount_id</name>
<sorting>ascending</sorting>
</field>
<field>
<name>key</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>

</database>
4 changes: 4 additions & 0 deletions lib/private/DB/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public function getDefaultConnectionParams($type) {
\PDO::MYSQL_ATTR_FOUND_ROWS => true,
];
}

// set default table creation options
$result['defaultTableOptions'] = ['collate' => 'utf8_bin'];

return $result;
}

Expand Down
1 change: 1 addition & 0 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MigrationService {
* @param string $appName
* @param IDBConnection $connection
* @return Configuration
* @throws \Exception
*/
public function buildConfiguration($appName, $connection) {
if ($appName === 'core') {
Expand Down