diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 0b6a34ee95..f702bb7ac7 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -242,7 +242,6 @@ abstract class Migration public function createAttributeFromCollection(Database $database, string $collectionId, string $attributeId): void { $collection = Config::getParam('collections', [])[$collectionId] ?? null; - if (is_null($collection)) { throw new Exception("Collection {$collectionId} not found"); } @@ -250,7 +249,7 @@ abstract class Migration $attributeKey = array_search($attributeId, array_column($attributes, '$id')); - if (!$attributeKey) { + if ($attributeKey === false) { throw new Exception("Attribute {$attributeId} not found"); } diff --git a/src/Appwrite/Migration/Version/V14.php b/src/Appwrite/Migration/Version/V14.php index b6312381a8..dd5dc4fa67 100644 --- a/src/Appwrite/Migration/Version/V14.php +++ b/src/Appwrite/Migration/Version/V14.php @@ -40,15 +40,39 @@ class V14 extends Migration try { $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getId()}_{$id}` RENAME TO `_{$this->project->getInternalId()}_{$id}`")->execute(); - $this->pdo->prepare("ALTER TABLE `_{$this->project->getInternalId()}_{$id}` ADD `_createdAt` int unsigned DEFAULT NULL")->execute(); - $this->pdo->prepare("ALTER TABLE `_{$this->project->getInternalId()}_{$id}` ADD `_updatedAt` int unsigned DEFAULT NULL")->execute(); - $this->pdo->prepare("CREATE INDEX `_created_at` ON `_{$this->project->getInternalId()}_{$id}` (`_createdAt`)")->execute(); - $this->pdo->prepare("CREATE INDEX `_updatedAt` ON `_{$this->project->getInternalId()}_{$id}` (`_updatedAt`)")->execute(); } catch (\Throwable $th) { Console::warning("Migrating {$id} Collection: {$th->getMessage()}"); } + try { + $this->pdo->prepare("ALTER TABLE IF EXISTS `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getId()}_{$id}_perms` RENAME TO `_{$this->project->getInternalId()}_{$id}_perms`")->execute(); + } catch (\Throwable $th) { + Console::warning("Migrating {$id} Collection: {$th->getMessage()}"); + } + try { + $this->pdo->prepare("ALTER TABLE `_{$this->project->getInternalId()}_{$id}` ADD COLUMN IF NOT EXISTS `_createdAt` int unsigned DEFAULT NULL")->execute(); + } catch (\Throwable $th) { + Console::warning("Migrating {$id} Collection: {$th->getMessage()}"); + } + try { + $this->pdo->prepare("ALTER TABLE `_{$this->project->getInternalId()}_{$id}` ADD COLUMN IF NOT EXISTS `_updatedAt` int unsigned DEFAULT NULL")->execute(); + } catch (\Throwable $th) { + Console::warning("Migrating {$id} Collection: {$th->getMessage()}"); + } + try { + $this->pdo->prepare("CREATE INDEX IF NOT EXISTS `_created_at` ON `_{$this->project->getInternalId()}_{$id}` (`_createdAt`)")->execute(); + } catch (\Throwable $th) { + Console::warning("Migrating {$id} Collection: {$th->getMessage()}"); + } + try { + $this->pdo->prepare("CREATE INDEX IF NOT EXISTS `_updatedAt` ON `_{$this->project->getInternalId()}_{$id}` (`_updatedAt`)")->execute(); + } catch (\Throwable $th) { + Console::warning("Migrating {$id} Collection: {$th->getMessage()}"); + } + usleep(100000); + $this->projectDB->setNamespace("_{$this->project->getInternalId()}"); + switch ($id) { case 'attributes': case 'indexes': @@ -303,9 +327,6 @@ class V14 extends Migration */ $document->setAttribute('version', '0.15.0'); - break; - case '': - break; }