kopia lustrzana https://github.com/nextcloud/social
improved auto_increment
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/985/head
rodzic
f5bd9ca6f0
commit
e57fcd2a36
|
@ -75,7 +75,7 @@ class CoreRequestBuilder {
|
|||
const TABLE_CACHE_ACTORS = 'social_3_cache_actor';
|
||||
const TABLE_CACHE_DOCUMENTS = 'social_3_cache_doc';
|
||||
|
||||
const TABLE_CLIENT = 'social_3_clients';
|
||||
const TABLE_CLIENT = 'social_3_client';
|
||||
const TABLE_CLIENT_AUTH = 'social_3_client_auth';
|
||||
const TABLE_CLIENT_TOKEN = 'social_3_client_token';
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ class Version0003Date20200611000001 extends SimpleMigrationStep {
|
|||
$this->createActors($schema);
|
||||
$this->createCacheActors($schema);
|
||||
$this->createCacheDocuments($schema);
|
||||
$this->createClients($schema);
|
||||
$this->createClient($schema);
|
||||
$this->createFollows($schema);
|
||||
$this->createHashtags($schema);
|
||||
$this->createInstance($schema);
|
||||
|
@ -1052,12 +1052,12 @@ class Version0003Date20200611000001 extends SimpleMigrationStep {
|
|||
/**
|
||||
* @param ISchemaWrapper $schema
|
||||
*/
|
||||
private function createClients(ISchemaWrapper $schema) {
|
||||
if ($schema->hasTable('social_3_clients')) {
|
||||
private function createClient(ISchemaWrapper $schema) {
|
||||
if ($schema->hasTable('social_3_client')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$table = $schema->createTable('social_3_clients');
|
||||
$table = $schema->createTable('social_3_client');
|
||||
$table->addColumn(
|
||||
'id', 'integer',
|
||||
[
|
||||
|
|
|
@ -34,6 +34,7 @@ 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;
|
||||
|
@ -76,7 +77,7 @@ class Version0003Date20200823023911 extends SimpleMigrationStep {
|
|||
$this->fixStreamNid($schema);
|
||||
$this->fixCacheActorNid($schema);
|
||||
|
||||
$this->createClients($schema);
|
||||
$this->createClient($schema);
|
||||
$this->createInstance($schema);
|
||||
|
||||
$this->addChunkToTable($schema, 'social_3_stream', '');
|
||||
|
@ -87,6 +88,38 @@ class Version0003Date20200823023911 extends SimpleMigrationStep {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
@ -104,12 +137,8 @@ class Version0003Date20200823023911 extends SimpleMigrationStep {
|
|||
$table->addColumn(
|
||||
'nid', 'bigint',
|
||||
[
|
||||
'autoincrement' => true,
|
||||
'length' => 11,
|
||||
'unsigned' => true,
|
||||
'customSchemaOptions' => [
|
||||
'unique' => true
|
||||
]
|
||||
'length' => 11,
|
||||
'unsigned' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -146,12 +175,12 @@ class Version0003Date20200823023911 extends SimpleMigrationStep {
|
|||
/**
|
||||
* @param ISchemaWrapper $schema
|
||||
*/
|
||||
private function createClients(ISchemaWrapper $schema) {
|
||||
if ($schema->hasTable('social_3_clients')) {
|
||||
private function createClient(ISchemaWrapper $schema) {
|
||||
if ($schema->hasTable('social_3_client')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$table = $schema->createTable('social_3_clients');
|
||||
$table = $schema->createTable('social_3_client');
|
||||
$table->addColumn(
|
||||
'id', 'integer',
|
||||
[
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
<?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 {
|
||||
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Ładowanie…
Reference in New Issue