feat: migration
This commit is contained in:
parent
5925d61a9c
commit
ff82a24a4b
4 changed files with 51 additions and 16 deletions
|
@ -115,12 +115,6 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
|
|||
if (!$dbForConsole->getCollection($key)->isEmpty()) {
|
||||
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'] . '...');
|
||||
|
||||
|
@ -215,6 +209,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
|
|||
}
|
||||
|
||||
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)');
|
||||
|
|
20
composer.lock
generated
20
composer.lock
generated
|
@ -2113,12 +2113,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database.git",
|
||||
"reference": "6ce621ac9d97e3ff18e1595c328526b3050ab68b"
|
||||
"reference": "c3dfecc21e3b8ce8f233425150b4a330739806b5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/6ce621ac9d97e3ff18e1595c328526b3050ab68b",
|
||||
"reference": "6ce621ac9d97e3ff18e1595c328526b3050ab68b",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/c3dfecc21e3b8ce8f233425150b4a330739806b5",
|
||||
"reference": "c3dfecc21e3b8ce8f233425150b4a330739806b5",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2163,7 +2163,7 @@
|
|||
"issues": "https://github.com/utopia-php/database/issues",
|
||||
"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",
|
||||
|
@ -3784,16 +3784,16 @@
|
|||
},
|
||||
{
|
||||
"name": "phpstan/phpdoc-parser",
|
||||
"version": "1.20.0",
|
||||
"version": "1.20.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpstan/phpdoc-parser.git",
|
||||
"reference": "10553ab3f0337ff1a71433c3417d7eb2a3eec1fd"
|
||||
"reference": "90490bd8fd8530a272043c4950c180b6d0cf5f81"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/10553ab3f0337ff1a71433c3417d7eb2a3eec1fd",
|
||||
"reference": "10553ab3f0337ff1a71433c3417d7eb2a3eec1fd",
|
||||
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/90490bd8fd8530a272043c4950c180b6d0cf5f81",
|
||||
"reference": "90490bd8fd8530a272043c4950c180b6d0cf5f81",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -3823,9 +3823,9 @@
|
|||
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
||||
"support": {
|
||||
"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",
|
||||
|
|
|
@ -37,6 +37,9 @@ abstract class Migration
|
|||
*/
|
||||
protected Database $consoleDB;
|
||||
|
||||
/**
|
||||
* @var \PDO
|
||||
*/
|
||||
protected \PDO $pdo;
|
||||
|
||||
/**
|
||||
|
@ -102,6 +105,12 @@ abstract class Migration
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PDO for Migration.
|
||||
*
|
||||
* @param \PDO $pdo
|
||||
* @return \Appwrite\Migration\Migration
|
||||
*/
|
||||
public function setPDO(\PDO $pdo): self
|
||||
{
|
||||
$this->pdo = $pdo;
|
||||
|
|
|
@ -25,6 +25,7 @@ class V18 extends Migration
|
|||
|
||||
Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
|
||||
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
|
||||
$this->addDocumentSecurityToProject();
|
||||
|
||||
Console::info('Migrating Databases');
|
||||
$this->migrateDatabases();
|
||||
|
@ -58,6 +59,15 @@ class V18 extends Migration
|
|||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue