Skip to content

Commit

Permalink
Merge pull request #56 from keboola/PST-2392-ondra
Browse files Browse the repository at this point in the history
restore triggers/notifications based on config
  • Loading branch information
ondrajodas authored Jan 23, 2025
2 parents 0291aa1 + f2c45f7 commit c1014e6
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public function shouldMigratePermanentFiles(): bool
return $this->getValue(['parameters', 'migratePermanentFiles']);
}

public function shouldMigrateTriggers(): bool
{
return $this->getValue(['parameters', 'migrateTriggers']);
}

public function shouldMigrateNotifications(): bool
{
return $this->getValue(['parameters', 'migrateNotifications']);
}

public function shouldMigrateStructureOnly(): bool
{
return $this->getValue(['parameters', 'migrateStructureOnly']);
Expand Down
2 changes: 2 additions & 0 deletions src/ConfigDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ protected function getParametersDefinition(): ArrayNodeDefinition
->booleanNode('dryRun')->defaultFalse()->end()
->booleanNode('directDataMigration')->defaultTrue()->end()
->booleanNode('migratePermanentFiles')->defaultTrue()->end()
->booleanNode('migrateTriggers')->defaultTrue()->end()
->booleanNode('migrateNotifications')->defaultTrue()->end()
->booleanNode('migrateStructureOnly')->defaultFalse()->end()
->booleanNode('migrateSecrets')->defaultFalse()->end()
->enumNode('dataMode')->values(['sapi', 'database'])->defaultValue('sapi')->end()
Expand Down
12 changes: 12 additions & 0 deletions src/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class Migrate

private bool $migratePermanentFiles;

private bool $migrateTriggers;

private bool $migrateNotifications;

private bool $migrateStructureOnly;

public const OBSOLETE_COMPONENTS = [
Expand Down Expand Up @@ -92,6 +96,8 @@ public function __construct(
$this->directDataMigration = $config->directDataMigration();
$this->migrateSecrets = $config->shouldMigrateSecrets();
$this->migratePermanentFiles = $config->shouldMigratePermanentFiles();
$this->migrateTriggers = $config->shouldMigrateTriggers();
$this->migrateNotifications = $config->shouldMigrateNotifications();
$this->migrateStructureOnly = $config->shouldMigrateStructureOnly();
$this->logger = $logger;
$this->migrateDataMode = $config->getMigrateDataMode();
Expand Down Expand Up @@ -348,6 +354,8 @@ private function getRestoreConfigData(array $restoreCredentials): array
'useDefaultBackend' => true,
'restoreConfigs' => $this->migrateSecrets === false,
'restorePermanentFiles' => $this->migratePermanentFiles,
'restoreTriggers' => $this->migrateTriggers,
'restoreNotifications' => $this->migrateNotifications,
],
];
} elseif (isset($restoreCredentials['credentials']['connectionString'])) {
Expand All @@ -360,6 +368,8 @@ private function getRestoreConfigData(array $restoreCredentials): array
'useDefaultBackend' => true,
'restoreConfigs' => $this->migrateSecrets === false,
'restorePermanentFiles' => $this->migratePermanentFiles,
'restoreTriggers' => $this->migrateTriggers,
'restoreNotifications' => $this->migrateNotifications,
],
];
} elseif (isset($restoreCredentials['credentials']['accessToken'])) {
Expand All @@ -378,6 +388,8 @@ private function getRestoreConfigData(array $restoreCredentials): array
'useDefaultBackend' => true,
'restoreConfigs' => $this->migrateSecrets === false,
'restorePermanentFiles' => $this->migratePermanentFiles,
'restoreTriggers' => $this->migrateTriggers,
'restoreNotifications' => $this->migrateNotifications,
],
];
} else {
Expand Down
48 changes: 48 additions & 0 deletions tests/phpunit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,52 @@ public function testMigrateSecretsConfigValid(): void
$this->assertSame(true, $baseConfig->shouldMigrateSecrets());
$this->assertEquals('manage-token', $baseConfig->getSourceManageToken());
}

