Skip to content

Commit

Permalink
💡 Improved declarativeness.
Browse files Browse the repository at this point in the history
- Added comment in prepareSqlForOneTable().
- Renamed createVersion() to createVersionAndTriggers() for clarity.
  • Loading branch information
netbrothers-tr committed May 24, 2023
1 parent 263d16a commit e174fa7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
11 changes: 7 additions & 4 deletions src/Command/MakeVersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,15 @@ private function prepareSqlForOneTable(string $tableName, InputInterface $input)
}
}
if (in_array($tableName, $this->jobs['CreateVersion'])) {
foreach ($this->generateService->createVersion($tableName) as $query) {
foreach ($this->generateService->createVersionAndTriggers($tableName) as $query) {
$sql[] = $query;
}
return $sql;
}
if (in_array($tableName, $this->jobs['CreateTrigger'])) {
/**
* The `CreateVersion` job will create the version table and also
* the triggers. That's why the the `CreateTrigger` job is never
* available, if a `CreateVersion` job is set: hence, the `else if`.
*/
} else if (in_array($tableName, $this->jobs['CreateTrigger'])) {
foreach ($this->generateService->createTriggers($tableName) as $query) {
$sql[] = $query;
}
Expand Down
20 changes: 11 additions & 9 deletions src/Services/GenerateService.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php

/**
* NetBrothers VersionBundle
*
* @author Stefan Wessel, NetBrothers GmbH
* @date 22.03.21
*
*/

namespace NetBrothers\VersionBundle\Services;


use Doctrine\DBAL\Schema\AbstractSchemaManager;
use NetBrothers\VersionBundle\Services\Sql\CreateTrigger;
use NetBrothers\VersionBundle\Services\Sql\Definitions;
Expand All @@ -22,7 +20,6 @@
*/
class GenerateService
{

/** @var AbstractSchemaManager */
private $schemaManager;

Expand All @@ -34,8 +31,10 @@ class GenerateService
* @param AbstractSchemaManager $schemaManager
* @param string $databaseName
*/
public function __construct(AbstractSchemaManager $schemaManager, string $databaseName)
{
public function __construct(
AbstractSchemaManager $schemaManager,
string $databaseName
) {
$this->schemaManager = $schemaManager;
$this->databaseName = $databaseName;
}
Expand All @@ -55,7 +54,10 @@ public function dropVersionTableAndTriggersInOriginTable(string $tableName): arr
$sql = $this->dropTriggers($tableName);
// dropping version
$versionService = new VersionTable();
$sql[] = $versionService->dropVersionTable($this->databaseName, $tableName);
$sql[] = $versionService->dropVersionTable(
$this->databaseName,
$tableName
);
}
return $sql;
}
Expand All @@ -78,7 +80,7 @@ public function dropTriggers(string $tableName): array
* @param string $tableName name of origin table
* @return array
*/
public function createVersion(string $tableName): array
public function createVersionAndTriggers(string $tableName): array
{
$sql = [];
if ($this->schemaManager->tablesExist([$tableName])) {
Expand Down Expand Up @@ -109,4 +111,4 @@ public function createTriggers(string $tableName): array
}
return $sql;
}
}
}

0 comments on commit e174fa7

Please sign in to comment.