Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat split migrations #8144

Open
wants to merge 9 commits into
base: refactor-usage-sn
Choose a base branch
from

Conversation

PineappleIOnic
Copy link
Member

@PineappleIOnic PineappleIOnic commented May 17, 2024

What does this PR do?

This PR splits migrations out so it can be handled by multiple workers

Test Plan

Tested locally for Appwrite, still need to test firebase, and other adapters. Will tick off as I go

  • Firebase
  • Supabase
  • NHost

This is a DB Breaking change, a migration will be needed.

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@@ -34,12 +34,6 @@ public function __construct()
'default' => '',
'example' => 'pending',
])
->addRule('stage', [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the difference between stage and status? why is this removed?

This needs to be released as a patch version so we should not have breaking changes. If it has to be removed, then we need a response filter for it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a response filter, please re-review

Comment on lines -627 to -651
- _APP_MIGRATIONS_FIREBASE_CLIENT_ID
- _APP_MIGRATIONS_FIREBASE_CLIENT_SECRET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're never rolling out firebase OAuth so I just removed it while I was there

@PineappleIOnic PineappleIOnic changed the base branch from main to refactor-usage-sn May 28, 2024 05:37
@PineappleIOnic
Copy link
Member Author

@christyjacob4 I rebased this to refactor-usage-sn so we can get this onto cloud easier

@@ -4138,6 +4117,106 @@
]
],
],
'groupMigrations' => [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'groupMigrations' => [
'migrationsGroup' => [

Comment on lines +44 to +47
if (!empty(array_intersect(
$groupResources,
$resources
))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move this to a variable and reuse it on L53

$migration = $dbForProject->createDocument('migrations', new Document([
'$id' => ID::unique(),
'status' => 'pending',
'stage' => 'init',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets keep the stage attribute since its required. We can attempt to remove it during the 1.6 migrations for example

@@ -163,7 +157,7 @@ protected function updateMigrationDocument(Document $migration, Document $projec
roles: $target['roles'],
);

return $this->dbForProject->updateDocument('migrations', $migration->getId(), $migration);
return $this->dbForProject->updateDocument($migration->getCollection(), $migration->getId(), $migration);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change required?

Comment on lines 257 to +261
$log->addBreadcrumb(new Breadcrumb("debug", "migration", "Migration hit stage 'processing'", \microtime(true)));
$this->updateMigrationDocument($migrationDocument, $projectDocument);

$log->addTag('type', $migrationDocument->getAttribute('source'));
$this->updateMigrationDocument($migration, $projectDocument);

$log->addTag('type', $migration->getAttribute('source'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets group the logger related statements together and the migrations related statements together

Comment on lines +281 to +296
switch ($group->getAttribute('group')) {
case Transfer::GROUP_AUTH:
$resources = array_intersect(Transfer::GROUP_AUTH_RESOURCES, $resources);
break;
case Transfer::GROUP_STORAGE:
$resources = array_intersect(Transfer::GROUP_STORAGE_RESOURCES, $resources);
break;
case Transfer::GROUP_DATABASES:
$resources = array_intersect(Transfer::GROUP_DATABASES_RESOURCES, $resources);
break;
case Transfer::GROUP_FUNCTIONS:
$resources = array_intersect(Transfer::GROUP_FUNCTIONS_RESOURCES, $resources);
break;
default:
throw new Exception('Migration worker was initialized with unknown group');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already did an array_intersect in the API level. This doesn't seem to be required


$status = $document->getAttribute('status', 'processing');

if ($status == 'processing' || $status == 'pending') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($status == 'processing' || $status == 'pending') {
if ($status === 'processing' || $status === 'pending') {

Comment on lines +355 to +357
if ($status == 'failed') {
break;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($status == 'failed') {
break;
}
if ($status === 'failed') {
$result = 'failed';
break;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants