Skip to content

Commit 757ae03

Browse files
committed
fix(db): make sure all instances have the same notNull for msg.attachements and msg.sources
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent f8ee8db commit 757ae03

File tree

4 files changed

+68
-20
lines changed

4 files changed

+68
-20
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Known providers:
6262
6363
More details on how to set this up in the [admin docs](https://docs.nextcloud.com/server/latest/admin_manual/ai/index.html)
6464
]]> </description>
65-
<version>2.6.0</version>
65+
<version>2.6.1</version>
6666
<licence>agpl</licence>
6767
<author>Julien Veyssier</author>
6868
<namespace>Assistant</namespace>

lib/Db/ChattyLLM/Message.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
* @method \void setTimestamp(int $timestamp)
2424
* @method \int getOcpTaskId()
2525
* @method \void setOcpTaskId(int $ocpTaskId)
26-
* @method \string getSources()
27-
* @method \void setSources(string $sources)
28-
* @method \string getAttachments()
29-
* @method \void setAttachments(string $attachments)
26+
* @method \string|null getSources()
27+
* @method \void setSources(?string $sources)
28+
* @method \string|null getAttachments()
29+
* @method \void setAttachments(?string $attachments)
3030
*/
3131
class Message extends Entity implements \JsonSerializable {
3232
/** @var int */
@@ -39,9 +39,9 @@ class Message extends Entity implements \JsonSerializable {
3939
protected $timestamp;
4040
/** @var int */
4141
protected $ocpTaskId;
42-
/** @var string */
42+
/** @var ?string */
4343
protected $sources;
44-
/** @var string */
44+
/** @var ?string */
4545
protected $attachments;
4646

4747
public static $columns = [

lib/Db/ChattyLLM/Session.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@
1313
use OCP\DB\Types;
1414

1515
/**
16-
* @method string getUserId()
17-
* @method void setUserId(string $userId)
18-
* @method \string|\null getTitle()
19-
* @method \void setTitle(?\string $title)
20-
* @method \int|\null getTimestamp()
21-
* @method \void setTimestamp(?\int $timestamp)
22-
* @method string|null getAgencyConversationToken()
23-
* @method void setAgencyConversationToken(?string $agencyConversationToken)
24-
* @method string|null getAgencyPendingActions()
25-
* @method void setAgencyPendingActions(?string $agencyPendingActions)
16+
* @method \string getUserId()
17+
* @method \void setUserId(string $userId)
18+
* @method \string|null getTitle()
19+
* @method \void setTitle(?string $title)
20+
* @method \int getTimestamp()
21+
* @method \void setTimestamp(int $timestamp)
22+
* @method \string|null getAgencyConversationToken()
23+
* @method \void setAgencyConversationToken(?string $agencyConversationToken)
24+
* @method \string|null getAgencyPendingActions()
25+
* @method \void setAgencyPendingActions(?string $agencyPendingActions)
2626
*/
2727
class Session extends Entity implements \JsonSerializable {
2828
/** @var string */
2929
protected $userId;
30-
/** @var string */
30+
/** @var ?string */
3131
protected $title;
3232
/** @var int */
3333
protected $timestamp;
34-
/** @var string */
34+
/** @var ?string */
3535
protected $agencyConversationToken;
36-
/** @var string */
36+
/** @var ?string */
3737
protected $agencyPendingActions;
3838

3939
public static $columns = [
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Assistant\Migration;
10+
11+
use Closure;
12+
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\Types;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
17+
class Version020601Date20250709130151 extends SimpleMigrationStep {
18+
19+
/**
20+
* @param IOutput $output
21+
* @param Closure(): ISchemaWrapper $schemaClosure
22+
* @param array $options
23+
* @return null|ISchemaWrapper
24+
*/
25+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
26+
/** @var ISchemaWrapper $schema */
27+
$schema = $schemaClosure();
28+
$schemaChanged = false;
29+
30+
// some MariaDB/MySQL instances upgraded successfully to 2.6.0 with notNull=true
31+
// this makes sure we bring everybody to the same notNull value for sources and attachments
32+
if ($schema->hasTable('assistant_chat_msgs')) {
33+
$table = $schema->getTable('assistant_chat_msgs');
34+
if ($table->hasColumn('sources')) {
35+
$column = $table->getColumn('sources');
36+
$column->setNotnull(false);
37+
$schemaChanged = true;
38+
}
39+
if ($table->hasColumn('attachments')) {
40+
$column = $table->getColumn('attachments');
41+
$column->setNotnull(false);
42+
$schemaChanged = true;
43+
}
44+
}
45+
46+
return $schemaChanged ? $schema : null;
47+
}
48+
}

0 commit comments

Comments
 (0)