fix: migration
This commit is contained in:
parent
2015106702
commit
0c5e9eed33
24
composer.lock
generated
24
composer.lock
generated
|
@ -5655,16 +5655,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/console",
|
"name": "symfony/console",
|
||||||
"version": "v6.0.1",
|
"version": "v6.0.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/console.git",
|
"url": "https://github.com/symfony/console.git",
|
||||||
"reference": "fafd9802d386bf1c267e0249ddb7ceb14dcfdad4"
|
"reference": "dd434fa8d69325e5d210f63070014d889511fcb3"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/console/zipball/fafd9802d386bf1c267e0249ddb7ceb14dcfdad4",
|
"url": "https://api.github.com/repos/symfony/console/zipball/dd434fa8d69325e5d210f63070014d889511fcb3",
|
||||||
"reference": "fafd9802d386bf1c267e0249ddb7ceb14dcfdad4",
|
"reference": "dd434fa8d69325e5d210f63070014d889511fcb3",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -5730,7 +5730,7 @@
|
||||||
"terminal"
|
"terminal"
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/console/tree/v6.0.1"
|
"source": "https://github.com/symfony/console/tree/v6.0.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -5746,7 +5746,7 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2021-12-09T12:47:37+00:00"
|
"time": "2021-12-27T21:05:08+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/polyfill-intl-grapheme",
|
"name": "symfony/polyfill-intl-grapheme",
|
||||||
|
@ -6077,16 +6077,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/string",
|
"name": "symfony/string",
|
||||||
"version": "v6.0.1",
|
"version": "v6.0.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/string.git",
|
"url": "https://github.com/symfony/string.git",
|
||||||
"reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32"
|
"reference": "bae261d0c3ac38a1f802b4dfed42094296100631"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/string/zipball/0cfed595758ec6e0a25591bdc8ca733c1896af32",
|
"url": "https://api.github.com/repos/symfony/string/zipball/bae261d0c3ac38a1f802b4dfed42094296100631",
|
||||||
"reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32",
|
"reference": "bae261d0c3ac38a1f802b4dfed42094296100631",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -6142,7 +6142,7 @@
|
||||||
"utf8"
|
"utf8"
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/string/tree/v6.0.1"
|
"source": "https://github.com/symfony/string/tree/v6.0.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -6158,7 +6158,7 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2021-12-08T15:13:44+00:00"
|
"time": "2021-12-16T22:13:01+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "textalk/websocket",
|
"name": "textalk/websocket",
|
||||||
|
|
|
@ -42,6 +42,7 @@ class V11 extends Migration
|
||||||
$this->options = array_map(fn ($option) => $option === 'yes' ? true : false, $this->options);
|
$this->options = array_map(fn ($option) => $option === 'yes' ? true : false, $this->options);
|
||||||
|
|
||||||
if (!is_null($cache)) {
|
if (!is_null($cache)) {
|
||||||
|
$this->cache->flushAll();
|
||||||
$cacheAdapter = new Cache(new RedisCache($this->cache));
|
$cacheAdapter = new Cache(new RedisCache($this->cache));
|
||||||
$this->dbProject = new Database(new MariaDB($this->db), $cacheAdapter); // namespace is set on execution
|
$this->dbProject = new Database(new MariaDB($this->db), $cacheAdapter); // namespace is set on execution
|
||||||
$this->dbConsole = new Database(new MariaDB($this->db), $cacheAdapter);
|
$this->dbConsole = new Database(new MariaDB($this->db), $cacheAdapter);
|
||||||
|
@ -63,6 +64,7 @@ class V11 extends Migration
|
||||||
$oldProject = $this->project;
|
$oldProject = $this->project;
|
||||||
|
|
||||||
$this->dbProject->setNamespace('_project_' . $oldProject->getId());
|
$this->dbProject->setNamespace('_project_' . $oldProject->getId());
|
||||||
|
$this->dbConsole->setNamespace('_project_console');
|
||||||
|
|
||||||
Console::info('');
|
Console::info('');
|
||||||
Console::info('------------------------------------');
|
Console::info('------------------------------------');
|
||||||
|
@ -73,7 +75,12 @@ class V11 extends Migration
|
||||||
* Create internal/external structure for projects and skip the console project.
|
* Create internal/external structure for projects and skip the console project.
|
||||||
*/
|
*/
|
||||||
if ($oldProject->getId() !== 'console') {
|
if ($oldProject->getId() !== 'console') {
|
||||||
$project = $this->dbConsole->getDocument('projects', $oldProject->getId());
|
try {
|
||||||
|
$project = $this->dbConsole->getDocument(collection: 'projects', id: $oldProject->getId());
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
var_dump($th->getTraceAsString());
|
||||||
|
var_dump($th);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migrate Project Document.
|
* Migrate Project Document.
|
||||||
|
@ -88,10 +95,10 @@ class V11 extends Migration
|
||||||
/**
|
/**
|
||||||
* Create internal tables
|
* Create internal tables
|
||||||
*/
|
*/
|
||||||
if (!$this->dbProject->exists('appwrite')) {
|
try {
|
||||||
$this->dbProject->create('appwrite');
|
|
||||||
Console::log('Created internal tables for : ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
|
Console::log('Created internal tables for : ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
|
||||||
}
|
$this->dbProject->createMetadata();
|
||||||
|
} catch (\Throwable $th) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Audit tables
|
* Create Audit tables
|
||||||
|
@ -197,10 +204,6 @@ class V11 extends Migration
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::error('Failed to update document: ' . $th->getMessage());
|
Console::error('Failed to update document: ' . $th->getMessage());
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ($document && $new->getId() !== $document->getId()) {
|
|
||||||
throw new Exception('Duplication Error');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +273,7 @@ class V11 extends Migration
|
||||||
'dateCreated' => time(),
|
'dateCreated' => time(),
|
||||||
'dateUpdated' => time(),
|
'dateUpdated' => time(),
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
'enabled' => true,
|
||||||
'search' => implode(' ', [$id, $name]),
|
'search' => implode(' ', [$id, $name]),
|
||||||
]));
|
]));
|
||||||
} else {
|
} else {
|
||||||
|
@ -284,7 +288,7 @@ class V11 extends Migration
|
||||||
foreach ($attributes as $attribute) {
|
foreach ($attributes as $attribute) {
|
||||||
try {
|
try {
|
||||||
$this->dbProject->createAttribute(
|
$this->dbProject->createAttribute(
|
||||||
collection: $attribute['$collection'],
|
collection: 'collection_' . $attribute['$collection'],
|
||||||
id: $attribute['$id'],
|
id: $attribute['$id'],
|
||||||
type: $attribute['type'],
|
type: $attribute['type'],
|
||||||
size: $attribute['size'],
|
size: $attribute['size'],
|
||||||
|
@ -296,7 +300,6 @@ class V11 extends Migration
|
||||||
formatOptions: $attribute['formatOptions'] ?? [],
|
formatOptions: $attribute['formatOptions'] ?? [],
|
||||||
filters: $attribute['filters']
|
filters: $attribute['filters']
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->dbProject->createDocument('attributes', new Document([
|
$this->dbProject->createDocument('attributes', new Document([
|
||||||
'$id' => $attribute['$collection'] . '_' . $attribute['$id'],
|
'$id' => $attribute['$collection'] . '_' . $attribute['$id'],
|
||||||
'key' => $attribute['$id'],
|
'key' => $attribute['$id'],
|
||||||
|
@ -426,7 +429,30 @@ class V11 extends Migration
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($document->getAttribute('$collection')) {
|
switch ($document->getAttribute('$collection')) {
|
||||||
case OldDatabase::SYSTEM_COLLECTION_PLATFORMS:
|
case OldDatabase::SYSTEM_COLLECTION_PROJECTS:
|
||||||
|
$newProviders = [];
|
||||||
|
$providers = Config::getParam('providers', []);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add enabled OAuth2 providers to default data rules
|
||||||
|
*/
|
||||||
|
foreach ($providers as $index => $provider) {
|
||||||
|
$appId = $document->getAttribute('usersOauth2'.\ucfirst($index).'Appid');
|
||||||
|
$appSecret = $document->getAttribute('usersOauth2'.\ucfirst($index).'Secret');
|
||||||
|
|
||||||
|
if (!is_null($appId) || !is_null($appId)) {
|
||||||
|
$newProviders[$appId] = $appSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
$document
|
||||||
|
->removeAttribute('usersOauth2'.\ucfirst($index).'Appid')
|
||||||
|
->removeAttribute('usersOauth2'.\ucfirst($index).'Secret');
|
||||||
|
}
|
||||||
|
|
||||||
|
$document->setAttribute('providers', $newProviders);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case OldDatabase::SYSTEM_COLLECTION_PLATFORMS:
|
||||||
$projectId = $this->getProjectIdFromReadPermissions($document);
|
$projectId = $this->getProjectIdFromReadPermissions($document);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue