1
0
Fork 0
mirror of synced 2024-07-04 06:00:53 +12:00

feat: migration

This commit is contained in:
Torsten Dittmann 2023-04-24 13:00:23 +02:00
parent 5925d61a9c
commit ff82a24a4b
4 changed files with 51 additions and 16 deletions

View file

@ -115,12 +115,6 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
if (!$dbForConsole->getCollection($key)->isEmpty()) { if (!$dbForConsole->getCollection($key)->isEmpty()) {
continue; continue;
} }
/**
* Skip to prevent 0.16 migration issues.
*/
if (in_array($key, ['cache', 'variables']) && $dbForConsole->exists(App::getEnv('_APP_DB_SCHEMA', 'appwrite'), 'bucket_1')) {
continue;
}
Console::success('[Setup] - Creating collection: ' . $collection['$id'] . '...'); Console::success('[Setup] - Creating collection: ' . $collection['$id'] . '...');
@ -215,6 +209,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
} }
Console::success('[Setup] - Server database init completed...'); Console::success('[Setup] - Server database init completed...');
var_dump($dbForConsole->find(Database::METADATA));
}); });
Console::success('Server started successfully (max payload is ' . number_format($payloadSize) . ' bytes)'); Console::success('Server started successfully (max payload is ' . number_format($payloadSize) . ' bytes)');

20
composer.lock generated
View file

@ -2113,12 +2113,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/database.git", "url": "https://github.com/utopia-php/database.git",
"reference": "6ce621ac9d97e3ff18e1595c328526b3050ab68b" "reference": "c3dfecc21e3b8ce8f233425150b4a330739806b5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/6ce621ac9d97e3ff18e1595c328526b3050ab68b", "url": "https://api.github.com/repos/utopia-php/database/zipball/c3dfecc21e3b8ce8f233425150b4a330739806b5",
"reference": "6ce621ac9d97e3ff18e1595c328526b3050ab68b", "reference": "c3dfecc21e3b8ce8f233425150b4a330739806b5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2163,7 +2163,7 @@
"issues": "https://github.com/utopia-php/database/issues", "issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/feat-collection-level-permissions" "source": "https://github.com/utopia-php/database/tree/feat-collection-level-permissions"
}, },
"time": "2023-04-21T10:56:21+00:00" "time": "2023-04-24T09:13:37+00:00"
}, },
{ {
"name": "utopia-php/domains", "name": "utopia-php/domains",
@ -3784,16 +3784,16 @@
}, },
{ {
"name": "phpstan/phpdoc-parser", "name": "phpstan/phpdoc-parser",
"version": "1.20.0", "version": "1.20.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git", "url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "10553ab3f0337ff1a71433c3417d7eb2a3eec1fd" "reference": "90490bd8fd8530a272043c4950c180b6d0cf5f81"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/10553ab3f0337ff1a71433c3417d7eb2a3eec1fd", "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/90490bd8fd8530a272043c4950c180b6d0cf5f81",
"reference": "10553ab3f0337ff1a71433c3417d7eb2a3eec1fd", "reference": "90490bd8fd8530a272043c4950c180b6d0cf5f81",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3823,9 +3823,9 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types", "description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": { "support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues", "issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.0" "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.2"
}, },
"time": "2023-04-20T11:18:07+00:00" "time": "2023-04-22T12:59:35+00:00"
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",

View file

@ -37,6 +37,9 @@ abstract class Migration
*/ */
protected Database $consoleDB; protected Database $consoleDB;
/**
* @var \PDO
*/
protected \PDO $pdo; protected \PDO $pdo;
/** /**
@ -102,6 +105,12 @@ abstract class Migration
return $this; return $this;
} }
/**
* Set PDO for Migration.
*
* @param \PDO $pdo
* @return \Appwrite\Migration\Migration
*/
public function setPDO(\PDO $pdo): self public function setPDO(\PDO $pdo): self
{ {
$this->pdo = $pdo; $this->pdo = $pdo;

View file

@ -25,6 +25,7 @@ class V18 extends Migration
Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')'); Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
$this->projectDB->setNamespace("_{$this->project->getInternalId()}"); $this->projectDB->setNamespace("_{$this->project->getInternalId()}");
$this->addDocumentSecurityToProject();
Console::info('Migrating Databases'); Console::info('Migrating Databases');
$this->migrateDatabases(); $this->migrateDatabases();
@ -58,6 +59,15 @@ class V18 extends Migration
} }
$this->changeAttributeInternalType($collectionTable, $attribute['key'], 'DOUBLE'); $this->changeAttributeInternalType($collectionTable, $attribute['key'], 'DOUBLE');
} }
try {
$documentSecurity = $collection->getAttribute('documentSecurity', false);
$permissions = $collection->getPermissions();
$this->projectDB->updateCollection($collectionTable, $permissions, $documentSecurity);
} catch (\Throwable $th) {
Console::warning($th->getMessage());
}
} }
} }
} }
@ -168,4 +178,25 @@ class V18 extends Migration
return $document; return $document;
} }
protected function addDocumentSecurityToProject(): void
{
try {
/**
* Create 'documentSecurity' column
*/
$this->pdo->prepare("ALTER TABLE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}__metadata` ADD COLUMN IF NOT EXISTS documentSecurity TINYINT(1);")->execute();
} catch (\Throwable $th) {
Console::warning($th->getMessage());
}
try {
/**
* Set 'documentSecurity' column to 1 if NULL
*/
$this->pdo->prepare("UPDATE `{$this->projectDB->getDefaultDatabase()}`.`_{$this->project->getInternalId()}__metadata` SET documentSecurity = 1 WHERE documentSecurity IS NULL")->execute();
} catch (\Throwable $th) {
Console::warning($th->getMessage());
}
}
} }