mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
feat(migrations): expose destination resource links
This commit is contained in:
1 parent
3cfe4dca6a
commit
a15da42790
9 files changed
+141
-1
No files matched your search
@@ -2322,6 +2322,28 @@ return [
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('destinationResourceId'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('destinationResourceType'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
[
|
||||
@@ -2387,6 +2409,20 @@ return [
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => '_key_destinationResourceId',
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['destinationResourceId'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => '_key_destinationResourceType',
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['destinationResourceType'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_fulltext_search'),
|
||||
'type' => Database::INDEX_FULLTEXT,
|
||||
|
||||
@@ -42,6 +42,8 @@ class V25 extends Migration
|
||||
'parentResourceId',
|
||||
'parentResourceInternalId',
|
||||
'parentResourceType',
|
||||
'destinationResourceId',
|
||||
'destinationResourceType',
|
||||
];
|
||||
try {
|
||||
$this->createAttributesFromCollection($this->dbForProject, $id, $attributes);
|
||||
@@ -55,6 +57,8 @@ class V25 extends Migration
|
||||
'_key_parentResourceId',
|
||||
'_key_parentResourceType',
|
||||
'_key_parentResourceInternalId',
|
||||
'_key_destinationResourceId',
|
||||
'_key_destinationResourceType',
|
||||
];
|
||||
foreach ($indexes as $index) {
|
||||
try {
|
||||
|
||||
@@ -196,6 +196,8 @@ class Create extends Action
|
||||
'parentResourceId' => $database->getId(),
|
||||
'parentResourceInternalId' => $database->getSequence(),
|
||||
'parentResourceType' => $parentResourceType,
|
||||
'destinationResourceId' => $database->getId(),
|
||||
'destinationResourceType' => $parentResourceType,
|
||||
'statusCounters' => '{}',
|
||||
'resourceData' => '{}',
|
||||
'errors' => [],
|
||||
|
||||
@@ -192,6 +192,8 @@ class Create extends Action
|
||||
'parentResourceId' => $database->getId(),
|
||||
'parentResourceInternalId' => $database->getSequence(),
|
||||
'parentResourceType' => $parentResourceType,
|
||||
'destinationResourceId' => $database->getId(),
|
||||
'destinationResourceType' => $parentResourceType,
|
||||
'statusCounters' => '{}',
|
||||
'resourceData' => '{}',
|
||||
'errors' => [],
|
||||
|
||||
@@ -14,6 +14,8 @@ class Migrations extends Base
|
||||
'resourceType',
|
||||
'parentResourceId',
|
||||
'parentResourceType',
|
||||
'destinationResourceId',
|
||||
'destinationResourceType',
|
||||
'statusCounters',
|
||||
'resourceData',
|
||||
'errors',
|
||||
|
||||
@@ -35,6 +35,8 @@ class V27 extends Filter
|
||||
unset($content['parentResourceId']);
|
||||
unset($content['parentResourceInternalId']);
|
||||
unset($content['parentResourceType']);
|
||||
unset($content['destinationResourceId']);
|
||||
unset($content['destinationResourceType']);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,20 @@ class Migration extends Model
|
||||
'example' => 'database',
|
||||
'array' => false
|
||||
])
|
||||
->addRule('destinationResourceId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'ID of the destination resource created or overwritten by the migration.',
|
||||
'default' => '',
|
||||
'example' => 'databaseId',
|
||||
'array' => false
|
||||
])
|
||||
->addRule('destinationResourceType', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Type of the destination resource created or overwritten by the migration.',
|
||||
'default' => '',
|
||||
'example' => 'database',
|
||||
'array' => false
|
||||
])
|
||||
->addRule('statusCounters', [
|
||||
'type' => self::TYPE_JSON,
|
||||
'description' => 'A group of counters that represent the total progress of the migration.',
|
||||
|
||||
@@ -3496,8 +3496,10 @@ trait MigrationsBase
|
||||
|
||||
/**
|
||||
* Import documents from a CSV file.
|
||||
*
|
||||
* @return array{databaseId: string, tableId: string, migrationId: string}
|
||||
*/
|
||||
public function testCreateCSVImport(): void
|
||||
public function testCreateCSVImport(): array
|
||||
{
|
||||
// Make a database
|
||||
$response = $this->client->call(Client::METHOD_POST, '/databases', [
|
||||
@@ -3799,6 +3801,76 @@ trait MigrationsBase
|
||||
$this->assertArrayHasKey(Resource::TYPE_ROW, $migration['body']['statusCounters']);
|
||||
$this->assertEquals(25, $migration['body']['statusCounters'][Resource::TYPE_ROW]['success']);
|
||||
}, 10_000, 500);
|
||||
|
||||
return [
|
||||
'databaseId' => $databaseId,
|
||||
'tableId' => $tableId,
|
||||
'migrationId' => $migration['body']['$id'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{databaseId: string, tableId: string, migrationId: string} $data
|
||||
*/
|
||||
#[Depends('testCreateCSVImport')]
|
||||
public function testListMigrationsByDatabaseResource(array $data): void
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$query = Query::or([
|
||||
Query::and([
|
||||
Query::equal('resourceId', [$databaseId]),
|
||||
Query::equal('resourceType', [Resource::TYPE_DATABASE]),
|
||||
]),
|
||||
Query::and([
|
||||
Query::equal('parentResourceId', [$databaseId]),
|
||||
Query::equal('parentResourceType', [Resource::TYPE_DATABASE]),
|
||||
]),
|
||||
Query::and([
|
||||
Query::equal('destinationResourceId', [$databaseId]),
|
||||
Query::equal('destinationResourceType', [Resource::TYPE_DATABASE]),
|
||||
]),
|
||||
]);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/migrations', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [
|
||||
$query->toString(),
|
||||
Query::limit(100)->toString(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
$this->assertContains($data['migrationId'], array_column($response['body']['migrations'], '$id'));
|
||||
|
||||
$migration = null;
|
||||
foreach ($response['body']['migrations'] as $candidate) {
|
||||
if ($candidate['$id'] === $data['migrationId']) {
|
||||
$migration = $candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertNotNull($migration);
|
||||
$this->assertSame($data['tableId'], $migration['resourceId']);
|
||||
$this->assertSame($databaseId, $migration['parentResourceId']);
|
||||
$this->assertSame(Resource::TYPE_DATABASE, $migration['parentResourceType']);
|
||||
$this->assertSame($databaseId, $migration['destinationResourceId']);
|
||||
$this->assertSame(Resource::TYPE_DATABASE, $migration['destinationResourceType']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/migrations', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [
|
||||
Query::equal('destinationResourceId', [$databaseId])->toString(),
|
||||
Query::equal('destinationResourceType', [Resource::TYPE_DATABASE])->toString(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
$this->assertContains($data['migrationId'], array_column($response['body']['migrations'], '$id'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,8 @@ final class V27Test extends TestCase
|
||||
'parentResourceId' => 'database',
|
||||
'parentResourceInternalId' => '10',
|
||||
'parentResourceType' => 'database',
|
||||
'destinationResourceId' => 'destination',
|
||||
'destinationResourceType' => 'database',
|
||||
], Response::MODEL_MIGRATION);
|
||||
|
||||
$this->assertSame([
|
||||
@@ -43,6 +45,8 @@ final class V27Test extends TestCase
|
||||
'parentResourceId' => '',
|
||||
'parentResourceInternalId' => '',
|
||||
'parentResourceType' => '',
|
||||
'destinationResourceId' => '',
|
||||
'destinationResourceType' => '',
|
||||
], Response::MODEL_MIGRATION);
|
||||
|
||||
$this->assertSame([
|
||||
@@ -64,6 +68,8 @@ final class V27Test extends TestCase
|
||||
'resourceType' => 'collection',
|
||||
'parentResourceId' => 'database',
|
||||
'parentResourceType' => 'database',
|
||||
'destinationResourceId' => 'destination',
|
||||
'destinationResourceType' => 'database',
|
||||
]],
|
||||
], Response::MODEL_MIGRATION_LIST);
|
||||
|
||||
|
||||
Reference in new issue
Block a user