Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-quoted newKey in MariaDB and add newKey filtering for postgres #448

Merged
merged 1 commit into from
Sep 10, 2024
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
38 changes: 19 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function updateAttribute(string $collection, string $id, string $type, in
$type = $this->getSQLType($type, $size, $signed, $array);

if (!empty($newKey)) {
$sql = "ALTER TABLE {$this->getSQLTable($name)} CHANGE COLUMN `{$id}` {$newKey} {$type};";
$sql = "ALTER TABLE {$this->getSQLTable($name)} CHANGE COLUMN `{$id}` `{$newKey}` {$type};";
} else {
$sql = "ALTER TABLE {$this->getSQLTable($name)} MODIFY `{$id}` {$type};";
}
Expand Down
1 change: 1 addition & 0 deletions src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public function updateAttribute(string $collection, string $id, string $type, in
{
$name = $this->filter($collection);
$id = $this->filter($id);
$newKey = empty($newKey) ? null : $this->filter($newKey);
$type = $this->getSQLType($type, $size, $signed, $array);

if ($type == 'TIMESTAMP(3)') {
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -5906,6 +5906,18 @@ public function testUpdateAttributeRename(): void
} catch (\Exception $e) {
$this->assertInstanceOf(StructureException::class, $e);
}

// Check new key filtering
static::getDatabase()->updateAttribute(
collection: 'rename_test',
id: 'renamed',
newKey: 'renamed-test',
);

$doc = static::getDatabase()->getDocument('rename_test', $doc->getId());

$this->assertEquals('string', $doc->getAttribute('renamed-test'));
$this->assertArrayNotHasKey('renamed', $doc->getAttributes());
}

public function createRandomString(int $length = 10): string
Expand Down
Loading