Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-11-13 13:18:52 +0300
committerJulius Härtl <jus@bitgrid.net>2020-11-13 17:31:57 +0300
commit22a29a06cc5ed8f3c7501903c61998af286e0580 (patch)
tree547e68b704055cdecbc5c24950a6076f76a40ad4 /lib
parentf7296a4861aaff8d5736609e6eed3a7206995808 (diff)
Add command to migrate tables to bigint
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/ConvertToBigInt.php115
-rw-r--r--lib/Migration/Version2060Date20200302131958.php28
-rw-r--r--lib/Migration/Version30704Date20200626072306.php2
3 files changed, 130 insertions, 15 deletions
diff --git a/lib/Command/ConvertToBigInt.php b/lib/Command/ConvertToBigInt.php
new file mode 100644
index 00000000..5561ce5c
--- /dev/null
+++ b/lib/Command/ConvertToBigInt.php
@@ -0,0 +1,115 @@
+<?php
+/**
+ * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\RichDocuments\Command;
+
+use Doctrine\DBAL\Platforms\SqlitePlatform;
+use Doctrine\DBAL\Types\Type;
+use Doctrine\DBAL\Types\Types;
+use OC\DB\SchemaWrapper;
+use OCP\IDBConnection;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Question\ConfirmationQuestion;
+
+class ConvertToBigInt extends Command {
+
+ /** @var IDBConnection */
+ private $connection;
+
+ /**
+ * @param IDBConnection $connection
+ */
+ public function __construct(IDBConnection $connection) {
+ $this->connection = $connection;
+ parent::__construct();
+ }
+
+ protected function configure() {
+ $this
+ ->setName('richdocuments:convert-bigint')
+ ->setDescription('Convert the ID columns of the richdocuments tables to BigInt');
+ }
+
+ protected function getColumnsByTable() {
+ return [
+ 'richdocuments_wopi' => ['id', 'fileid', 'version', 'template_id', 'template_destination', 'expiry'],
+ 'richdocuments_direct' => ['id', 'fileid', 'template_id', 'template_destination', 'timestamp'],
+ 'richdocuments_assets' => ['id', 'fileid', 'timestamp'],
+ ];
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int {
+ $schema = new SchemaWrapper($this->connection);
+ $isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform;
+ $updates = [];
+
+ $tables = $this->getColumnsByTable();
+ foreach ($tables as $tableName => $columns) {
+ if (!$schema->hasTable($tableName)) {
+ continue;
+ }
+
+ $table = $schema->getTable($tableName);
+
+ foreach ($columns as $columnName) {
+ $column = $table->getColumn($columnName);
+ $isAutoIncrement = $column->getAutoincrement();
+ $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
+ if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) {
+ $column->setType(Type::getType(Types::BIGINT));
+ $column->setOptions(['length' => 20]);
+ $column->setUnsigned(true);
+
+ $updates[] = '* ' . $tableName . '.' . $columnName;
+ }
+ }
+ }
+
+ if (empty($updates)) {
+ $output->writeln('<info>All tables already up to date!</info>');
+ return 0;
+ }
+
+ $output->writeln('<comment>Following columns will be updated:</comment>');
+ $output->writeln('');
+ $output->writeln($updates);
+ $output->writeln('');
+ $output->writeln('<comment>This can take up to hours, depending on the number of Collabora WOPI tokens in your instance!</comment>');
+
+ if ($input->isInteractive()) {
+ $helper = $this->getHelper('question');
+ $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false);
+
+ if (!$helper->ask($input, $output, $question)) {
+ return 1;
+ }
+ }
+
+ $this->connection->migrateToSchema($schema->getWrappedSchema());
+
+ return 0;
+ }
+}
diff --git a/lib/Migration/Version2060Date20200302131958.php b/lib/Migration/Version2060Date20200302131958.php
index d2b9eb17..567a7f2b 100644
--- a/lib/Migration/Version2060Date20200302131958.php
+++ b/lib/Migration/Version2060Date20200302131958.php
@@ -29,7 +29,7 @@ class Version2060Date20200302131958 extends SimpleMigrationStep {
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
- 'length' => 4,
+ 'length' => 20,
'unsigned' => true,
]);
$table->addColumn('owner_uid', 'string', [
@@ -46,12 +46,12 @@ class Version2060Date20200302131958 extends SimpleMigrationStep {
]);
$table->addColumn('fileid', 'integer', [
'notnull' => true,
- 'length' => 4,
+ 'length' => 20,
]);
$table->addColumn('version', 'integer', [
//'notnull' => true,
'notnull' => false,
- 'length' => 4,
+ 'length' => 20,
'default' => 0,
]);
$table->addColumn('canwrite', 'boolean', [
@@ -71,16 +71,16 @@ class Version2060Date20200302131958 extends SimpleMigrationStep {
]);
$table->addColumn('expiry', 'integer', [
'notnull' => false,
- 'length' => 4,
+ 'length' => 20,
'unsigned' => true,
]);
$table->addColumn('template_destination', 'integer', [
'notnull' => false,
- 'length' => 4,
+ 'length' => 20,
]);
$table->addColumn('template_id', 'integer', [
'notnull' => false,
- 'length' => 4,
+ 'length' => 20,
]);
$table->addColumn('hide_download', 'boolean', [
// 'notnull' => true,
@@ -117,7 +117,7 @@ class Version2060Date20200302131958 extends SimpleMigrationStep {
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
- 'length' => 4,
+ 'length' => 20,
'unsigned' => true,
]);
$table->addColumn('token', 'string', [
@@ -130,22 +130,22 @@ class Version2060Date20200302131958 extends SimpleMigrationStep {
]);
$table->addColumn('fileid', 'integer', [
'notnull' => true,
- 'length' => 4,
+ 'length' => 20,
]);
$table->addColumn('timestamp', 'integer', [
// 'notnull' => true,
'notnull' => false,
- 'length' => 4,
+ 'length' => 20,
'default' => 0,
'unsigned' => true,
]);
$table->addColumn('template_destination', 'integer', [
'notnull' => false,
- 'length' => 4,
+ 'length' => 20,
]);
$table->addColumn('template_id', 'integer', [
'notnull' => false,
- 'length' => 4,
+ 'length' => 20,
]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['token'], 'rd_direct_token_idx');
@@ -157,7 +157,7 @@ class Version2060Date20200302131958 extends SimpleMigrationStep {
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
- 'length' => 4,
+ 'length' => 20,
'unsigned' => true,
]);
$table->addColumn('uid', 'string', [
@@ -166,7 +166,7 @@ class Version2060Date20200302131958 extends SimpleMigrationStep {
]);
$table->addColumn('fileid', 'integer', [
'notnull' => true,
- 'length' => 4,
+ 'length' => 20,
]);
$table->addColumn('token', 'string', [
'notnull' => false,
@@ -175,7 +175,7 @@ class Version2060Date20200302131958 extends SimpleMigrationStep {
$table->addColumn('timestamp', 'integer', [
// 'notnull' => true,
'notnull' => false,
- 'length' => 4,
+ 'length' => 20,
'default' => 0,
'unsigned' => true,
]);
diff --git a/lib/Migration/Version30704Date20200626072306.php b/lib/Migration/Version30704Date20200626072306.php
index 01db590c..bb9efa40 100644
--- a/lib/Migration/Version30704Date20200626072306.php
+++ b/lib/Migration/Version30704Date20200626072306.php
@@ -26,7 +26,7 @@ class Version30704Date20200626072306 extends SimpleMigrationStep {
if (!$table->hasColumn('template_id')) {
$table->addColumn('template_id', 'integer', [
'notnull' => false,
- 'length' => 4,
+ 'length' => 20,
]);
}