-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: split user data from feed data #1706
Draft
SMillerDev
wants to merge
1
commit into
nextcloud:master
Choose a base branch
from
SMillerDev:chore/mapper/split_user_data
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\News\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\IDBConnection; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
/** | ||
* Auto-generated migration step: Please modify to your needs! | ||
*/ | ||
class Version160100Date20210821130702 extends SimpleMigrationStep { | ||
|
||
/** | ||
* @var IDBConnection | ||
*/ | ||
protected $connection; | ||
|
||
public function __construct(IDBConnection $connection) | ||
{ | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
* @param array $options | ||
*/ | ||
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { | ||
} | ||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
* @param array $options | ||
* @return null|ISchemaWrapper | ||
*/ | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
if (!$schema->hasTable('news_user_items')) { | ||
$table = $schema->createTable('news_user_items'); | ||
$table->addColumn('item_id', 'bigint', [ | ||
'notnull' => true, | ||
'length' => 8, | ||
'unsigned' => true, | ||
]); | ||
$table->addColumn('user_id', 'string', [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('unread', 'boolean', [ | ||
'notnull' => true, | ||
'default' => false, | ||
]); | ||
$table->addColumn('starred', 'boolean', [ | ||
'notnull' => true, | ||
'default' => false, | ||
]); | ||
$table->addColumn('last_modified', 'bigint', [ | ||
'notnull' => false, | ||
'length' => 8, | ||
'default' => 0, | ||
'unsigned' => true, | ||
]); | ||
$table->addColumn('shared_by', 'string', [ | ||
'notnull' => false, | ||
'length' => 64 | ||
]); | ||
$table->setPrimaryKey(['item_id', 'user_id']); | ||
} | ||
|
||
if (!$schema->hasTable('news_user_feeds')) { | ||
$table = $schema->createTable('news_user_feeds'); | ||
$table->addColumn('feed_id', 'bigint', [ | ||
'notnull' => true, | ||
'length' => 8, | ||
'unsigned' => true, | ||
]); | ||
$table->addColumn('user_id', 'string', [ | ||
'notnull' => true, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('folder_id', 'bigint', [ | ||
'notnull' => false, | ||
'length' => 8, | ||
]); | ||
$table->addColumn('deleted_at', 'bigint', [ | ||
'notnull' => false, | ||
'length' => 8, | ||
'default' => 0, | ||
'unsigned' => true, | ||
]); | ||
$table->addColumn('added', 'bigint', [ | ||
'notnull' => false, | ||
'length' => 8, | ||
'default' => 0, | ||
'unsigned' => true, | ||
]); | ||
$table->addColumn('title', 'text', [ | ||
'notnull' => true, | ||
]); | ||
$table->addColumn('last_modified', 'bigint', [ | ||
'notnull' => false, | ||
'length' => 8, | ||
'default' => 0, | ||
'unsigned' => true, | ||
]); | ||
$table->setPrimaryKey(['feed_id', 'user_id']); | ||
} | ||
|
||
return $schema; | ||
} | ||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
* @param array $options | ||
*/ | ||
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { | ||
$qb = $this->connection->getQueryBuilder(); | ||
$user_item_table = $qb->getTableName('news_user_items'); | ||
$user_feed_table = $qb->getTableName('news_user_feeds'); | ||
$item_table = $qb->getTableName('news_items'); | ||
$feed_table = $qb->getTableName('news_feeds'); | ||
|
||
$items_query = "REPLACE INTO $user_item_table SELECT id AS 'item_id', ? AS 'user_id',`unread`,`starred`,`last_modified`,`shared_by` FROM $item_table where feed_id = ?;"; | ||
|
||
$feeds = $this->connection->executeQuery("SELECT `id`,`user_id` FROM $feed_table;")->fetchAll(); | ||
foreach ($feeds as $feed) { | ||
$this->connection->executeUpdate($items_query, [$feed['user_id'], $feed['id']]); | ||
} | ||
|
||
$this->connection->executeUpdate("REPLACE INTO $user_feed_table SELECT id AS 'feed_id',user_id,folder_id,deleted_at,added,title,last_modified FROM $feed_table;"); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might have to find a different solution here, since PostgreSQL doesn't have
REPLACE INTO
statements.Alternatively, you could check the database type and use another suitable statement.