Skip to content

Commit

Permalink
Update postgres support (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon authored Jul 22, 2022
1 parent 3addc50 commit 30b85e6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
23 changes: 13 additions & 10 deletions src/Commands/DatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public function handle()

$public = $this->determineIfPublic();

if (! $public &&
if (
! $public &&
! $this->networkHasNatGateway($networkId) &&
! Helpers::confirm('A private database will require Vapor to add a NAT gateway to your network (~32 / month). Would you like to proceed', true)) {
! Helpers::confirm('A private database will require Vapor to add a NAT gateway to your network (~32 / month). Would you like to proceed', true)
) {
Helpers::abort('Action cancelled.');
}

Expand All @@ -57,7 +59,7 @@ public function handle()
$allocatedStorage = $this->determineAllocatedStorage($databaseType);

$pause = $databaseType == 'aurora-serverless' &&
Helpers::confirm('To reduce your bill, should the database pause during periods of inactivity', false);
Helpers::confirm('To reduce your bill, should the database pause during periods of inactivity', false);

$response = $this->vapor->createDatabase(
$networkId,
Expand Down Expand Up @@ -113,10 +115,10 @@ protected function determineDatabaseType($public)
'aurora-serverless' => 'Serverless v1 MySQL 5.7 Aurora Cluster',
'aurora-serverless-v2' => 'Serverless v2 MySQL 8.0 Aurora Cluster',
'rds-pgsql-13.4' => 'Fixed Size PostgreSQL Instance 13.4',
'rds-pgsql-11.10' => 'Fixed Size PostgreSQL Instance 11.10',
'aurora-serverless-pgsql' => 'Serverless PostgreSQL Aurora Cluster',
'aurora-serverless-pgsql' => 'Serverless PostgreSQL 10.7 Aurora Cluster',
'aurora-serverless-v2-pgsql' => 'Serverless v2 PostgreSQL 14.3 Aurora Cluster',
]), function ($type) use ($public) {
if (in_array($type, ['aurora-serverless', 'aurora-serverless-v2', 'aurora-serverless-pgsql']) && $public) {
if (in_array($type, ['aurora-serverless', 'aurora-serverless-v2', 'aurora-serverless-pgsql', 'aurora-serverless-v2-pgsql']) && $public) {
Helpers::abort('Aurora Serverless clusters may not be publicly accessible.');
}
});
Expand All @@ -138,10 +140,11 @@ protected function determineInstanceClass($type)
return;
}

if ($type == 'rds'
if (
$type == 'rds'
|| $type == 'rds-mysql-5.7'
|| $type == 'rds-pgsql-11.10'
|| $type == 'rds-pgsql-13.4') {
|| $type == 'rds-pgsql-13.4'
) {
return $this->determineRdsInstanceClass();
}
}
Expand Down Expand Up @@ -179,7 +182,7 @@ protected function determineRdsInstanceClass()
*/
protected function determineAllocatedStorage($type)
{
if (in_array($type, ['aurora-serverless', 'aurora-serverless-v2', 'aurora-serverless-pgsql'])) {
if (in_array($type, ['aurora-serverless', 'aurora-serverless-v2', 'aurora-serverless-pgsql', 'aurora-serverless-v2-pgsql'])) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DatabaseListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function handle()
$database['cloud_provider']['name'],
$database['name'],
$database['region'],
in_array($database['type'], ['aurora-serverless', 'aurora-serverless-v2', 'aurora-serverless-pgsql'])
in_array($database['type'], ['aurora-serverless', 'aurora-serverless-v2', 'aurora-serverless-pgsql', 'aurora-serverless-v2-pgsql'])
? 'Serverless'
: 'Fixed Size',
$database['instance_class'],
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DatabaseShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function handle()
$database['cloud_provider']['name'],
$database['name'],
$database['region'],
in_array($database['type'], ['aurora-serverless', 'aurora-serverless-v2', 'aurora-serverless-pgsql']) ? 'Serverless' : 'Fixed Size',
in_array($database['type'], ['aurora-serverless', 'aurora-serverless-v2', 'aurora-serverless-pgsql', 'aurora-serverless-v2-pgsql']) ? 'Serverless' : 'Fixed Size',
$database['instance_class'],
$database['storage'].'GB',
Str::title(str_replace('_', ' ', $database['status'])),
Expand Down
15 changes: 8 additions & 7 deletions src/Commands/DatabaseUpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class DatabaseUpgradeCommand extends Command
'aurora-serverless' => 'Serverless v1 MySQL 5.7 Aurora Cluster',
'aurora-serverless-v2' => 'Serverless v2 MySQL 8.0 Aurora Cluster',
'rds-pgsql-13.4' => 'Fixed Size PostgreSQL Instance 13.4',
'rds-pgsql-11.10' => 'Fixed Size PostgreSQL Instance 11.10',
'rds-pgsql' => 'Fixed Size PostgreSQL Instance 10.7',
'aurora-serverless-pgsql' => 'Serverless PostgreSQL Aurora Cluster',
'aurora-serverless-pgsql' => 'Serverless PostgreSQL 10.7 Aurora Cluster',
'aurora-serverless-v2-pgsql' => 'Serverless v2 PostgreSQL 14.3 Aurora Cluster',
];

/**
Expand All @@ -31,7 +31,6 @@ class DatabaseUpgradeCommand extends Command
*/
protected $possibleUpgrades = [
'rds-mysql-5.7' => ['rds'],
'rds-pgsql' => ['rds-pgsql-11.10'],
];

/**
Expand Down Expand Up @@ -104,10 +103,12 @@ protected function determineDatabaseType($databaseId)
$possibleUpgrades = Arr::get($this->possibleUpgrades, $databaseType, []);

if (! empty($possibleUpgrades)) {
return $this->menu('Which type of database would you like to create?', collect($this->databaseTypes)
->filter(function ($label, $type) use ($possibleUpgrades) {
return in_array($type, $possibleUpgrades);
})->all()
return $this->menu(
'Which type of database would you like to create?',
collect($this->databaseTypes)
->filter(function ($label, $type) use ($possibleUpgrades) {
return in_array($type, $possibleUpgrades);
})->all()
);
}
}
Expand Down

0 comments on commit 30b85e6

Please sign in to comment.