Skip to content

Commit

Permalink
Merge pull request #448 from utopia-php/fix-add-escapes-for-rename
Browse files Browse the repository at this point in the history
Fix non-quoted newKey in MariaDB and add newKey filtering for postgres
# Conflicts:
#	composer.lock
  • Loading branch information
abnegate committed Sep 10, 2024
1 parent 24b29bc commit 36a0e89
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
56 changes: 49 additions & 7 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 @@ -322,7 +322,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 @@ -351,6 +351,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 @@ -5899,6 +5899,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

0 comments on commit 36a0e89

Please sign in to comment.