Skip to content

Commit

Permalink
Allow to specify database storage of upgraded database (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Oct 5, 2021
1 parent 1efad41 commit 0000303
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/Commands/DatabaseUpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function handle()
}

$databaseType = $this->determineDatabaseType($databaseId);
$databaseStorage = $this->determineDatabaseStorage($databaseId, $databaseType);

if (is_null($databaseType)) {
Helpers::danger('No possible upgrades were found for the given database');
Expand All @@ -80,7 +81,8 @@ public function handle()
$this->vapor->upgradeDatabase(
$databaseId,
$this->argument('to'),
$databaseType,
$databaseStorage,
$databaseType
);

Helpers::info('Database upgrade initiated successfully.');
Expand All @@ -107,4 +109,24 @@ protected function determineDatabaseType($databaseId)
);
}
}

/**
* Determine how much storage should be allocated to the database.
*
* @param int $databaseId
* @param string $type
* @return int
*/
protected function determineDatabaseStorage($databaseId, $type)
{
$storage = $this->vapor->database($databaseId)['storage'];

$allocatedStorage = Helpers::ask('What is the maximum amount of storage that may be allocated to your new database (between 25GB and 32768GB) ($0.115 / GB)', $storage);

if ($allocatedStorage < 25 || $allocatedStorage > 32768) {
Helpers::abort('Maximum allocated storage must be between 25GB and 32TB.');
}

return $allocatedStorage;
}
}
4 changes: 3 additions & 1 deletion src/ConsoleVaporClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,15 @@ public function restoreDatabase($databaseId, $name, $restoreTo)
*
* @param string $databaseId
* @param string $name
* @param int $storage
* @param string $type
* @return array
*/
public function upgradeDatabase($databaseId, $name, $type)
public function upgradeDatabase($databaseId, $name, $storage, $type)
{
return $this->requestWithErrorHandling('post', '/api/databases/'.$databaseId.'/upgrades', [
'name' => $name,
'storage' => $storage,
'type' => $type,
]);
}
Expand Down

0 comments on commit 0000303

Please sign in to comment.