From 668a631e4c23c62302c1d29f8f042f0e0393f29e Mon Sep 17 00:00:00 2001 From: marc Date: Tue, 3 Dec 2024 13:58:41 +0100 Subject: [PATCH] add byodb source and ST support --- src/Config.php | 40 +++++++++++++++++++------- src/Configuration/ConfigDefinition.php | 1 + 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Config.php b/src/Config.php index 81de980..2fac271 100644 --- a/src/Config.php +++ b/src/Config.php @@ -39,7 +39,7 @@ class Config extends BaseConfig 'account' => 'NE35810', 'region' => 'GCP_US_EAST4', ], - 'coates.keboola.cloud' => [ + 'connection.coates.keboola.cloud' => [ 'db_replica_prefix' => 'COATESAWSUS', 'db_prefix' => 'KBC_AWSUSE1', 'account' => 'ALB08210', @@ -98,6 +98,12 @@ public function getTargetWarehouse(): string public function getSourceDatabaseAccount(): string { + if ($this->isSourceByodb()) { + $sourceByodb = $this->getValue(['parameters', 'sourceByodb']); + assert(array_key_exists($sourceByodb, self::BYODB_DATABASES)); + + return self::BYODB_DATABASES[$sourceByodb]['account']; + } $url = parse_url($this->getSourceKbcUrl()); assert($url && array_key_exists('host', $url)); @@ -106,6 +112,12 @@ public function getSourceDatabaseAccount(): string public function getSourceDatabaseRegion(): string { + if ($this->isSourceByodb()) { + $sourceByodb = $this->getValue(['parameters', 'sourceByodb']); + assert(array_key_exists($sourceByodb, self::BYODB_DATABASES)); + + return self::BYODB_DATABASES[$sourceByodb]['region']; + } $url = parse_url($this->getSourceKbcUrl()); assert($url && array_key_exists('host', $url)); @@ -114,6 +126,12 @@ public function getSourceDatabaseRegion(): string public function getSourceDatabasePrefix(): string { + if ($this->isSourceByodb()) { + $sourceByodb = $this->getValue(['parameters', 'sourceByodb']); + assert(array_key_exists($sourceByodb, self::BYODB_DATABASES)); + + return self::BYODB_DATABASES[$sourceByodb]['db_prefix']; + } $url = parse_url($this->getSourceKbcUrl()); assert($url && array_key_exists('host', $url)); @@ -122,7 +140,12 @@ public function getSourceDatabasePrefix(): string public function getReplicaDatabasePrefix(): string { + if ($this->isSourceByodb()) { + $sourceByodb = $this->getValue(['parameters', 'sourceByodb']); + assert(array_key_exists($sourceByodb, self::BYODB_DATABASES)); + return self::BYODB_DATABASES[$sourceByodb]['db_replica_prefix']; + } $url = parse_url($this->getSourceKbcUrl()); assert($url && array_key_exists('host', $url)); @@ -176,18 +199,15 @@ public function isDryRun(): bool return (bool) $this->getValue(['parameters', 'dryRun']); } - public function getIncludedWorkspaceSchemas(): array - { - return $this->getArrayValue(['parameters', 'includeWorkspaceSchemas']); - } - - public function getIncludedExternalSchemas(): array + public function isSourceByodb(): bool { - return $this->getArrayValue(['parameters', 'includeExternalSchemas']); + return (bool) $this->getValue(['parameters', 'isSourceByodb']); } - public function getByodbSource(): bool + public function getByodbSource(): array { - return (bool) $this->getValue(['parameters', 'sourceByodb']); + $sourceByodb = $this->getValue(['parameters', 'sourceByodb']); + assert(array_key_exists($sourceByodb, self::BYODB_DATABASES)); + return self::BYODB_DATABASES[$sourceByodb]; } } diff --git a/src/Configuration/ConfigDefinition.php b/src/Configuration/ConfigDefinition.php index cfad579..b1f43b6 100644 --- a/src/Configuration/ConfigDefinition.php +++ b/src/Configuration/ConfigDefinition.php @@ -19,6 +19,7 @@ protected function getParametersDefinition(): ArrayNodeDefinition ->enumNode('mode')->values(['sapi', 'database'])->defaultValue('sapi')->end() ->booleanNode('dryRun')->defaultFalse()->end() ->booleanNode('isSourceByodb')->defaultFalse()->end() + ->scalarNode('sourceByodb')->end() ->scalarNode('sourceKbcUrl')->isRequired()->cannotBeEmpty()->end() ->scalarNode('#sourceKbcToken')->isRequired()->cannotBeEmpty()->end() ->arrayNode('tables')->prototype('scalar')->end()->end()