Skip to content

Commit

Permalink
feat(db): database structure for contexts
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Feb 14, 2024
1 parent 9486b2f commit 976fb81
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions lib/Migration/Version000800Date20240213123743.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2024 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @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\Tables\Migration;

use Closure;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Table;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version000800Date20240213123743 extends SimpleMigrationStep {

protected const PREFIX = 'tables_contexts_';

/**
* @throws SchemaException
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
// Introduction of Contexts tables

/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$this->haveContextTable($schema);
$this->haveContextNodeRelationTable($schema);
$this->havePageTable($schema);
$this->havePageContentTable($schema);
$this->haveNavigationTable($schema);

return $schema;
}

protected function shouldAddTable(string $tableName, ISchemaWrapper $schema): ?Table {

Check failure on line 59 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:59:80: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 59 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:59:80: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)
return !$schema->hasTable($tableName) ? $schema->createTable($tableName) : null;
}

/**
* @throws SchemaException
*/
protected function haveContextTable(ISchemaWrapper $schema): void {
if ($table = $this->shouldAddTable(self::PREFIX . 'context', $schema)) {
$table->addColumn('id', Types::INTEGER, ['notnull' => true]);

Check failure on line 68 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:68:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 68 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:68:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)
$table->addColumn('name', Types::STRING, ['notnull' => true, 'length' => 200]);

Check failure on line 69 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:69:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 69 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:69:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)
$table->addColumn('icon', Types::STRING, ['notnull' => true, 'length' => 64]);

Check failure on line 70 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:70:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 70 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:70:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)
$table->addColumn('description', Types::TEXT);

Check failure on line 71 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:71:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 71 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:71:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)
$table->addColumn('owner_id', Types::STRING, ['notnull' => true, 'length' => 64]);

Check failure on line 72 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:72:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 72 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:72:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)
$table->addColumn('owner_type', Types::STRING, ['notnull' => true, 'length' => 64]);

Check failure on line 73 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:73:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 73 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:73:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

$table->setPrimaryKey(['id']);

Check failure on line 75 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:75:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 75 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:75:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)
}
}

/**
* @throws SchemaException
*/
protected function haveContextNodeRelationTable(ISchemaWrapper $schema): void {
if ($table = $this->shouldAddTable(self::PREFIX . 'rel_context_node', $schema)) {
$table->addColumn('id', Types::INTEGER, ['notnull' => true]);

Check failure on line 84 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:84:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 84 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:84:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)
$table->addColumn('context_id', Types::INTEGER, ['notnull' => true]);

Check failure on line 85 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:85:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)

Check failure on line 85 in lib/Migration/Version000800Date20240213123743.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

UndefinedClass

lib/Migration/Version000800Date20240213123743.php:85:4: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Table does not exist (see https://psalm.dev/019)
$table->addColumn('node_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('node_type', Types::STRING, ['notnull' => true, 'length' => 50]);
$table->addColumn('permissions', Types::INTEGER, ['notnull' => true]);

$table->setPrimaryKey(['id']);
}
}

/**
* @throws SchemaException
*/
protected function havePageTable(ISchemaWrapper $schema): void {
if ($table = $this->shouldAddTable(self::PREFIX . 'page', $schema)) {
$table->addColumn('id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('context_id', Types::STRING, ['notnull' => true]);
$table->addColumn('page_type', Types::STRING, ['notnull' => true, 'length' => 32]);

$table->setPrimaryKey(['id']);
}
}

/**
* @throws SchemaException
*/
protected function havePageContentTable(ISchemaWrapper $schema): void {
if ($table = $this->shouldAddTable(self::PREFIX . 'page_content', $schema)) {
$table->addColumn('id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('page_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('node_rel_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('order', Types::INTEGER, ['notnull' => true]);

$table->setPrimaryKey(['id']);
}
}

/**
* @throws SchemaException
*/
protected function haveNavigationTable(ISchemaWrapper $schema): void {
if ($table = $this->shouldAddTable(self::PREFIX . 'navigation', $schema)) {
$table->addColumn('share_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('display_mode', Types::INTEGER, ['notnull' => true]);
$table->addColumn('user_id', Types::STRING, ['notnull' => true, 'length' => 64, 'default' => '']);

$table->setPrimaryKey(['share_id', 'user_id']);
}
}
}

0 comments on commit 976fb81

Please sign in to comment.