|
6 | 6 |
|
7 | 7 | use Appwrite\Migration\Version\V25; |
8 | 8 | use PHPUnit\Framework\TestCase; |
| 9 | +use Utopia\Cache\Adapter\None as NoCache; |
| 10 | +use Utopia\Cache\Cache; |
| 11 | +use Utopia\Config\Config; |
| 12 | +use Utopia\Database\Adapter\Memory; |
| 13 | +use Utopia\Database\Database; |
9 | 14 | use Utopia\Database\Document; |
| 15 | +use Utopia\Database\Validator\Authorization; |
10 | 16 | use Utopia\Migration\Resource; |
11 | 17 |
|
12 | 18 | final class V25Test extends TestCase |
@@ -121,6 +127,41 @@ protected function resolveInternalIds(string $parentResourceId, string $resource |
121 | 127 | $this->assertSame($afterResolution, $document->getArrayCopy()); |
122 | 128 | } |
123 | 129 |
|
| 130 | + public function testCreatesPushLedgerForProjectFromPreviousRelease(): void |
| 131 | + { |
| 132 | + $authorization = new Authorization(); |
| 133 | + $database = new Database(new Memory(), new Cache(new NoCache())); |
| 134 | + $database |
| 135 | + ->setAuthorization($authorization) |
| 136 | + ->setDatabase('migrationTests') |
| 137 | + ->setNamespace('v25_' . \uniqid()); |
| 138 | + $database->create(); |
| 139 | + |
| 140 | + // A project created on 2.2.0 has every collection except pushLedger. |
| 141 | + $collections = Config::getParam('collections', [])['projects']; |
| 142 | + foreach ($collections as $id => $collection) { |
| 143 | + if ($id === 'pushLedger' || ($collection['$collection'] ?? null) !== Database::METADATA) { |
| 144 | + continue; |
| 145 | + } |
| 146 | + $database->createCollection( |
| 147 | + $id, |
| 148 | + \array_map(fn (array $attribute) => new Document($attribute), $collection['attributes']), |
| 149 | + \array_map(fn (array $index) => new Document($index), $collection['indexes']), |
| 150 | + ); |
| 151 | + } |
| 152 | + $database->createCollection('audit'); |
| 153 | + |
| 154 | + $migration = new V25(); |
| 155 | + $migration->setProject(new Document(['$id' => 'project', '$sequence' => '1']), $database, $database, $authorization); |
| 156 | + $migration->execute(); |
| 157 | + |
| 158 | + $this->assertFalse($database->getCollection('pushLedger')->isEmpty()); |
| 159 | + |
| 160 | + $migration->execute(); |
| 161 | + |
| 162 | + $this->assertFalse($database->getCollection('pushLedger')->isEmpty()); |
| 163 | + } |
| 164 | + |
124 | 165 | public function testRejectsResourcesCreatedAfterMigration(): void |
125 | 166 | { |
126 | 167 | $migration = new class () extends V25 { |
|
0 commit comments