Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 3 additions & 3 deletions src/Migration/Resources/Database/Columns/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
$key,
$table,
options: [
'relatedTable' => $relatedTable,
'relatedCollection' => $relatedTable,
'relationType' => $relationType,
'twoWay' => $twoWay,
'twoWayKey' => $twoWayKey,
Expand Down Expand Up @@ -77,7 +77,7 @@ public static function fromArray(array $array): self
return new self(
$array['key'],
Table::fromArray($array['table'] ?? $array['collection']),
relatedTable: $array['options']['relatedTable'] ?? $array['options']['relatedCollection'],
relatedTable: $array['options']['relatedCollection'],
relationType: $array['options']['relationType'],
twoWay: $array['options']['twoWay'],
twoWayKey: $array['options']['twoWayKey'],
Expand All @@ -95,7 +95,7 @@ public function getType(): string

public function getRelatedTable(): string
{
return $this->options['relatedTable'] ?? $this->options['relatedCollection'];
return $this->options['relatedCollection'];
}

public function getRelationType(): string
Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -998,12 +998,12 @@ private function exportIndexes(int $batchSize): void

foreach ($response as $index) {
$indexes[] = new Index(
'unique()',
$index['$id'],
Comment thread
abnegate marked this conversation as resolved.
$index['key'],
$table,
$index['type'],
$index['columns'] ?? $index['attributes'],
[],
$index['lengths'],
Comment thread
abnegate marked this conversation as resolved.
Outdated
$index['orders'],
$index['$createdAt'] = empty($index['$createdAt']) ? UtopiaDateTime::now() : $index['$createdAt'],
$index['$updatedAt'] = empty($index['$updatedAt']) ? UtopiaDateTime::now() : $index['$updatedAt'],
Expand Down
19 changes: 9 additions & 10 deletions src/Migration/Sources/Appwrite/Reader/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,33 @@ public function report(array $resources, array &$report): mixed
: [Query::limit($pageLimit)]
)['collections']; /* ['tables'] */

$tables = array_merge($tables, $currentTables);
$tables = \array_merge($tables, $currentTables);
$lastTable = $tables[count($tables) - 1]['$id'] ?? null;

if (count($currentTables) < $pageLimit) {
if (\count($currentTables) < $pageLimit) {
break;
}
}

if (Resource::isSupported(Resource::TYPE_TABLE, $resources)) {
$report[Resource::TYPE_TABLE] += count($tables);
if (Resource::isSupported([Resource::TYPE_TABLE, Resource::TYPE_COLLECTION], $resources)) {
Comment thread
abnegate marked this conversation as resolved.
Outdated
$report[Resource::TYPE_TABLE] += \count($tables);
}

if (Resource::isSupported([Resource::TYPE_ROW, Resource::TYPE_COLUMN, Resource::TYPE_INDEX], $resources)) {
foreach ($tables as $table) {
$tableId = $table['$id'];

if (Resource::isSupported(Resource::TYPE_COLUMN, $resources)) {
if (Resource::isSupported([Resource::TYPE_COLUMN, Resource::TYPE_ATTRIBUTE], $resources)) {
// a table already returns a list of attributes
$report[Resource::TYPE_COLUMN] += count($table['columns'] ?? $table['attributes'] ?? []);
}

if (in_array(Resource::TYPE_INDEX, $resources)) {
// a table already returns a list of indexes
$report[Resource::TYPE_INDEX] += count($table['indexes'] ?? []);
if (\in_array(Resource::TYPE_INDEX, $resources)) {
// A table already returns a list of indexes
$report[Resource::TYPE_INDEX] += \count($table['indexes'] ?? []);
}

// this one's a bit heavy if the number of tables are high!
if (Resource::isSupported(Resource::TYPE_ROW, $resources)) {
if (Resource::isSupported([Resource::TYPE_ROW, Resource::TYPE_DOCUMENT], $resources)) {
/* $rowsResponse = $this->tables->listRows(...) */
$rowsResponse = $this->database->listDocuments(
$databaseId,
Expand Down
9 changes: 2 additions & 7 deletions src/Migration/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ class Transfer
Resource::TYPE_INDEX,
Resource::TYPE_COLUMN,
Resource::TYPE_ROW,

// legacy
Resource::TYPE_DOCUMENT,
Resource::TYPE_ATTRIBUTE,
Resource::TYPE_COLLECTION,
Comment on lines -43 to -47
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these here just duplicates what were store in the migrations resources, we now the have fallbacks to handle existing migrations that reference these

];

public const GROUP_SETTINGS_RESOURCES = [];
Expand Down Expand Up @@ -142,7 +137,7 @@ public function getStatusCounters(): array

foreach ($this->cache->getAll() as $resourceType => $resources) {
foreach ($resources as $resource) {
if ($resourceType === Resource::TYPE_ROW && is_string($resource)) {
if (($resourceType === Resource::TYPE_ROW || $resourceType === Resource::TYPE_DOCUMENT) && is_string($resource)) {
$rowStatus = $resource;
$status[$resourceType][$rowStatus]++;

Expand Down Expand Up @@ -286,7 +281,7 @@ public function getReport(string $statusLevel = ''): array

foreach ($cache as $type => $resources) {
foreach ($resources as $id => $resource) {
if ($type === Resource::TYPE_ROW && is_string($resource)) {
if (($type === Resource::TYPE_ROW || $type === Resource::TYPE_DOCUMENT) && is_string($resource)) {
if ($statusLevel && $resource !== $statusLevel) {
continue;
}
Expand Down