Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function test_initialize_multiple_channels_at_once(): void

// Initialize multiple channels at once
$result = $runner->execute('ecotone:migration:channel:setup', [
'channels' => [self::TEST_CHANNEL_NAME_2, self::TEST_CHANNEL_NAME_3],
'channel' => [self::TEST_CHANNEL_NAME_2, self::TEST_CHANNEL_NAME_3],
'initialize' => true,
]);

Expand Down Expand Up @@ -198,7 +198,7 @@ public function test_delete_multiple_channels_at_once(): void

// Delete multiple channels at once
$result = $runner->execute('ecotone:migration:channel:delete', [
'channels' => [self::TEST_CHANNEL_NAME_2, self::TEST_CHANNEL_NAME_3],
'channel' => [self::TEST_CHANNEL_NAME_2, self::TEST_CHANNEL_NAME_3],
'force' => true,
]);

Expand Down Expand Up @@ -230,7 +230,7 @@ public function test_stream_channel_initialization(): void

// Initialize stream channel
$result = $runner->execute('ecotone:migration:channel:setup', [
'channels' => [self::TEST_STREAM_CHANNEL_NAME],
'channel' => [self::TEST_STREAM_CHANNEL_NAME],
'initialize' => true,
]);

Expand All @@ -248,7 +248,7 @@ public function test_stream_channel_initialization(): void

// Delete stream channel
$result = $runner->execute('ecotone:migration:channel:delete', [
'channels' => [self::TEST_STREAM_CHANNEL_NAME],
'channel' => [self::TEST_STREAM_CHANNEL_NAME],
'force' => true,
]);

