feat(migration): version 0.12.x
This commit is contained in:
parent
e47abb3c9a
commit
34e80acb7f
|
@ -1617,8 +1617,8 @@ foreach ($providers as $index => $provider) {
|
|||
foreach ($auth as $index => $method) {
|
||||
$collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'][] = [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||
'label' => $method['name'] || '',
|
||||
'key' => $method['key'] || '',
|
||||
'label' => $method['name'] ?? '',
|
||||
'key' => $method['key'] ?? '',
|
||||
'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN,
|
||||
'default' => true,
|
||||
'required' => false,
|
||||
|
|
|
@ -476,7 +476,7 @@ $collections = [
|
|||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'default' => [],
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
|
@ -487,7 +487,7 @@ $collections = [
|
|||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'default' => [],
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
|
@ -498,7 +498,7 @@ $collections = [
|
|||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'default' => [],
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
|
@ -873,7 +873,7 @@ $collections = [
|
|||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
|
@ -884,7 +884,7 @@ $collections = [
|
|||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
|
@ -990,7 +990,7 @@ $collections = [
|
|||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'default' => [],
|
||||
'array' => false,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
|
@ -1034,7 +1034,7 @@ $collections = [
|
|||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'default' => [],
|
||||
'array' => true,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
|
@ -1045,7 +1045,7 @@ $collections = [
|
|||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'default' => [],
|
||||
'array' => true,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
|
@ -1056,7 +1056,7 @@ $collections = [
|
|||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'default' => [],
|
||||
'array' => true,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
|
@ -1805,7 +1805,7 @@ $collections = [
|
|||
'size' => 8192,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'default' => [],
|
||||
'array' => false,
|
||||
'filters' => ['json', 'encrypt'],
|
||||
],
|
||||
|
|
|
@ -81,10 +81,6 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
|
|||
return $redis;
|
||||
});
|
||||
|
||||
App::setResource('app', function() use (&$app) {
|
||||
return $app;
|
||||
});
|
||||
|
||||
$dbForConsole = $app->getResource('dbForConsole'); /** @var Utopia\Database\Database $dbForConsole */
|
||||
|
||||
if(!$dbForConsole->exists()) {
|
||||
|
|
|
@ -176,7 +176,7 @@ DatabaseOld::addFilter('encrypt',
|
|||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
|
||||
|
||||
return json_encode([
|
||||
'data' => OpenSSL::encrypt($value, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag),
|
||||
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
|
@ -216,7 +216,7 @@ Database::addFilter('enum',
|
|||
return $value;
|
||||
},
|
||||
function($value, Document $attribute) {
|
||||
$formatOptions = json_decode($attribute->getAttribute('formatOptions', []), true);
|
||||
$formatOptions = json_decode($attribute->getAttribute('formatOptions', '[]'), true);
|
||||
if (isset($formatOptions['elements'])) {
|
||||
$attribute->setAttribute('elements', $formatOptions['elements']);
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ Database::addFilter('range',
|
|||
return $value;
|
||||
},
|
||||
function($value, Document $attribute) {
|
||||
$formatOptions = json_decode($attribute->getAttribute('formatOptions', []), true);
|
||||
$formatOptions = json_decode($attribute->getAttribute('formatOptions', '[]'), true);
|
||||
if (isset($formatOptions['min']) || isset($formatOptions['max'])) {
|
||||
$attribute
|
||||
->setAttribute('min', $formatOptions['min'])
|
||||
|
|
|
@ -17,31 +17,46 @@ $cli
|
|||
->task('migrate')
|
||||
->param('version', APP_VERSION_STABLE, new Text(8), 'Version to migrate to.', true)
|
||||
->action(function ($version) use ($register) {
|
||||
Authorization::disable();
|
||||
if (!array_key_exists($version, Migration::$versions)) {
|
||||
Console::error("Version {$version} not found.");
|
||||
Console::exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_starts_with($version, '0.12.')) {
|
||||
Console::error('WARNING');
|
||||
Console::warning('Migrating to Version 0.12.x introduces a major breaking change within the Database Service!');
|
||||
Console::warning('Before migrating, please read about the breaking changes here:');
|
||||
Console::info('https://appwrite.io/guide-to-db-migration');
|
||||
$confirm = Console::confirm("If you want to proceed, type 'yes':");
|
||||
if($confirm != 'yes') {
|
||||
Console::exit(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Config::load('collectionsold' , __DIR__.'/../config/collections.old.php');
|
||||
|
||||
Console::success('Starting Data Migration to version '.$version);
|
||||
|
||||
$db = $register->get('db', true);
|
||||
$cache = $register->get('cache', true);
|
||||
$cache->flushAll();
|
||||
|
||||
$consoleDB = new Database();
|
||||
$consoleDB
|
||||
->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache))
|
||||
->setNamespace('app_console') // Main DB
|
||||
->setMocks(Config::getParam('collections.old', []));
|
||||
->setMocks(Config::getParam('collectionsold', []));
|
||||
|
||||
$projectDB = new Database();
|
||||
$projectDB
|
||||
->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache))
|
||||
->setMocks(Config::getParam('collections.old', []));
|
||||
->setMocks(Config::getParam('collectionsold', []));
|
||||
|
||||
$console = $consoleDB->getDocument('console');
|
||||
|
||||
Authorization::disable();
|
||||
|
||||
$limit = 30;
|
||||
$sum = 30;
|
||||
$offset = 0;
|
||||
|
@ -49,13 +64,13 @@ $cli
|
|||
$count = 0;
|
||||
|
||||
$class = 'Appwrite\\Migration\\Version\\'.Migration::$versions[$version];
|
||||
$migration = new $class($register->get('db'));
|
||||
$migration = new $class($register->get('db'), $register->get('cache'));
|
||||
|
||||
while ($sum > 0) {
|
||||
foreach ($projects as $project) {
|
||||
try {
|
||||
$migration
|
||||
->setProject($project, $projectDB)
|
||||
->setProject($project, $projectDB, $consoleDB)
|
||||
->execute();
|
||||
} catch (\Throwable $th) {
|
||||
throw $th;
|
||||
|
@ -79,6 +94,7 @@ $cli
|
|||
Console::log('Fetched '.$count.'/'.$consoleDB->getSum().' projects...');
|
||||
}
|
||||
}
|
||||
$cache->flushAll();
|
||||
|
||||
Console::success('Data Migration Completed');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue