Skip to content

Commit 522ae8d

Browse files
feat: migration for 1.1.x
1 parent 7288520 commit 522ae8d

File tree

3 files changed

+119
-8
lines changed

3 files changed

+119
-8
lines changed

CHANGES.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
# Version 1.1.0
2-
32
## Features
4-
- Added new property to projects configuration: `sessionDuration` which allows you to alter the duration of signed in sessions for your project. [#4618](https://github.com/appwrite/appwrite/pull/4618)
3+
- Added new property to projects configuration: `authDuration` which allows you to alter the duration of signed in sessions for your project. [#4618](https://github.com/appwrite/appwrite/pull/4618)
54

65
## Bugs
76
- Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435)
8-
- Fix missing status, buildStderr and buildStderr from get deployment response [#4611](https://github.com/appwrite/appwrite/pull/4611)
7+
- Fix missing `status`, `buildStderr` and `buildStderr` from get deployment response [#4611](https://github.com/appwrite/appwrite/pull/4611)
8+
- Fix project pagination in DB usage aggregation [#4517](https://github.com/appwrite/appwrite/pull/4517)
99

1010
# Features
1111
- Added Auth Duration API to allow users to set the duration of their sessions. [#4618](https://github.com/appwrite/appwrite/pull/4618)
1212

13-
# Version 1.0.4
14-
15-
- Fix project pagination in DB usage collector [#4517](https://github.com/appwrite/appwrite/pull/4517)
16-
1713
# Version 1.0.3
1814
## Bugs
1915
- Fix document audit deletion [#4429](https://github.com/appwrite/appwrite/pull/4429)

src/Appwrite/Migration/Migration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class Migration
4545
'1.0.0' => 'V15',
4646
'1.0.1' => 'V15',
4747
'1.0.3' => 'V15',
48-
'1.1.0' => 'V15',
48+
'1.1.0' => 'V16',
4949
];
5050

5151
/**
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
namespace Appwrite\Migration\Version;
4+
5+
use Appwrite\Auth\Auth;
6+
use Appwrite\Migration\Migration;
7+
use Utopia\CLI\Console;
8+
use Utopia\Database\Database;
9+
use Utopia\Database\Document;
10+
11+
class V16 extends Migration
12+
{
13+
public function execute(): void
14+
{
15+
/**
16+
* Disable SubQueries for Performance.
17+
*/
18+
foreach (['subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subqueryVariables'] as $name) {
19+
Database::addFilter(
20+
$name,
21+
fn () => null,
22+
fn () => []
23+
);
24+
}
25+
26+
Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
27+
28+
Console::info('Migrating Collections');
29+
$this->migrateCollections();
30+
31+
Console::info('Migrating Documents');
32+
$this->forEachDocument([$this, 'fixDocument']);
33+
}
34+
35+
/**
36+
* Migrate all Collections.
37+
*
38+
* @return void
39+
*/
40+
protected function migrateCollections(): void
41+
{
42+
foreach ($this->collections as $collection) {
43+
$id = $collection['$id'];
44+
45+
Console::log("Migrating Collection \"{$id}\"");
46+
47+
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
48+
49+
switch ($id) {
50+
case 'sessions':
51+
try {
52+
/**
53+
* Create 'compression' attribute
54+
*/
55+
$this->projectDB->deleteAttribute($id, 'expire');
56+
} catch (\Throwable $th) {
57+
Console::warning("'expire' from {$id}: {$th->getMessage()}");
58+
}
59+
60+
break;
61+
62+
case 'projects':
63+
try {
64+
/**
65+
* Create 'region' attribute
66+
*/
67+
$this->createAttributeFromCollection($this->projectDB, $id, 'region');
68+
} catch (\Throwable $th) {
69+
Console::warning("'region' from {$id}: {$th->getMessage()}");
70+
}
71+
72+
try {
73+
/**
74+
* Create '_key_team' index
75+
*/
76+
$this->createIndexFromCollection($this->projectDB, $id, '_key_team');
77+
} catch (\Throwable $th) {
78+
Console::warning("'_key_team' from {$id}: {$th->getMessage()}");
79+
}
80+
81+
default:
82+
break;
83+
}
84+
85+
usleep(50000);
86+
}
87+
}
88+
89+
/**
90+
* Fix run on each document
91+
*
92+
* @param \Utopia\Database\Document $document
93+
* @return \Utopia\Database\Document
94+
*/
95+
protected function fixDocument(Document $document)
96+
{
97+
switch ($document->getCollection()) {
98+
case 'projects':
99+
/**
100+
* Bump version number.
101+
*/
102+
$document->setAttribute('version', '1.1.0');
103+
104+
/**
105+
* Set default authDuration
106+
*/
107+
$document->setAttribute('auths', array_merge($document->getAttribute('auths', []), [
108+
'duration' => Auth::TOKEN_EXPIRATION_LOGIN_LONG
109+
]));
110+
break;
111+
}
112+
113+
return $document;
114+
}
115+
}

0 commit comments

Comments
 (0)