stabilize database

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
master
Maxence Lange 2022-11-18 14:31:53 -01:00
rodzic 9cb3b7e886
commit 7da94393dc
9 zmienionych plików z 242 dodań i 986 usunięć

Wyświetl plik

@ -77,7 +77,7 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->select(
'ca.nid', 'ca.id', 'ca.account', 'ca.following', 'ca.followers', 'ca.inbox', 'ca.shared_inbox',
'ca.id', 'ca.account', 'ca.following', 'ca.followers', 'ca.inbox', 'ca.shared_inbox',
'ca.outbox', 'ca.featured', 'ca.url', 'ca.type', 'ca.preferred_username', 'ca.name', 'ca.summary',
'ca.public_key', 'ca.local', 'ca.details', 'ca.source', 'ca.creation'
)

Wyświetl plik

@ -48,6 +48,7 @@ use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IURLGenerator;
use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@ -56,26 +57,26 @@ use Psr\Log\LoggerInterface;
* @package OCA\Social\Db
*/
class CoreRequestBuilder {
public const TABLE_REQUEST_QUEUE = 'social_3_req_queue';
public const TABLE_INSTANCE = 'social_3_instance';
public const TABLE_REQUEST_QUEUE = 'social_req_queue';
public const TABLE_INSTANCE = 'social_instance';
public const TABLE_ACTORS = 'social_3_actor';
public const TABLE_STREAM = 'social_3_stream';
public const TABLE_STREAM_DEST = 'social_3_stream_dest';
public const TABLE_STREAM_TAGS = 'social_3_stream_tag';
public const TABLE_STREAM_QUEUE = 'social_3_stream_queue';
public const TABLE_STREAM_ACTIONS = 'social_3_stream_act';
public const TABLE_ACTORS = 'social_actor';
public const TABLE_STREAM = 'social_stream';
public const TABLE_STREAM_DEST = 'social_stream_dest';
public const TABLE_STREAM_TAGS = 'social_stream_tag';
public const TABLE_STREAM_QUEUE = 'social_stream_queue';
public const TABLE_STREAM_ACTIONS = 'social_stream_act';
public const TABLE_HASHTAGS = 'social_3_hashtag';
public const TABLE_FOLLOWS = 'social_3_follow';
public const TABLE_ACTIONS = 'social_3_action';
public const TABLE_HASHTAGS = 'social_hashtag';
public const TABLE_FOLLOWS = 'social_follow';
public const TABLE_ACTIONS = 'social_action';
public const TABLE_CACHE_ACTORS = 'social_3_cache_actor';
public const TABLE_CACHE_DOCUMENTS = 'social_3_cache_doc';
public const TABLE_CACHE_ACTORS = 'social_cache_actor';
public const TABLE_CACHE_DOCUMENTS = 'social_cache_doc';
public const TABLE_CLIENT = 'social_3_client';
public const TABLE_CLIENT_AUTH = 'social_3_client_auth';
public const TABLE_CLIENT_TOKEN = 'social_3_client_token';
public const TABLE_CLIENT = 'social_client';
public const TABLE_CLIENT_AUTH = 'social_client_auth';
public const TABLE_CLIENT_TOKEN = 'social_client_token';
private array $tables = [
@ -105,7 +106,10 @@ class CoreRequestBuilder {
protected ?string $defaultSelectAlias = null;
public function __construct(
IDBConnection $connection, LoggerInterface $logger, IURLGenerator $urlGenerator, ConfigService $configService,
IDBConnection $connection,
LoggerInterface $logger,
IURLGenerator $urlGenerator,
ConfigService $configService,
MiscService $miscService
) {
$this->dbConnection = $connection;
@ -736,8 +740,7 @@ class CoreRequestBuilder {
$pf = (($alias === '') ? $this->defaultSelectAlias : $alias);
$qb->from(self::TABLE_CACHE_ACTORS, $pf);
$qb->selectAlias($pf . '.nid', 'cacheactor_nid')
->selectAlias($pf . '.id', 'cacheactor_id')
$qb->selectAlias($pf . '.id', 'cacheactor_id')
->selectAlias($pf . '.type', 'cacheactor_type')
->selectAlias($pf . '.account', 'cacheactor_account')
->selectAlias($pf . '.following', 'cacheactor_following')
@ -777,8 +780,7 @@ class CoreRequestBuilder {
$pf = ($alias === '') ? $this->defaultSelectAlias : $alias;
$qb->selectAlias('ca.nid', 'cacheactor_nid')
->selectAlias('ca.id', 'cacheactor_id')
$qb->selectAlias('ca.id', 'cacheactor_id')
->selectAlias('ca.type', 'cacheactor_type')
->selectAlias('ca.account', 'cacheactor_account')
->selectAlias('ca.following', 'cacheactor_following')
@ -1129,7 +1131,7 @@ class CoreRequestBuilder {
*/
public function emptyAll() {
/** @var ISchemaWrapper|SchemaWrapper $schema */
$schema = new SchemaWrapper($this->dbConnection);
$schema = new SchemaWrapper(Server::get(OC\DB\Connection::class));
foreach ($this->tables as $table) {
if ($schema->hasTable($table)) {
$qb = $this->dbConnection->getQueryBuilder();
@ -1145,7 +1147,7 @@ class CoreRequestBuilder {
*/
public function uninstallSocialTables() {
/** @var ISchemaWrapper|SchemaWrapper $schema */
$schema = new SchemaWrapper($this->dbConnection);
$schema = new SchemaWrapper(Server::get(OC\DB\Connection::class));
foreach ($this->tables as $table) {
if ($schema->hasTable($table)) {
$schema->dropTable($table);

Wyświetl plik

@ -108,8 +108,7 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
$this->from(CoreRequestBuilder::TABLE_CACHE_ACTORS, $pf);
}
$this->selectAlias($pf . '.nid', 'cacheactor_nid')
->selectAlias($pf . '.id', 'cacheactor_id')
$this->selectAlias($pf . '.id', 'cacheactor_id')
->selectAlias($pf . '.type', 'cacheactor_type')
->selectAlias($pf . '.account', 'cacheactor_account')
->selectAlias($pf . '.following', 'cacheactor_following')

Wyświetl plik

@ -1,74 +0,0 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @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\Social\Migration;
use OCA\Social\Service\CheckService;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
/**
* Class CheckInstallation
*
* @package OCA\Social\Migration
*/
class CheckInstallation implements IRepairStep {
protected CheckService $checkService;
/**
* CheckInstallation constructor.
*
* @param CheckService $checkService
*/
public function __construct(CheckService $checkService) {
$this->checkService = $checkService;
}
/**
* Returns the step's name
*
* @return string
* @since 9.1.0
*/
public function getName() {
return 'Check the installation of the Social app.';
}
/**
* @param IOutput $output
*/
public function run(IOutput $output) {
$this->checkService->checkInstallationStatus(true);
}
}

Wyświetl plik

@ -1,96 +0,0 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @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\Social\Migration;
use Closure;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\SchemaException;
use Exception;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
* Class Version0003Date20200823023910
*
* @package OCA\Social\Migration
*/
class Version0003Date20200823023900 extends SimpleMigrationStep {
private IDBConnection $connection;
/**
* @param IDBConnection $connection
*/
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @return ISchemaWrapper
* @throws SchemaException
* @throws DBALException
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if ($schema->hasTable('social_3_cache_actor')) {
$table = $schema->getTable('social_3_cache_actor');
if ($table->hasPrimaryKey()) {
$kc = $table->getPrimaryKeyColumns();
if (count($kc) === 1 && $kc[0] === 'id_prim') {
$table->dropPrimaryKey();
}
}
}
return $schema;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @throws Exception
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}
}

Wyświetl plik

@ -1,451 +0,0 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @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\Social\Migration;
use Closure;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Types\Type;
use Exception;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
* Class Version0003Date20200823023911
*
* @package OCA\Social\Migration
*/
class Version0003Date20200823023911 extends SimpleMigrationStep {
private IDBConnection $connection;
/**
* @param IDBConnection $connection
*/
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @return ISchemaWrapper
* @throws SchemaException
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options
): ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$this->fixStreamNid($schema);
$this->fixCacheActorNid($schema);
$this->createClient($schema);
$this->createInstance($schema);
$this->addChunkToTable($schema, 'social_3_stream', '');
$this->addChunkToTable($schema, 'social_3_stream_act', '_act');
$this->addChunkToTable($schema, 'social_3_stream_dest', '_dest');
return $schema;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @throws Exception
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
$qb = $this->connection->getQueryBuilder();
$qb->select('*')
->from('social_3_stream')
->orderBy('creation', 'asc');
$result = $qb->execute();
$nid = 0;
while ($row = $result->fetch()) {
$nid++;
if (is_int($row['nid']) and $row['nid'] > 0) {
continue;
}
$update = $this->connection->getQueryBuilder();
$expr = $update->expr();
$update->update('social_3_stream');
$update->set('nid', $update->createNamedParameter($nid));
$update->where($expr->eq('id_prim', $update->createNamedParameter($row['id_prim'])));
$update->execute();
}
}
/**
* @param ISchemaWrapper $schema
*/
private function fixStreamNid(ISchemaWrapper $schema) {
try {
$table = $schema->getTable('social_3_stream');
} catch (SchemaException $e) {
return;
}
if ($table->hasColumn('nid')) {
return;
}
$table->addColumn(
'nid', 'bigint',
[
'length' => 11,
'unsigned' => true,
'notnull' => false,
]
);
}
/**
* @param ISchemaWrapper $schema
*/
private function fixCacheActorNid(ISchemaWrapper $schema) {
try {
$table = $schema->getTable('social_3_cache_actor');
} catch (SchemaException $e) {
return;
}
if ($table->hasColumn('nid')) {
return;
}
$table->addColumn(
'nid', 'bigint',
[
'autoincrement' => true,
'length' => 11,
'unsigned' => true,
'customSchemaOptions' => [
'unique' => true
]
]
);
$table->addUniqueIndex(['id_prim']);
}
/**
* @param ISchemaWrapper $schema
*/
private function createClient(ISchemaWrapper $schema) {
if ($schema->hasTable('social_3_client')) {
return;
}
$table = $schema->createTable('social_3_client');
$table->addColumn(
'id', 'integer',
[
'autoincrement' => true,
'notnull' => true,
'length' => 7,
'unsigned' => true,
]
);
$table->addColumn(
'app_name', 'string',
[
'notnull' => false,
'length' => 127,
'default' => ''
]
);
$table->addColumn(
'app_website', 'string',
[
'notnull' => false,
'length' => 255,
'default' => ''
]
);
$table->addColumn(
'app_redirect_uris', 'text',
[
'notnull' => false,
'default' => ''
]
);
$table->addColumn(
'app_client_id', 'string',
[
'notnull' => false,
'length' => 63,
'default' => ''
]
);
$table->addColumn(
'app_client_secret', 'string',
[
'notnull' => false,
'length' => 63,
'default' => ''
]
);
$table->addColumn(
'app_scopes', 'text',
[
'notnull' => false
]
);
$table->addColumn(
'auth_scopes', 'text',
[
'notnull' => false
]
);
$table->addColumn(
'auth_account', 'string',
[
'notnull' => false,
'length' => 127,
'default' => ''
]
);
$table->addColumn(
'auth_user_id', 'string',
[
'notnull' => false,
'length' => 127,
'default' => ''
]
);
$table->addColumn(
'auth_code', 'string',
[
'notnull' => false,
'length' => 127,
'default' => ''
]
);
$table->addColumn(
'token', 'string',
[
'notnull' => false,
'length' => 127,
'default' => ''
]
);
$table->addColumn(
'last_update', 'datetime',
[
'notnull' => false,
]
);
$table->addColumn(
'creation', 'datetime',
[
'notnull' => false,
]
);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['auth_code', 'token', 'app_client_id', 'app_client_secret']);
}
/**
* @param ISchemaWrapper $schema
*/
private function createInstance(ISchemaWrapper $schema) {
if ($schema->hasTable('social_3_instance')) {
return;
}
$table = $schema->createTable('social_3_instance');
$table->addColumn(
'local', 'smallint',
[
'notnull' => false,
'length' => 1,
'default' => 0,
'unsigned' => true
]
);
$table->addColumn(
'uri', 'string',
[
'notnull' => false,
'length' => 255,
]
);
$table->addColumn(
'title', 'string',
[
'notnull' => false,
'length' => 255,
'default' => ''
]
);
$table->addColumn(
'version', 'string',
[
'notnull' => false,
'length' => 31,
'default' => ''
]
);
$table->addColumn(
'short_description', 'text',
[
'notnull' => false,
'default' => ''
]
);
$table->addColumn(
'description', 'text',
[
'notnull' => false,
'default' => ''
]
);
$table->addColumn(
'email', 'string',
[
'notnull' => false,
'length' => 255,
'default' => ''
]
);
$table->addColumn(
'urls', 'text',
[
'notnull' => false,
'default' => '[]'
]
);
$table->addColumn(
'stats', 'text',
[
'notnull' => false,
'default' => '[]'
]
);
$table->addColumn(
'usage', 'text',
[
'notnull' => false,
'default' => '[]'
]
);
$table->addColumn(
'image', 'string',
[
'notnull' => false,
'length' => 255,
'default' => ''
]
);
$table->addColumn(
'languages', 'text',
[
'notnull' => false,
'default' => '[]'
]
);
$table->addColumn(
'contact', 'string',
[
'notnull' => false,
'length' => 127,
'default' => ''
]
);
$table->addColumn(
'account_prim', 'string',
[
'notnull' => false,
'length' => 128,
'default' => ''
]
);
$table->addColumn(
'creation', 'datetime',
[
'notnull' => false,
]
);
$table->setPrimaryKey(['uri']);
$table->addIndex(['local', 'uri', 'account_prim']);
}
/**
* @param ISchemaWrapper $schema
* @param string $tableName
* @param string $indexName
*
* @throws SchemaException
*/
private function addChunkToTable(ISchemaWrapper $schema, string $tableName, string $indexName) {
if (!$schema->hasTable($tableName)) {
return;
}
$table = $schema->getTable($tableName);
if ($table->hasColumn('chunk')) {
return;
}
$table->addColumn(
'chunk', Type::SMALLINT,
[
'default' => 1,
'length' => 1,
'unsigned' => true
]
);
if (!$table->hasIndex('chunk' . $indexName)) {
$table->addIndex(['chunk'], 'chunk' . $indexName);
}
}
}

Wyświetl plik

@ -1,86 +0,0 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @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\Social\Migration;
use Closure;
use Doctrine\DBAL\Schema\SchemaException;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
* Class Version0003Date20200921103342
*
* @package OCA\Social\Migration
*/
class Version0003Date20200921103342 extends SimpleMigrationStep {
private IDBConnection $connection;
/**
* @param IDBConnection $connection
*/
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @return ISchemaWrapper
* @throws SchemaException
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options
): ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$table = $schema->getTable('social_3_stream');
$column = $table->getColumn('nid');
if (!$column->getAutoincrement()) {
$table->changeColumn(
'nid', [
'autoincrement' => true, 'customSchemaOptions' => [
'unique' => true
]
]
);
}
return $schema;
}
}

Wyświetl plik

@ -55,7 +55,6 @@ class ConfigService {
public const CLOUD_URL = 'cloud_url';
public const SOCIAL_URL = 'social_url';
public const SOCIAL_ADDRESS = 'social_address';
public const DATABASE_CHUNK_SIZE = 'db_chunk_size';
public const SOCIAL_SERVICE = 'service';
public const SOCIAL_MAX_SIZE = 'max_size';
@ -78,8 +77,7 @@ class ConfigService {
self::SOCIAL_MAX_SIZE => 10,
self::SOCIAL_ACCESS_TYPE => 'all_but',
self::SOCIAL_ACCESS_LIST => '[]',
self::SOCIAL_SELF_SIGNED => '0',
self::DATABASE_CHUNK_SIZE => 10000
self::SOCIAL_SELF_SIGNED => '0'
];
public array $accessTypeList = [