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
7 changes: 7 additions & 0 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,13 @@ abstract public function getSupportForSpatialAttributes(): bool;
*/
abstract public function getSupportForSpatialIndexNull(): bool;

/**
* Adapter supports optional spatial attributes with existing rows.
*
* @return bool
*/
abstract public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool;

/**
* Does the adapter support order attribute in spatial indexes?
*
Expand Down
10 changes: 10 additions & 0 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1917,4 +1917,14 @@ public function getSupportForSpatialAxisOrder(): bool
{
return false;
}

/**
* Adapter supports optional spatial attributes with existing rows.
*
* @return bool
*/
public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool
{
return true;
}
}
15 changes: 15 additions & 0 deletions src/Database/Adapter/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Utopia\Database\Database;
use Utopia\Database\Exception as DatabaseException;
use Utopia\Database\Exception\Dependency as DependencyException;
use Utopia\Database\Exception\Structure as StructureException;
use Utopia\Database\Exception\Timeout as TimeoutException;
use Utopia\Database\Query;

Expand Down Expand Up @@ -155,6 +156,10 @@ protected function processException(PDOException $e): \Exception
return new DependencyException('Attribute cannot be deleted because it is used in an index', $e->getCode(), $e);
}

if ($e->getCode() === '22004' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1138) {
return new StructureException('Attribute does not allow null values', $e->getCode(), $e);
}

return parent::processException($e);
}
/**
Expand Down Expand Up @@ -249,4 +254,14 @@ protected function getSpatialAxisOrderSpec(): string
{
return "'axis-order=long-lat'";
}

/**
* Adapter supports optional spatial attributes with existing rows.
*
* @return bool
*/
public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool
{
return false;
}
}
10 changes: 10 additions & 0 deletions src/Database/Adapter/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,14 @@ public function getSupportForSpatialAxisOrder(): bool
{
return $this->delegate(__FUNCTION__, \func_get_args());
}

/**
* Adapter supports optional spatial attributes with existing rows.
*
* @return bool
*/
public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool
{
return $this->delegate(__FUNCTION__, \func_get_args());
}
}
10 changes: 10 additions & 0 deletions src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -2002,4 +2002,14 @@ public function getSupportForSpatialAxisOrder(): bool
{
return false;
}

/**
* Adapter supports optional spatial attributes with existing rows.
*
* @return bool
*/
public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool
{
return false;
}
}
10 changes: 10 additions & 0 deletions src/Database/Adapter/SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -1284,4 +1284,14 @@ public function getSupportForSpatialAxisOrder(): bool
{
return false;
}

/**
* Adapter supports optionalspatial attributes with existing rows.
*
* @return bool
*/
public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool
{
return true;
}
}
34 changes: 34 additions & 0 deletions tests/e2e/Adapter/Scopes/SpatialTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2747,4 +2747,38 @@ public function testInvalidCoordinateDocuments(): void
$database->deleteCollection($collectionName);
}
}

public function testCreateSpatialColumnWithExistingData(): void
{
/** @var Database $database */
$database = static::getDatabase();
if (!$database->getAdapter()->getSupportForSpatialAttributes()) {
$this->expectNotToPerformAssertions();
return;
}
if ($database->getAdapter()->getSupportForSpatialIndexNull()) {
$this->expectNotToPerformAssertions();
return;
}

if ($database->getAdapter()->getSupportForOptionalSpatialAttributeWithExistingRows()) {
$this->expectNotToPerformAssertions();
return;
}

$col = 'spatial_col_existing_data';
try {
$database->createCollection($col);

$database->createAttribute($col, 'name', Database::VAR_STRING, 40, false);
$database->createDocument($col, new Document(['name' => 'test-doc','$permissions' => [Permission::update(Role::any()), Permission::read(Role::any())]]));
try {
$database->createAttribute($col, 'loc', Database::VAR_POINT, 0, true);
} catch (\Throwable $e) {
$this->assertInstanceOf(StructureException::class, $e);
}
} finally {
$database->deleteCollection($col);
}
}
}