Skip to content

Commit

Permalink
Merge pull request #16 from keboola/ondra-create-tables-dry-run
Browse files Browse the repository at this point in the history
dry-run - create bucket/table
  • Loading branch information
ondrajodas authored Sep 6, 2024
2 parents f288d66 + bea946e commit 574bb6f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
20 changes: 13 additions & 7 deletions src/Strategy/DatabaseMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ public function migrate(Config $config): void
}

if (!$this->targetSapiClient->bucketExists($schemaName)) {
$this->logger->info(sprintf('Creating bucket "%s".', $schemaName));
$this->storageModifier->createBucket($schemaName);
if ($this->dryRun) {
$this->logger->info(sprintf('[dry-run] Creating bucket "%s".', $schemaName));
} else {
// Create bucket
$this->logger->info(sprintf('Creating bucket "%s".', $schemaName));
$this->storageModifier->createBucket($schemaName);
}
}

$this->migrateSchema($config->getMigrateTables(), $schemaName);
Expand All @@ -116,6 +121,12 @@ private function migrateSchema(array $tablesWhiteList, string $schemaName): void
if ($tablesWhiteList && !in_array($tableId, $tablesWhiteList, true)) {
continue;
}

if ($this->dryRun) {
$this->logger->info(sprintf('[dry-run] Migrating table %s.%s', $schemaName, $table['name']));
continue;
}

if (!$this->targetSapiClient->tableExists($tableId)) {
$this->logger->info(sprintf('Creating table "%s".', $tableId));
$this->storageModifier->createTable(
Expand All @@ -136,11 +147,6 @@ private function migrateSchema(array $tablesWhiteList, string $schemaName): void

private function migrateTable(string $schemaName, string $tableName): void
{
if ($this->dryRun) {
$this->logger->info(sprintf('[dry-run] Migrating table %s.%s', $schemaName, $tableName));
return;
}

$this->logger->info(sprintf('Migrating table %s.%s', $schemaName, $tableName));
$tableRole = $this->getSourceRole(
$this->targetConnection,
Expand Down
21 changes: 14 additions & 7 deletions src/Strategy/SapiMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,23 @@ public function migrate(Config $config): void

if (!in_array($tableInfo['bucket']['id'], $this->bucketsExist) &&
!$this->targetClient->bucketExists($tableInfo['bucket']['id'])) {
$this->logger->info(sprintf('Creating bucket %s', $tableInfo['bucket']['id']));
$this->bucketsExist[] = $tableInfo['bucket']['id'];

$this->storageModifier->createBucket($tableInfo['bucket']['id']);
if ($this->dryRun) {
$this->logger->info(sprintf('[dry-run] Creating bucket %s', $tableInfo['bucket']['id']));
} else {
$this->logger->info(sprintf('Creating bucket %s', $tableInfo['bucket']['id']));
$this->bucketsExist[] = $tableInfo['bucket']['id'];

$this->storageModifier->createBucket($tableInfo['bucket']['id']);
}
}

if (!$this->targetClient->tableExists($tableId)) {
$this->logger->info(sprintf('Creating table %s', $tableInfo['id']));

$this->storageModifier->createTable($tableInfo);
if ($this->dryRun) {
$this->logger->info(sprintf('[dry-run] Creating table %s', $tableInfo['id']));
} else {
$this->logger->info(sprintf('Creating table %s', $tableInfo['id']));
$this->storageModifier->createTable($tableInfo);
}
}

$this->migrateTable($tableInfo);
Expand Down

0 comments on commit 574bb6f

Please sign in to comment.