From 9cb44594c875936928531848dbb8670eb42ef99e Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 29 Nov 2016 15:00:14 +0100 Subject: [PATCH 1/2] Initialize DB with migration --- appinfo/Migrations/Version20161209151129.php | 71 ++++++++++++++++++++ appinfo/app.php | 21 ++++++ appinfo/info.xml | 1 + 3 files changed, 93 insertions(+) create mode 100644 appinfo/Migrations/Version20161209151129.php create mode 100644 appinfo/app.php diff --git a/appinfo/Migrations/Version20161209151129.php b/appinfo/Migrations/Version20161209151129.php new file mode 100644 index 00000000..72d0d07c --- /dev/null +++ b/appinfo/Migrations/Version20161209151129.php @@ -0,0 +1,71 @@ +createGroupsTable($schema); + $this->createMembersTable($schema); + } + + private function createGroupsTable(Schema $schema) { + $prefix = $this->connection->getPrefix(); + $table = $schema->createTable("${prefix}custom_group"); + $table->addColumn('group_id', 'integer', [ + 'autoincrement' => true, + 'unsigned' => true, + 'length' => 4, + ]); + $table->addColumn('uri', 'text', [ + 'length' => 255, + 'notnull' => true, + ]); + $table->addColumn('display_name', 'text', [ + 'length' => 64, + 'notnull' => true, + ]); + // TODO: find how to set sort to ascending + $table->addUniqueIndex(['uri'], 'cg_uri_index', [ + // Doctrine ignores the length, MySQL is not happy + 'length' => 255 + ]); + $table->setPrimaryKey(['group_id']); + } + + private function createMembersTable(Schema $schema) { + $prefix = $this->connection->getPrefix(); + $table = $schema->createTable("${prefix}custom_group_member"); + $table->addColumn('group_id', 'integer', [ + 'autoincrement' => true, + 'unsigned' => true, + 'length' => 4, + ]); + $table->addColumn('user_id', 'text', [ + 'length' => 64, + 'notnull' => true, + ]); + $table->addColumn('is_admin', 'integer', [ + 'length' => 4, + 'notnull' => true, + 'default' => 0, + ]); + $table->setPrimaryKey(['group_id', 'user_id']); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) { + $schema->dropTable('custom_group_member'); + $schema->dropTable('custom_group'); + } +} diff --git a/appinfo/app.php b/appinfo/app.php new file mode 100644 index 00000000..58d1db86 --- /dev/null +++ b/appinfo/app.php @@ -0,0 +1,21 @@ + + * + * @copyright Copyright (c) 2016, ownCloud GmbH. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + diff --git a/appinfo/info.xml b/appinfo/info.xml index 42b44810..99941f68 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -12,6 +12,7 @@ + true From eac1afbd59742f36fb6d1222b43f1af88ca7f847 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 9 Dec 2016 18:07:02 +0100 Subject: [PATCH 2/2] Use "string" instead of "text" for the index to work correctly with Mysql --- appinfo/Migrations/Version20161209151129.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/appinfo/Migrations/Version20161209151129.php b/appinfo/Migrations/Version20161209151129.php index 72d0d07c..989951c1 100644 --- a/appinfo/Migrations/Version20161209151129.php +++ b/appinfo/Migrations/Version20161209151129.php @@ -25,19 +25,16 @@ private function createGroupsTable(Schema $schema) { 'unsigned' => true, 'length' => 4, ]); - $table->addColumn('uri', 'text', [ + $table->addColumn('uri', 'string', [ 'length' => 255, 'notnull' => true, ]); - $table->addColumn('display_name', 'text', [ + $table->addColumn('display_name', 'string', [ 'length' => 64, 'notnull' => true, ]); // TODO: find how to set sort to ascending - $table->addUniqueIndex(['uri'], 'cg_uri_index', [ - // Doctrine ignores the length, MySQL is not happy - 'length' => 255 - ]); + $table->addUniqueIndex(['uri'], 'cg_uri_index'); $table->setPrimaryKey(['group_id']); } @@ -49,7 +46,7 @@ private function createMembersTable(Schema $schema) { 'unsigned' => true, 'length' => 4, ]); - $table->addColumn('user_id', 'text', [ + $table->addColumn('user_id', 'string', [ 'length' => 64, 'notnull' => true, ]);