Skip to content

Commit 0cb4c09

Browse files
committed
Fix postgres
1 parent cf1abba commit 0cb4c09

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

src/Database/Adapter/Postgres.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Utopia\Database\Document;
1111
use Utopia\Database\Exception as DatabaseException;
1212
use Utopia\Database\Exception\Duplicate as DuplicateException;
13+
use Utopia\Database\Exception\NotFound as NotFoundException;
1314
use Utopia\Database\Exception\Order as OrderException;
1415
use Utopia\Database\Exception\Timeout as TimeoutException;
1516
use Utopia\Database\Exception\Transaction as TransactionException;
@@ -1926,17 +1927,6 @@ protected function getSQLSchema(): string
19261927
return "\"{$this->getDatabase()}\".";
19271928
}
19281929

1929-
/**
1930-
* Get SQL table
1931-
*
1932-
* @param string $name
1933-
* @return string
1934-
*/
1935-
protected function getSQLTable(string $name): string
1936-
{
1937-
return "\"{$this->getDatabase()}\".\"{$this->getNamespace()}_{$name}\"";
1938-
}
1939-
19401930
/**
19411931
* Get PDO Type
19421932
*
@@ -2078,6 +2068,11 @@ protected function processException(PDOException $e): \Exception
20782068
return new TruncateException('Resize would result in data truncation', $e->getCode(), $e);
20792069
}
20802070

2071+
// Unknown column
2072+
if ($e->getCode() === "42703" && isset($e->errorInfo[1]) && $e->errorInfo[1] === 7) {
2073+
return new NotFoundException('Attribute not found', $e->getCode(), $e);
2074+
}
2075+
20812076
return $e;
20822077
}
20832078

src/Database/Adapter/SQL.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ public function createAttributes(string $collection, array $attributes): bool
257257
$sql = "ALTER TABLE {$this->getSQLTable($collection)} ADD COLUMN {$columns};";
258258
$sql = $this->trigger(Database::EVENT_ATTRIBUTE_CREATE, $sql);
259259

260-
\var_dump($sql);
261-
262260
try {
263261
return $this->getPDO()
264262
->prepare($sql)
@@ -309,11 +307,8 @@ public function renameAttribute(string $collection, string $old, string $new): b
309307
*/
310308
public function deleteAttribute(string $collection, string $id, bool $array = false): bool
311309
{
312-
$name = $this->filter($collection);
313310
$id = $this->quote($this->filter($id));
314-
315-
$sql = "ALTER TABLE {$this->getSQLTable($name)} DROP COLUMN {$id};";
316-
311+
$sql = "ALTER TABLE {$this->getSQLTable($collection)} DROP COLUMN {$id};";
317312
$sql = $this->trigger(Database::EVENT_ATTRIBUTE_DELETE, $sql);
318313

319314
try {

0 commit comments

Comments
 (0)