1
0
Fork 0
mirror of synced 2024-10-02 10:16:27 +13:00

feat: migrate createdAt and updatedAt to collections

This commit is contained in:
Torsten Dittmann 2022-06-21 12:48:56 +02:00
parent 5fd7238ad1
commit ef6768433c

View file

@ -4,12 +4,21 @@ namespace Appwrite\Migration\Version;
use Appwrite\Migration\Migration; use Appwrite\Migration\Migration;
use Utopia\CLI\Console; use Utopia\CLI\Console;
use Utopia\Database\Database;
use Utopia\Database\Document; use Utopia\Database\Document;
class V14 extends Migration class V14 extends Migration
{ {
/**
* @var \PDO $pdo
*/
private $pdo;
public function execute(): void public function execute(): void
{ {
global $register;
$this->pdo = $register->get('db');
Console::log('Migrating project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); Console::log('Migrating project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
Console::info('Migrating Collections'); Console::info('Migrating Collections');
$this->migrateCollections(); $this->migrateCollections();
@ -28,6 +37,18 @@ class V14 extends Migration
$id = $collection['$id']; $id = $collection['$id'];
Console::log("- {$id}"); Console::log("- {$id}");
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()}");
}
usleep(100000);
switch ($id) { switch ($id) {
case 'attributes': case 'attributes':
case 'indexes': case 'indexes':
@ -282,6 +303,9 @@ class V14 extends Migration
*/ */
$document->setAttribute('version', '0.15.0'); $document->setAttribute('version', '0.15.0');
break;
case '':
break; break;
} }