Expand Down
34 changes: 26 additions & 8 deletions packages/Dbal/src/Database/DatabaseDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ public function __construct(

#[ConsoleCommand('ecotone:migration:database:delete')]
public function delete(
#[ConsoleParameterOption] array $features = [],
#[ConsoleParameterOption] bool $force = false,
#[ConsoleParameterOption] bool $onlyUsed = true,
#[ConsoleParameterOption] array $feature = [],
#[ConsoleParameterOption] bool|string $force = false,
#[ConsoleParameterOption] bool|string $onlyUsed = true,
): ?ConsoleCommandResultSet {
// Normalize boolean parameters from CLI strings
$force = $this->normalizeBoolean($force);
$onlyUsed = $this->normalizeBoolean($onlyUsed);

// If specific feature names provided
if (\count($features) > 0) {
if (\count($feature) > 0) {
$rows = [];

if (! $force) {
foreach ($features as $featureName) {
if (!$force) {
foreach ($feature as $featureName) {
$rows[] = [$featureName, 'Would be deleted (use --force to confirm)'];
}
return ConsoleCommandResultSet::create(['Feature', 'Warning'], $rows);
}

foreach ($features as $featureName) {
foreach ($feature as $featureName) {
$this->databaseSetupManager->drop($featureName);
$rows[] = [$featureName, 'Deleted'];
}
Expand All @@ -54,7 +58,7 @@ public function delete(
);
}

if (! $force) {
if (!$force) {
return ConsoleCommandResultSet::create(
['Feature', 'Warning'],
array_map(fn (string $feature) => [$feature, 'Would be deleted (use --force to confirm)'], $featureNames)
Expand All @@ -67,4 +71,18 @@ public function delete(
array_map(fn (string $feature) => [$feature, 'Deleted'], $featureNames)
);
}

/**
* Normalize boolean parameter from CLI string to actual boolean.
* Handles cases where CLI passes "false" as a string.
*/
private function normalizeBoolean(bool|string $value): bool
{
if (is_bool($value)) {
return $value;
}

// Handle string values from CLI
return $value !== 'false' && $value !== '0' && $value !== '';
}
}
35 changes: 27 additions & 8 deletions packages/Dbal/src/Database/DatabaseSetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,30 @@ public function __construct(

#[ConsoleCommand('ecotone:migration:database:setup')]
public function setup(
#[ConsoleParameterOption] array $features = [],
#[ConsoleParameterOption] bool $initialize = false,
#[ConsoleParameterOption] bool $sql = false,
#[ConsoleParameterOption] bool $onlyUsed = true,
#[ConsoleParameterOption] array $feature = [],
#[ConsoleParameterOption] bool|string $initialize = false,
#[ConsoleParameterOption] bool|string $sql = false,
#[ConsoleParameterOption] bool|string $onlyUsed = true,
): ?ConsoleCommandResultSet {
// Normalize boolean parameters from CLI strings
$initialize = $this->normalizeBoolean($initialize);
$sql = $this->normalizeBoolean($sql);
$onlyUsed = $this->normalizeBoolean($onlyUsed);

// If specific feature names provided
if (count($features) > 0) {
if (count($feature) > 0) {
$rows = [];

if ($sql) {
$statements = $this->databaseSetupManager->getCreateSqlStatementsForFeatures($features);
$statements = $this->databaseSetupManager->getCreateSqlStatementsForFeatures($feature);
return ConsoleCommandResultSet::create(
['SQL Statement'],
[[implode("\n", $statements)]]
);
}

if ($initialize) {
foreach ($features as $featureName) {
foreach ($feature as $featureName) {
$this->databaseSetupManager->initialize($featureName);
$rows[] = [$featureName, 'Created'];
}
Expand All @@ -49,7 +54,7 @@ public function setup(

$initStatus = $this->databaseSetupManager->getInitializationStatus();
$usageStatus = $this->databaseSetupManager->getUsageStatus();
foreach ($features as $featureName) {
foreach ($feature as $featureName) {
$isInitialized = $initStatus[$featureName] ?? false;
$isUsed = $usageStatus[$featureName] ?? false;
$rows[] = [$featureName, $isUsed ? 'Yes' : 'No', $isInitialized ? 'Yes' : 'No'];
Expand Down Expand Up @@ -97,4 +102,18 @@ public function setup(
$rows
);
}

/**
* Normalize boolean parameter from CLI string to actual boolean.
* Handles cases where CLI passes "false" as a string.
*/
private function normalizeBoolean(bool|string $value): bool
{
if (\is_bool($value)) {
return $value;
}

// Handle string values from CLI
return $value !== 'false' && $value !== '0' && $value !== '';
}
}
51 changes: 45 additions & 6 deletions packages/Dbal/tests/Integration/DatabaseInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function test_database_setup_with_specific_features(): void

// Initialize only specific feature
$result = $this->executeConsoleCommand($ecotone, 'ecotone:migration:database:setup', [
'features' => ['dead_letter'],
'feature' => ['dead_letter'],
'initialize' => true,
]);

Expand All @@ -179,13 +179,13 @@ public function test_database_setup_shows_status_for_specific_features(): void

// First initialize
$this->executeConsoleCommand($ecotone, 'ecotone:migration:database:setup', [
'features' => ['dead_letter'],
'feature' => ['dead_letter'],
'initialize' => true,
]);

// Check status for specific feature
$result = $this->executeConsoleCommand($ecotone, 'ecotone:migration:database:setup', [
'features' => ['dead_letter'],
'feature' => ['dead_letter'],
]);

self::assertEquals(['Feature', 'Used', 'Initialized'], $result->getColumnHeaders());
Expand All @@ -197,7 +197,7 @@ public function test_database_setup_returns_sql_for_specific_features(): void
$ecotone = $this->bootstrapEcotone();

$result = $this->executeConsoleCommand($ecotone, 'ecotone:migration:database:setup', [
'features' => ['dead_letter'],
'feature' => ['dead_letter'],
'sql' => true,
]);

Expand All @@ -218,7 +218,7 @@ public function test_database_delete_with_specific_features(): void

// Delete specific feature
$result = $this->executeConsoleCommand($ecotone, 'ecotone:migration:database:delete', [
'features' => ['dead_letter'],
'feature' => ['dead_letter'],
'force' => true,
]);

Expand All @@ -237,7 +237,7 @@ public function test_database_delete_shows_warning_for_specific_features_without

// Try to delete without force
$result = $this->executeConsoleCommand($ecotone, 'ecotone:migration:database:delete', [
'features' => ['dead_letter'],
'feature' => ['dead_letter'],
]);

self::assertEquals(['Feature', 'Warning'], $result->getColumnHeaders());
Expand Down Expand Up @@ -294,4 +294,43 @@ private function cleanUpTables(): void
$connection->executeStatement('DROP TABLE ' . DbalDeadLetterHandler::DEFAULT_DEAD_LETTER_TABLE);
}
}

public function test_database_setup_respects_string_false_for_initialize(): void
{
$ecotone = $this->bootstrapEcotone();

// Pass "false" as a string for initialize parameter
$result = $this->executeConsoleCommand($ecotone, 'ecotone:migration:database:setup', ['initialize' => 'false']);

// Should show status, not initialize
self::assertEquals(['Feature', 'Used', 'Initialized'], $result->getColumnHeaders());
self::assertFalse($this->tableExists(DbalDeadLetterHandler::DEFAULT_DEAD_LETTER_TABLE));
}

public function test_database_setup_respects_string_false_for_sql(): void
{
$ecotone = $this->bootstrapEcotone();

// Pass "false" as a string for sql parameter
$result = $this->executeConsoleCommand($ecotone, 'ecotone:migration:database:setup', ['sql' => 'false']);

// Should show status, not SQL
self::assertEquals(['Feature', 'Used', 'Initialized'], $result->getColumnHeaders());
}

public function test_database_delete_respects_string_false_for_force(): void
{
$ecotone = $this->bootstrapEcotone();

// First create tables
$this->executeConsoleCommand($ecotone, 'ecotone:migration:database:setup', ['initialize' => true]);
self::assertTrue($this->tableExists(DbalDeadLetterHandler::DEFAULT_DEAD_LETTER_TABLE));

// Pass "false" as a string for force parameter
$result = $this->executeConsoleCommand($ecotone, 'ecotone:migration:database:delete', ['force' => 'false']);

// Should show warning, not delete
self::assertEquals(['Feature', 'Warning'], $result->getColumnHeaders());
self::assertTrue($this->tableExists(DbalDeadLetterHandler::DEFAULT_DEAD_LETTER_TABLE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ public function __construct(

#[ConsoleCommand('ecotone:migration:channel:delete')]
public function delete(
#[ConsoleParameterOption] array $channels = [],
#[ConsoleParameterOption] bool $force = false,
#[ConsoleParameterOption] array $channel = [],
#[ConsoleParameterOption] bool|string $force = false,
): ?ConsoleCommandResultSet {
// Normalize boolean parameters from CLI strings
$force = $this->normalizeBoolean($force);

// If specific channel names provided
if (count($channels) > 0) {
if (\count($channel) > 0) {
$rows = [];

if (! $force) {
foreach ($channels as $channelName) {
if (!$force) {
foreach ($channel as $channelName) {
$rows[] = [$channelName, 'Would be deleted (use --force to confirm)'];
}
return ConsoleCommandResultSet::create(['Channel', 'Warning'], $rows);
}

foreach ($channels as $channelName) {
foreach ($channel as $channelName) {
$this->channelSetupManager->delete($channelName);
$rows[] = [$channelName, 'Deleted'];
}
Expand All @@ -55,7 +58,7 @@ public function delete(
);
}

if (! $force) {
if (!$force) {
return ConsoleCommandResultSet::create(
['Channel', 'Warning'],
array_map(fn (string $channel) => [$channel, 'Would be deleted (use --force to confirm)'], $channelNames)
Expand All @@ -68,4 +71,18 @@ public function delete(
array_map(fn (string $channel) => [$channel, 'Deleted'], $channelNames)
);
}

/**
* Normalize boolean parameter from CLI string to actual boolean.
* Handles cases where CLI passes "false" as a string.
*/
private function normalizeBoolean(bool|string $value): bool
{
if (\is_bool($value)) {
return $value;
}

// Handle string values from CLI
return $value !== 'false' && $value !== '0' && $value !== '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@ public function __construct(

#[ConsoleCommand('ecotone:migration:channel:setup')]
public function setup(
#[ConsoleParameterOption] array $channels = [],
#[ConsoleParameterOption] bool $initialize = false,
#[ConsoleParameterOption] array $channel = [],
#[ConsoleParameterOption] bool|string $initialize = false,
): ?ConsoleCommandResultSet {
// Normalize boolean parameters from CLI strings
$initialize = $this->normalizeBoolean($initialize);

// If specific channel names provided
if (count($channels) > 0) {
if (count($channel) > 0) {
$rows = [];

if ($initialize) {
foreach ($channels as $channelName) {
foreach ($channel as $channelName) {
$this->channelSetupManager->initialize($channelName);
$rows[] = [$channelName, 'Initialized'];
}
return ConsoleCommandResultSet::create(['Channel', 'Status'], $rows);
}

$status = $this->channelSetupManager->getInitializationStatus();
foreach ($channels as $channelName) {
foreach ($channel as $channelName) {
$channelStatus = $status[$channelName] ?? false;
$rows[] = [$channelName, $this->formatStatus($channelStatus)];
}
Expand Down Expand Up @@ -74,6 +77,20 @@ public function setup(
return ConsoleCommandResultSet::create(['Channel', 'Initialized'], $rows);
}

/**
* Normalize boolean parameter from CLI string to actual boolean.
* Handles cases where CLI passes "false" as a string.
*/
private function normalizeBoolean(bool|string $value): bool
{
if (\is_bool($value)) {
return $value;
}

// Handle string values from CLI
return $value !== 'false' && $value !== '0' && $value !== '';
}

/**
* Format the initialization status for display
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function delete(string $channelName): void

/**
* Returns initialization status for each channel
* @return array<string, bool|string> Map of channel name to initialization status (bool for managed, 'Not managed by migration' for non-managed)
* @return array<string, bool|string> Map of channel name to initialization status (bool for managed, 'Not managed by channel migration' for non-managed)
*/
public function getInitializationStatus(): array
{
Expand All @@ -119,7 +119,7 @@ public function getInitializationStatus(): array

foreach ($this->allPollableChannelNames as $channelName) {
if (! isset($status[$channelName])) {
$status[$channelName] = 'Not managed by migration';
$status[$channelName] = 'Not managed by channel migration';
}
}

Expand Down
Loading