Skip to content
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

feat(db): Add timestamp field to steps database #5888

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- **💾 Open format:** Files are saved as [Markdown](https://en.wikipedia.org/wiki/Markdown), so you can edit them from any other text app too.
- **✊ Strong foundation:** We use [🐈 tiptap](https://tiptap.scrumpy.io) which is based on [🦉 ProseMirror](https://prosemirror.net) – huge thanks to them!
]]></description>
<version>4.0.0</version>
<version>4.1.0</version>
mejo- marked this conversation as resolved.
Show resolved Hide resolved
<licence>agpl</licence>
<author mail="jus@bitgrid.net">Julius Härtl</author>
<namespace>Text</namespace>
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'OCA\\Text\\Migration\\Version030501Date20220202101853' => $baseDir . '/../lib/Migration/Version030501Date20220202101853.php',
'OCA\\Text\\Migration\\Version030701Date20230207131313' => $baseDir . '/../lib/Migration/Version030701Date20230207131313.php',
'OCA\\Text\\Migration\\Version030901Date20231114150437' => $baseDir . '/../lib/Migration/Version030901Date20231114150437.php',
'OCA\\Text\\Migration\\Version040100Date20240611165300' => $baseDir . '/../lib/Migration/Version040100Date20240611165300.php',
'OCA\\Text\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\Text\\Service\\ApiService' => $baseDir . '/../lib/Service/ApiService.php',
'OCA\\Text\\Service\\AttachmentService' => $baseDir . '/../lib/Service/AttachmentService.php',
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ComposerStaticInitText
'OCA\\Text\\Migration\\Version030501Date20220202101853' => __DIR__ . '/..' . '/../lib/Migration/Version030501Date20220202101853.php',
'OCA\\Text\\Migration\\Version030701Date20230207131313' => __DIR__ . '/..' . '/../lib/Migration/Version030701Date20230207131313.php',
'OCA\\Text\\Migration\\Version030901Date20231114150437' => __DIR__ . '/..' . '/../lib/Migration/Version030901Date20231114150437.php',
'OCA\\Text\\Migration\\Version040100Date20240611165300' => __DIR__ . '/..' . '/../lib/Migration/Version040100Date20240611165300.php',
'OCA\\Text\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\Text\\Service\\ApiService' => __DIR__ . '/..' . '/../lib/Service/ApiService.php',
'OCA\\Text\\Service\\AttachmentService' => __DIR__ . '/..' . '/../lib/Service/AttachmentService.php',
Expand Down
7 changes: 6 additions & 1 deletion lib/Db/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* @method setSessionId(int $sessionId): void
* @method getDocumentId(): int
* @method setDocumentId(int $documentId): void
* @method getTimestamp(): int
* @method setTimestamp(int $timestam): void
*/
class Step extends Entity implements JsonSerializable {

Expand All @@ -50,12 +52,14 @@ class Step extends Entity implements JsonSerializable {
protected int $version = 0;
protected int $sessionId = 0;
protected int $documentId = 0;
protected int $timestamp = 0;

public function __construct() {
$this->addType('id', 'integer');
$this->addType('version', 'integer');
$this->addType('documentId', 'integer');
$this->addType('sessionId', 'integer');
$this->addType('timestamp', 'integer');
}

public function jsonSerialize(): array {
Expand All @@ -70,7 +74,8 @@ public function jsonSerialize(): array {
'id' => $this->getId(),
'data' => $jsonData,
'version' => $version,
'sessionId' => $this->getSessionId()
'sessionId' => $this->getSessionId(),
'timestamp' => $this->getTimestamp(),
];
}
}
53 changes: 53 additions & 0 deletions lib/Migration/Version040100Date20240611165300.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2024 Jonas <jonas@freesources.org>
*
* @author Jonas <jonas@freesources.org>
*
* @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\Text\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version040100Date20240611165300 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('text_steps')) {
$table = $schema->getTable('text_steps');
if (!$table->hasColumn('timestamp')) {
$table->addColumn('timestamp', Types::BIGINT, [
'notnull' => true,
'length' => 6,
'default' => 0,
]);
return $schema;
}
}
return null;
}
}
1 change: 1 addition & 0 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ private function insertSteps(Document $document, Session $session, array $steps)
$step->setSessionId($session->getId());
$step->setDocumentId($document->getId());
$step->setVersion(Step::VERSION_STORED_IN_ID);
$step->setTimestamp(time());
$step = $this->stepMapper->insert($step);
$newVersion = $step->getId();
$this->logger->debug("Adding steps to " . $document->getId() . ": bumping version from $stepsVersion to $newVersion");
Expand Down
Loading