Skip to content

Commit

Permalink
don't change length if not has been changed
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajodas committed Dec 2, 2024
1 parent 40f3dca commit 4ae8c43
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Storage/TableStructureModifierFromSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,19 @@ private function modifyColumnsAttributes(
array $columns,
): void {
foreach ($columns as $column) {
$params = [
'nullable' => $column->isNullable(),
// Default value is not works correctly
// 'default' => $column->getDataType()?->getDefaultValue($backend),
];
if ($column->getDataType() !== null && $column->getDataType()->getLength($backend) !== null) {
$params['length'] = $column->getDataType()->getLength($backend);
}
try {
$this->client->updateTableColumnDefinition(
$tableId,
$column->getName(),
[
'length' => $column->getDataType()?->getLength($backend),
// Default value is not works correctly
// 'default' => $column->getDataType()?->getDefaultValue($backend),
'nullable' => $column->isNullable(),
],
$params,
);
} catch (ClientException $e) {
throw new InvalidOutputException($e->getMessage(), $e->getCode(), $e);
Expand Down
41 changes: 41 additions & 0 deletions tests/Storage/TableStructureModifierFromSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,47 @@ public function setup(): void
$this->tableStructureModifier = new TableStructureModifierFromSchema($this->clientWrapper, $this->testLogger);
}

#[NeedsEmptyOutputBucket]
public function testNotChangeLength(): void
{
$this->prepareStorageData();

$tableChangesStore = new TableChangesStore();
$tableChangesStore->addColumnAttributeChanges(new MappingFromConfigurationSchemaColumn([
'name' => 'Name',
'data_type' => [
'base' => [
'type' => BaseType::STRING,
],
],
'nullable' => false,
]));

$this->tableStructureModifier->updateTableStructure(
new BucketInfo($this->bucket),
new TableInfo($this->table),
$tableChangesStore,
);

$updatedTable = $this->clientWrapper->getTableAndFileStorageClient()->getTable($this->table['id']);

self::assertTrue($updatedTable['isTyped']);

self::assertEquals(
[
'name' => 'Name',
'definition' => [
'type' => 'VARCHAR',
'nullable' => false,
'length' => '17',
],
'basetype' => 'STRING',
'canBeFiltered' => true,
],
$updatedTable['definition']['columns'][1],
);
}

#[NeedsEmptyOutputBucket]
public function testEmptyChanges(): void
{
Expand Down

0 comments on commit 4ae8c43

Please sign in to comment.