Skip to content

Commit

Permalink
Merge pull request #65 from keboola/miro-PS-3910
Browse files Browse the repository at this point in the history
PS-3910: refactor: dbtCompile action
  • Loading branch information
MiroCillik authored Oct 19, 2022
2 parents dc3f522 + a7e5fd6 commit 523df50
Show file tree
Hide file tree
Showing 28 changed files with 555 additions and 330 deletions.
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ parameters:
ignoreErrors:
- '#Cannot call method end\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null.#'
- '#Cannot call method integerNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null.#'
- '#Cannot call method scalarNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null.#'
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\).#'
28 changes: 18 additions & 10 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace DbtTransformation;

use DbtTransformation\ConfigDefinition\ConfigDefinition;
use DbtTransformation\ConfigDefinition\SyncAction\DbtCompileDefinition;
use DbtTransformation\ConfigDefinition\SyncAction\DbtDocsDefinition;
use DbtTransformation\ConfigDefinition\SyncAction\DbtRunResultsDefinition;
use DbtTransformation\ConfigDefinition\SyncAction\GitRepositoryDefinition;
use DbtTransformation\Configuration\ConfigDefinition;
use DbtTransformation\Configuration\SyncAction\DbtCompileDefinition;
use DbtTransformation\Configuration\SyncAction\DbtDocsDefinition;
use DbtTransformation\Configuration\SyncAction\DbtRunResultsDefinition;
use DbtTransformation\Configuration\SyncAction\GitRepositoryDefinition;
use DbtTransformation\DwhProvider\DwhProviderFactory;
use DbtTransformation\Helper\DbtCompileHelper;
use DbtTransformation\Helper\DbtDocsHelper;
use DbtTransformation\Helper\ParseDbtOutputHelper;
use DbtTransformation\Helper\ParseLogFileHelper;
Expand Down Expand Up @@ -226,22 +227,29 @@ protected function actionDbtRunResults(): array

/**
* @return array<string, array<int|string, string|false>>
* @throws \Keboola\Component\UserException
*/
protected function actionDbtCompile(): array
{
$componentId = getenv('KBC_COMPONENTID') ?: self::COMPONENT_ID;
$configId = $this->getConfig()->getConfigId();
$branchId = $this->getConfig()->getBranchId();
$config = $this->getConfig();
$this->cloneRepository($config);
$provider = $this->dwhProviderFactory->getProvider($config, $this->projectPath);
$provider->createDbtYamlFiles();

$this->artifacts->downloadLastRun($componentId, $configId, $branchId);
$dbtService = new DbtService($this->projectPath, $this->getConfig()->getModelNames());
if (file_exists($this->projectPath . '/packages.yml')) {
$dbtService->runCommand(DbtService::COMMAND_DEPS);
}
$dbtService->runCommand(DbtService::COMMAND_COMPILE);

return [
'compiled' => $this->artifacts->getCompiledSqlFiles(),
'compiled' => DbtCompileHelper::getCompiledSqlFiles($this->projectPath),
];
}

/**
* @return array<string, array<string, array<int, string>|string>>
* @throws \Keboola\Component\UserException
*/
protected function actionGitRepository(): array
{
Expand Down
227 changes: 0 additions & 227 deletions src/ConfigDefinition/ConfigDefinition.php

This file was deleted.

38 changes: 38 additions & 0 deletions src/Configuration/ConfigDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace DbtTransformation\Configuration;

use DbtTransformation\Configuration\NodeDefinition\DbtNode;
use DbtTransformation\Configuration\NodeDefinition\GitNode;
use DbtTransformation\Configuration\NodeDefinition\RemoteDwhNode;
use Keboola\Component\Config\BaseConfigDefinition;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

class ConfigDefinition extends BaseConfigDefinition
{
protected function getParametersDefinition(): ArrayNodeDefinition
{
$parametersNode = parent::getParametersDefinition();
// @formatter:off
/** @noinspection NullPointerExceptionInspection */
$parametersNode
->isRequired()
->children()
->append(new GitNode())
->append(new RemoteDwhNode())
->append(new DbtNode())
->end();

/** @noinspection NullPointerExceptionInspection */
$parametersNode
->children()
->booleanNode('showExecutedSqls')
->defaultFalse()
->end();

// @formatter:on
return $parametersNode;
}
}
Loading

0 comments on commit 523df50

Please sign in to comment.