This commit is contained in:
shimon 2024-02-01 22:14:09 +02:00
parent a254bb7edb
commit 883cfedc46
2 changed files with 25 additions and 5 deletions

View file

@ -72,9 +72,26 @@ class V20 extends Migration
default => 'projects', default => 'projects',
}; };
$databases = $this->projectDB->find('databases', []); // Support database array type migration (user collections)
foreach ($databases as $database) { $attributes = $this->projectDB->find('attributes', [
var_dump($database); Query::equal('array', [true]),
]);
foreach ($attributes as $attribute) {
$indexes = $this->projectDB->find('indexes', [
Query::equal('databaseInternalId', [$attribute['databaseInternalId']]),
Query::equal('collectionInternalId', [$attribute['collectionInternalId']]),
]);
$foundIndex = 0;
foreach ($indexes as $index) {
if (in_array($attribute['key'], $index['attributes'])) {
$this->projectDB->deleteIndex($index['collectionId'], $index['_uid']);
$foundIndex = 1;
}
}
if ($foundIndex === 1) {
$this->projectDB->updateAttribute($attribute['collectionInternalId'], $attribute['key'], Database::VAR_STRING);
}
} }
$collections = $this->collections[$collectionType]; $collections = $this->collections[$collectionType];
@ -86,14 +103,18 @@ class V20 extends Migration
$this->projectDB->setNamespace("_$internalProjectId"); $this->projectDB->setNamespace("_$internalProjectId");
// Support database array type migration // Support database array type migration
$foundIndex = 0;
foreach ($collection['attributes'] ?? [] as $attribute) { foreach ($collection['attributes'] ?? [] as $attribute) {
if ($attribute['array'] === true) { if ($attribute['array'] === true) {
foreach ($collection['indexes'] ?? [] as $index) { foreach ($collection['indexes'] ?? [] as $index) {
if (in_array($attribute['$id'], $index['attributes'])) { if (in_array($attribute['$id'], $index['attributes'])) {
$this->projectDB->deleteIndex($id, $index['$id']); $this->projectDB->deleteIndex($id, $index['$id']);
$foundIndex = 1;
} }
} }
$this->projectDB->updateAttribute($id, $attribute['$id'], Database::VAR_STRING); if ($foundIndex === 1) {
$this->projectDB->updateAttribute($id, $attribute['$id'], Database::VAR_STRING);
}
} }
} }

View file

@ -93,7 +93,6 @@ class Migrate extends Action
// TODO: Iterate through all project DBs // TODO: Iterate through all project DBs
/** @var Database $projectDB */ /** @var Database $projectDB */
$projectDB = $getProjectDB($project); $projectDB = $getProjectDB($project);
var_dump($project);
$migration $migration
->setProject($project, $projectDB, $dbForConsole) ->setProject($project, $projectDB, $dbForConsole)
->setPDO($register->get('db', true)) ->setPDO($register->get('db', true))