public function testDisabledMigrateNotifications(): void
{
$config = new Config(
[
'parameters' => [
'sourceKbcUrl' => 'https://connection.keboola.com',
'#sourceKbcToken' => 'token',
'migrateNotifications' => false,
],
],
new ConfigDefinition()
);

$this->assertFalse($config->shouldMigrateNotifications());
}

public function testDisabledMigrateTriggers(): void
{
$config = new Config(
[
'parameters' => [
'sourceKbcUrl' => 'https://connection.keboola.com',
'#sourceKbcToken' => 'token',
'migrateTriggers' => false,
],
],
new ConfigDefinition()
);

$this->assertFalse($config->shouldMigrateTriggers());
}

public function testDisabledMigratePermanentFiles(): void
{
$config = new Config(
[
'parameters' => [
'sourceKbcUrl' => 'https://connection.keboola.com',
'#sourceKbcToken' => 'token',
'migratePermanentFiles' => false,
],
],
new ConfigDefinition()
);

$this->assertFalse($config->shouldMigratePermanentFiles());
}
}
64 changes: 63 additions & 1 deletion tests/phpunit/MigrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function testMigrateSuccess(
int $expectsRunJobs,
bool $restoreConfigs,
bool $migrateStructureOnly,
bool $restorePermanentFiles
bool $restorePermanentFiles,
bool $restoreTriggers,
bool $restoreNotifications
): void {
$sourceJobRunnerMock = $this->createMock($jobRunnerClass);
$destJobRunnerMock = $this->createMock($jobRunnerClass);
Expand Down Expand Up @@ -76,6 +78,8 @@ public function testMigrateSuccess(
'restoreConfigs' => $restoreConfigs,
'dryRun' => false,
'restorePermanentFiles' => $restorePermanentFiles,
'restoreTriggers' => $restoreTriggers,
'restoreNotifications' => $restoreNotifications,
]
),
],
Expand Down Expand Up @@ -138,6 +142,8 @@ public function testMigrateSuccess(
'#sourceManageToken' => 'manage-token',
'migrateStructureOnly' => $migrateStructureOnly,
'migratePermanentFiles' => $restorePermanentFiles,
'migrateTriggers' => $restoreTriggers,
'migrateNotifications' => $restoreNotifications,
],
],
new ConfigDefinition()
Expand Down Expand Up @@ -1221,6 +1227,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-ABS-syrup' => [
Expand All @@ -1236,6 +1244,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-GCS-syrup' => [
Expand All @@ -1257,6 +1267,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-S3-queuev2' => [
Expand All @@ -1274,6 +1286,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-ABS-queuev2' => [
Expand All @@ -1289,6 +1303,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-GCS-queuev2' => [
Expand All @@ -1310,6 +1326,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrateABS-queuev2-data-directly' => [
Expand All @@ -1325,6 +1343,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-ABS-queuev2-structure-only' => [
Expand All @@ -1340,6 +1360,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => true,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-GCS-queuev2-structure-only' => [
Expand All @@ -1361,6 +1383,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => true,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-secrets-false' => [
Expand All @@ -1376,6 +1400,8 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-permanentFiles-false' => [
Expand All @@ -1391,6 +1417,42 @@ public function successMigrateDataProvider(): Generator
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => false,
'restoreTriggers' => true,
'restoreNotifications' => true,
];

yield 'migrate-triggers-false' => [
'expectedCredentialsData' => [
'abs' => [
'container' => 'abcdefgh',
'#connectionString' => 'https://testConnectionString',
],
],
'jobRunnerClass' => QueueV2JobRunner::class,
'migrateDataOfTablesDirectly' => true,
'expectsRunJobs' => 3,
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => false,
'restoreNotifications' => true,
];

yield 'migrate-notifications-false' => [
'expectedCredentialsData' => [
'abs' => [
'container' => 'abcdefgh',
'#connectionString' => 'https://testConnectionString',
],
],
'jobRunnerClass' => QueueV2JobRunner::class,
'migrateDataOfTablesDirectly' => true,
'expectsRunJobs' => 3,
'restoreConfigs' => true,
'migrateStructureOnly' => false,
'restorePermanentFiles' => true,
'restoreTriggers' => true,
'restoreNotifications' => false,
];
}
}

0 comments on commit c1014e6

Please sign in to comment.