From 3db58dcda5f735e9e680e1291da983ef85739a3c Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 23 Jun 2020 11:11:49 -0100 Subject: migration Signed-off-by: Maxence Lange --- lib/Command/MigrateAlpha3.php | 482 ++++++++++++++++++++++++ lib/Db/FollowsRequest.php | 6 +- lib/Db/FollowsRequestBuilder.php | 6 +- lib/Migration/Version0003Date20200611000001.php | 238 ++++++++---- 4 files changed, 643 insertions(+), 89 deletions(-) create mode 100644 lib/Command/MigrateAlpha3.php diff --git a/lib/Command/MigrateAlpha3.php b/lib/Command/MigrateAlpha3.php new file mode 100644 index 00000000..2ec0e337 --- /dev/null +++ b/lib/Command/MigrateAlpha3.php @@ -0,0 +1,482 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Command; + + +use daita\MySmallPhpTools\Traits\TArrayTools; +use Exception; +use OC\Core\Command\Base; +use OCA\Social\Db\CoreRequestBuilder; +use OCA\Social\Service\CheckService; +use OCA\Social\Service\ConfigService; +use OCA\Social\Service\MiscService; +use OCP\DB\QueryBuilder\IParameter; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; + + +class MigrateAlpha3 extends Base { + + + use TArrayTools; + + + /** @var IDBConnection */ + private $dbConnection; + + /** @var CoreRequestBuilder */ + private $coreRequestBuilder; + + /** @var CheckService */ + private $checkService; + + /** @var ConfigService */ + private $configService; + + /** @var MiscService */ + private $miscService; + + /** @var array */ + private $done = []; + + + /** @var array */ + public $tables = [ + 'social_a2_actions' => [ + ['id_prim'], + 'social_3_action', + [ + 'actor_id_prim' => 'PRIM:actor_id', + 'object_id_prim' => 'PRIM:object_id' + ] + ], + 'social_a2_actors' => [['user_id'], 'social_3_actor', []], + 'social_a2_cache_actors' => [['id_prim'], 'social_3_cache_actor', []], + 'social_a2_cache_documts' => [['id_prim'], 'social_3_cache_doc', []], + 'social_a2_follows' => [ + ['id_prim'], + 'social_3_follow', + [ + 'actor_id_prim' => 'PRIM:actor_id', + 'object_id_prim' => 'PRIM:object_id', + 'follow_id_prim' => 'PRIM:follow_id' + ] + ], + + 'social_a2_hashtags' => [['hashtag'], 'social_3_hashtag', []], + 'social_a2_request_queue' => [['id'], 'social_3_req_queue', []], + 'social_a2_stream' => [ + ['id_prim'], + 'social_3_stream', + [ + 'object_id_prim' => 'PRIM:object_id', + 'in_reply_to_prim' => 'PRIM:in_reply_to', + 'attributed_to_prim' => 'PRIM:attributed_to', + 'filter_duplicate' => 'COPY:hidden_on_timeline', + 'hidden_on_timeline' => 'REMOVED:' + ] + ], + 'social_a2_stream_action' => [ + ['id'], + 'social_3_stream_act', + [ + 'actor_id_prim' => 'PRIM:actor_id', + 'stream_id_prim' => 'PRIM:stream_id', + '_function_' => 'migrateTableStreamAction' + ] + ], + 'social_a2_stream_queue' => [['id'], 'social_3_stream_queue', []] + ]; + + + /** + * CacheUpdate constructor. + * + * @param IDBConnection $dbConnection + * @param CoreRequestBuilder $coreRequestBuilder + * @param CheckService $checkService + * @param ConfigService $configService + * @param MiscService $miscService + */ + public function __construct( + IDBConnection $dbConnection, CoreRequestBuilder $coreRequestBuilder, CheckService $checkService, + ConfigService $configService, MiscService $miscService + ) { + parent::__construct(); + $this->dbConnection = $dbConnection; + $this->checkService = $checkService; + $this->coreRequestBuilder = $coreRequestBuilder; + $this->configService = $configService; + $this->miscService = $miscService; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('social:migrate:alpha3') + ->setDescription('Trying to migrate old data to Alpha3') + ->addOption( + 'remove-migrated-tables', '', InputOption::VALUE_NONE, 'Remove old table once copy is done' + ) + ->addOption( + 'force-remove-old-tables', '', InputOption::VALUE_NONE, 'Force remove old tables' + ); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $tables = $this->checkTables(); + + if ($input->getOption('force-remove-old-tables')) { + foreach ($tables as $table) { + $this->dropTable($table); + } + + return; + } + + if (empty($tables)) { + $output->writeln('Nothing to migrate.'); + + return; + } + + $defTables = ''; + if (sizeof($tables) < sizeof($this->tables)) { + $defTables = ': \'' . implode("', '", $tables) . '\''; + } + + $output->writeln( + 'Found ' . sizeof($tables) . ' tables to migrate' . $defTables . '.' + ); + + if (!$this->confirmExecute($input, $output)) { + return; + } + + $this->done = []; + $this->migrateTables($output, $tables); + + if ($input->getOption('remove-migrated-tables')) { + $this->dropDeprecatedTables($input, $output); + } + } + + + /** + * @return string[] + */ + private function checkTables(): array { + $ak = array_keys($this->tables); + $tables = []; + foreach ($ak as $k) { + if ($this->dbConnection->tableExists($k)) { + $tables[] = $k; + } + } + + return $tables; + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return bool + */ + private function confirmExecute(InputInterface $input, OutputInterface $output): bool { + $helper = $this->getHelper('question'); + $output->writeln(''); + $question = new ConfirmationQuestion( + 'Do you want to migrate data from the old database? (y/N) ', false, '/^(y|Y)/i' + ); + + if (!$helper->ask($input, $output, $question)) { + return false; + } + + return true; + } + + + /** + * @param OutputInterface $output + * @param array $tables + */ + private function migrateTables(OutputInterface $output, array $tables) { + foreach ($tables as $table) { + try { + $this->migrateTable($output, $table); + $output->writeln('Migration of \'' . $table . '\': ok'); + } catch (Exception $e) { + $output->writeln( + 'Migration of \'' . $table . '\': fail - ' + . $e->getMessage() + ); + } + } + + } + + + /** + * @param OutputInterface $output + * @param string $table + */ + private function migrateTable(OutputInterface $output, string $table) { + $output->writeln(''); + $output->writeln('Retrieving data from \'' . $table . '\'.'); + $fullContent = $this->getContentFromTable($table); + + $output->write('Found ' . count($fullContent) . ' entries'); + $m = $copied = 0; + foreach ($fullContent as $entry) { + if ($m % 50 == 0) { + $output->write('.'); + } + + if ($this->migrateEntry($table, $entry)) { + $copied++; + } + + $m++; + } + + $output->writeln(' ' . $copied . ' copied'); + + $this->done[] = $table; + } + + + /** + * @param string $table + * + * @return array + */ + private function getContentFromTable(string $table): array { + $qb = $this->dbConnection->getQueryBuilder(); + + $qb->select('*') + ->from($table); + + $entries = []; + $cursor = $qb->execute(); + while ($data = $cursor->fetch()) { + $entries[] = $data; + } + $cursor->closeCursor(); + + return $entries; + } + + + /** + * @param string $table + * @param $entry + * + * @return bool + */ + private function migrateEntry(string $table, $entry): bool { + if (!$this->checkUnique($table, $entry)) { + return false; + } + + list(, $destTable, $destDefault) = $this->tables[$table]; + + $qb = $this->dbConnection->getQueryBuilder(); + + $qb->insert($destTable); + $ak = array_merge(array_keys($entry), array_keys($destDefault)); + foreach ($ak as $k) { + if ($k === '_function_') { + continue; + } + + $value = ''; + + try { + if ($this->get($k, $entry, '') !== '') { + $this->manageDefault($qb, $this->get($k, $destDefault), $entry); + $value = $entry[$k]; + } else if (array_key_exists($k, $destDefault)) { + $value = $this->manageDefault($qb, $destDefault[$k], $entry); + } + } catch (Exception $e) { + continue; + } + + if ($value !== '') { + $qb->setValue($k, $qb->createNamedParameter($value)); + } + } + + if (array_key_exists('_function_', $destDefault)) { + call_user_func_array([$this, $destDefault['_function_']], [$qb, $entry]); + } + + $qb->execute(); + + return true; + } + + + /** + * @param string $table + * @param $entry + * + * @return bool + */ + private function checkUnique(string $table, $entry): bool { + list($unique, $destTable) = $this->tables[$table]; + + $qb = $this->dbConnection->getQueryBuilder(); + $qb->select('*') + ->from($destTable); + + $expr = $qb->expr(); + $andX = $expr->andX(); + foreach ($unique as $f) { + $andX->add($expr->eq($f, $qb->createNamedParameter($entry[$f]))); + } + $qb->andWhere($andX); + + $cursor = $qb->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + if ($data === false) { + return true; + } + + return false; + } + + + /** + * @param IQueryBuilder $qb + * @param string $default + * @param array $entry + * + * @return IParameter|string + * @throws Exception + */ + private function manageDefault(IQueryBuilder $qb, string $default, array $entry) { + if ($default === '') { + return ''; + } + + if (!strpos($default, ':')) { + return $qb->createNamedParameter($default); + } + + list($k, $v) = explode(':', $default, 2); + switch ($k) { + case 'COPY': + return $this->get($v, $entry, ''); + + case 'PRIM': + if ($this->get($v, $entry, '') === '') { + return ''; + } + + return hash('sha512', $entry[$v]); + + case 'REMOVED': + throw new Exception(); + } + + return ''; + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + */ + private function dropDeprecatedTables(InputInterface $input, OutputInterface $output) { + $helper = $this->getHelper('question'); + $output->writeln(''); + $question = new ConfirmationQuestion( + 'You migrate ' . count($this->done) . ' table. Do you want to remove them ? (y/N) ', + false, '/^(y|Y)/i' + ); + + if (!$helper->ask($input, $output, $question)) { + return; + } + + foreach ($this->done as $table) { + $this->dropTable($table); + } + } + + + /** + * @param string $table + */ + private function dropTable(string $table) { + $this->dbConnection->dropTable($table); + } + + + /** + * @param IQueryBuilder $qb + * @param array $entry + */ + public function migrateTableStreamAction(IQueryBuilder $qb, array $entry) { + $values = json_decode($entry['values'], true); + if ($values === null) { + return; + } + + $liked = ($this->getBool('liked', $values)) ? '1' : '0'; + $boosted = ($this->getBool('boosted', $values)) ? '1' : '0'; + + $qb->setValue('liked', $qb->createNamedParameter($liked)); + $qb->setValue('boosted', $qb->createNamedParameter($boosted)); + } + +} + diff --git a/lib/Db/FollowsRequest.php b/lib/Db/FollowsRequest.php index ec46401f..c9138ba4 100644 --- a/lib/Db/FollowsRequest.php +++ b/lib/Db/FollowsRequest.php @@ -76,8 +76,7 @@ class FollowsRequest extends FollowsRequestBuilder { } catch (Exception $e) { } - $this->generatePrimaryKey($qb, $follow->getId()); - + $qb->generatePrimaryKey($follow->getId()); $qb->execute(); } @@ -102,8 +101,7 @@ class FollowsRequest extends FollowsRequestBuilder { } catch (Exception $e) { } - $this->generatePrimaryKey($qb, $actor->getId()); - + $qb->generatePrimaryKey($actor->getId()); $qb->execute(); } diff --git a/lib/Db/FollowsRequestBuilder.php b/lib/Db/FollowsRequestBuilder.php index 91695738..eb3bc2d4 100644 --- a/lib/Db/FollowsRequestBuilder.php +++ b/lib/Db/FollowsRequestBuilder.php @@ -51,10 +51,10 @@ class FollowsRequestBuilder extends CoreRequestBuilder { /** * Base of the Sql Insert request * - * @return IQueryBuilder + * @return SocialQueryBuilder */ - protected function getFollowsInsertSql(): IQueryBuilder { - $qb = $this->dbConnection->getQueryBuilder(); + protected function getFollowsInsertSql(): SocialQueryBuilder { + $qb = $this->getQueryBuilder(); $qb->insert(self::TABLE_FOLLOWS); return $qb; diff --git a/lib/Migration/Version0003Date20200611000001.php b/lib/Migration/Version0003Date20200611000001.php index c8621ede..6593a912 100644 --- a/lib/Migration/Version0003Date20200611000001.php +++ b/lib/Migration/Version0003Date20200611000001.php @@ -128,34 +128,39 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { [ 'notnull' => false, 'length' => 31, + 'default' => '' ] ); $table->addColumn( 'actor_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'actor_id_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( 'object_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'object_id_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( @@ -197,28 +202,30 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'user_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 63, ] ); $table->addColumn( 'preferred_username', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 127, ] ); $table->addColumn( 'name', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 127, + 'default' => '' ] ); $table->addColumn( 'summary', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( @@ -279,48 +286,55 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { [ 'notnull' => false, 'length' => 31, + 'default' => '' ] ); $table->addColumn( 'actor_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'actor_id_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( 'object_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'object_id_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( 'follow_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'follow_id_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( @@ -363,7 +377,8 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { 'trend', 'string', [ 'notnull' => false, - 'length' => 500 + 'length' => 500, + 'default' => '' ] ); @@ -398,59 +413,68 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'type', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 31, + 'default' => '' ] ); $table->addColumn( 'subtype', Type::STRING, [ - 'notnull' => true, + 'notnull' => false, 'length' => 31, + 'default' => '' ] ); $table->addColumn( 'to', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'to_array', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'cc', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'bcc', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'content', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'summary', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'published', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 31, + 'default' => '' ] ); $table->addColumn( @@ -464,13 +488,15 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { [ 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'attributed_to_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( @@ -478,13 +504,15 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { [ 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'in_reply_to_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( @@ -492,6 +520,7 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { [ 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( @@ -499,50 +528,57 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { [ 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'object_id_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( - 'hashtags', 'string', + 'hashtags', Type::TEXT, [ 'notnull' => false, - 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'details', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'source', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'instances', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'attachments', Type::TEXT, [ - 'notnull' => false + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'cache', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( @@ -554,14 +590,14 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'local', 'boolean', [ - 'notnull' => true, + 'notnull' => false, 'default' => false ] ); $table->addColumn( 'filter_duplicate', 'boolean', [ - 'notnull' => true, + 'notnull' => false, 'default' => false ] ); @@ -609,15 +645,17 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'type', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 31, + 'default' => '' ] ); $table->addColumn( 'account', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 127, + 'default' => '' ] ); $table->addColumn( @@ -630,89 +668,102 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'following', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'followers', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'inbox', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'shared_inbox', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'outbox', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'featured', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'url', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'preferred_username', 'string', [ - 'notnull' => true, - 'length' => 127 + 'notnull' => false, + 'length' => 127, + 'default' => '' ] ); $table->addColumn( 'name', 'string', [ - 'notnull' => true, - 'length' => 127 + 'notnull' => false, + 'length' => 127, + 'default' => '' ] ); $table->addColumn( 'icon_id', 'string', [ 'notnull' => false, - 'length' => 1000 + 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'summary', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'public_key', Type::TEXT, [ - 'notnull' => false + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'source', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( @@ -751,69 +802,76 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'id_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128 ] ); $table->addColumn( 'type', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 31, + 'default' => '' ] ); $table->addColumn( 'parent_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '', ] ); $table->addColumn( 'media_type', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 63, + 'default' => '', ] ); $table->addColumn( 'mime_type', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 63, + 'default' => '' ] ); $table->addColumn( 'url', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'local_copy', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'resized_copy', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'public', 'boolean', [ - 'notnull' => true, + 'notnull' => false, 'default' => false ] ); $table->addColumn( 'error', 'smallint', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1, ] ); @@ -856,28 +914,31 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'token', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 63, ] ); $table->addColumn( 'author', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'activity', Type::TEXT, [ - 'notnull' => true + 'notnull' => false, + 'default' => '' ] ); $table->addColumn( 'instance', Type::TEXT, [ - 'notnull' => true, + 'notnull' => false, 'length' => 500, + 'default' => '' ] ); $table->addColumn( @@ -937,38 +998,43 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'actor_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'actor_id_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( 'stream_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 1000, + 'default' => '' ] ); $table->addColumn( 'stream_id_prim', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); - $table->addColumn('liked', 'boolean'); - $table->addColumn('boosted', 'boolean'); - $table->addColumn('replied', 'boolean'); + $table->addColumn('liked', 'boolean', ['default' => false]); + $table->addColumn('boosted', 'boolean', ['default' => false]); + $table->addColumn('replied', 'boolean', ['default' => false]); $table->addColumn( 'values', Type::TEXT, [ - 'notnull' => false + 'notnull' => false, + 'default' => '' ] ); @@ -989,15 +1055,17 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'stream_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( 'actor_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( @@ -1005,6 +1073,7 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { [ 'notnull' => false, 'length' => 15, + 'default' => '' ] ); $table->addColumn( @@ -1012,6 +1081,7 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { [ 'notnull' => false, 'length' => 7, + 'default' => '' ] ); @@ -1041,22 +1111,24 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'token', 'string', [ - 'notnull' => true, - 'length' => 63, + 'notnull' => false, + 'length' => 63 ] ); $table->addColumn( 'stream_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 255, + 'default' => '' ] ); $table->addColumn( 'type', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 31, + 'default' => '' ] ); $table->addColumn( @@ -1098,8 +1170,9 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { $table->addColumn( 'stream_id', 'string', [ - 'notnull' => true, + 'notnull' => false, 'length' => 128, + 'default' => '' ] ); $table->addColumn( @@ -1107,6 +1180,7 @@ class Version0003Date20200611000001 extends SimpleMigrationStep { [ 'notnull' => false, 'length' => 127, + 'default' => '' ] ); -- cgit v1.2.3