Skip to content

Commit ef4429e

Browse files
renamed getIndexKey to getShortKey
1 parent 68d47bf commit ef4429e

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

src/Database/Adapter/Postgres.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,20 @@ public function createCollection(string $name, array $attributes = [], array $in
245245
";
246246

247247
if ($this->sharedTables) {
248-
$uidIndex = $this->getIndexKey("{$namespace}_{$this->tenant}_{$id}_uid");
249-
$createdIndex = $this->getIndexKey("{$namespace}_{$this->tenant}_{$id}_created");
250-
$updatedIndex = $this->getIndexKey("{$namespace}_{$this->tenant}_{$id}_updated");
251-
$tenantIdIndex = $this->getIndexKey("{$namespace}_{$this->tenant}_{$id}_tenant_id");
248+
$uidIndex = $this->getShortKey("{$namespace}_{$this->tenant}_{$id}_uid");
249+
$createdIndex = $this->getShortKey("{$namespace}_{$this->tenant}_{$id}_created");
250+
$updatedIndex = $this->getShortKey("{$namespace}_{$this->tenant}_{$id}_updated");
251+
$tenantIdIndex = $this->getShortKey("{$namespace}_{$this->tenant}_{$id}_tenant_id");
252252
$collection .= "
253253
CREATE UNIQUE INDEX \"{$uidIndex}\" ON {$this->getSQLTable($id)} (\"_uid\" COLLATE utf8_ci_ai, \"_tenant\");
254254
CREATE INDEX \"{$createdIndex}\" ON {$this->getSQLTable($id)} (_tenant, \"_createdAt\");
255255
CREATE INDEX \"{$updatedIndex}\" ON {$this->getSQLTable($id)} (_tenant, \"_updatedAt\");
256256
CREATE INDEX \"{$tenantIdIndex}\" ON {$this->getSQLTable($id)} (_tenant, _id);
257257
";
258258
} else {
259-
$uidIndex = $this->getIndexKey("{$namespace}_{$id}_uid");
260-
$createdIndex = $this->getIndexKey("{$namespace}_{$id}_created");
261-
$updatedIndex = $this->getIndexKey("{$namespace}_{$id}_updated");
259+
$uidIndex = $this->getShortKey("{$namespace}_{$id}_uid");
260+
$createdIndex = $this->getShortKey("{$namespace}_{$id}_created");
261+
$updatedIndex = $this->getShortKey("{$namespace}_{$id}_updated");
262262
$collection .= "
263263
CREATE UNIQUE INDEX \"{$uidIndex}\" ON {$this->getSQLTable($id)} (\"_uid\" COLLATE utf8_ci_ai);
264264
CREATE INDEX \"{$createdIndex}\" ON {$this->getSQLTable($id)} (\"_createdAt\");
@@ -279,17 +279,17 @@ public function createCollection(string $name, array $attributes = [], array $in
279279
";
280280

281281
if ($this->sharedTables) {
282-
$uniquePermissionIndex = $this->getIndexKey("{$namespace}_{$this->tenant}_{$id}_ukey");
283-
$permissionIndex = $this->getIndexKey("{$namespace}_{$this->tenant}_{$id}_permission");
282+
$uniquePermissionIndex = $this->getShortKey("{$namespace}_{$this->tenant}_{$id}_ukey");
283+
$permissionIndex = $this->getShortKey("{$namespace}_{$this->tenant}_{$id}_permission");
284284
$permissions .= "
285285
CREATE UNIQUE INDEX \"{$uniquePermissionIndex}\"
286286
ON {$this->getSQLTable($id . '_perms')} USING btree (_tenant,_document,_type,_permission);
287287
CREATE INDEX \"{$permissionIndex}\"
288288
ON {$this->getSQLTable($id . '_perms')} USING btree (_tenant,_permission,_type);
289289
";
290290
} else {
291-
$uniquePermissionIndex = $this->getIndexKey("{$namespace}_{$id}_ukey");
292-
$permissionIndex = $this->getIndexKey("{$namespace}_{$id}_permission");
291+
$uniquePermissionIndex = $this->getShortKey("{$namespace}_{$id}_ukey");
292+
$permissionIndex = $this->getShortKey("{$namespace}_{$id}_permission");
293293
$permissions .= "
294294
CREATE UNIQUE INDEX \"{$uniquePermissionIndex}\"
295295
ON {$this->getSQLTable($id . '_perms')} USING btree (_document COLLATE utf8_ci_ai,_type,_permission);
@@ -905,7 +905,7 @@ public function createIndex(string $collection, string $id, string $type, array
905905
default => throw new DatabaseException('Unknown index type: ' . $type . '. Must be one of ' . Database::INDEX_KEY . ', ' . Database::INDEX_UNIQUE . ', ' . Database::INDEX_FULLTEXT . ', ' . Database::INDEX_SPATIAL . ', ' . Database::INDEX_OBJECT . ', ' . Database::INDEX_HNSW_EUCLIDEAN . ', ' . Database::INDEX_HNSW_COSINE . ', ' . Database::INDEX_HNSW_DOT),
906906
};
907907

908-
$keyName = $this->getIndexKey("{$this->getNamespace()}_{$this->tenant}_{$collection}_{$id}");
908+
$keyName = $this->getShortKey("{$this->getNamespace()}_{$this->tenant}_{$collection}_{$id}");
909909
$attributes = \implode(', ', $attributes);
910910

911911
if ($this->sharedTables && \in_array($type, [Database::INDEX_KEY, Database::INDEX_UNIQUE])) {
@@ -948,7 +948,7 @@ public function deleteIndex(string $collection, string $id): bool
948948
$id = $this->filter($id);
949949
$schemaName = $this->getDatabase();
950950

951-
$keyName = $this->getIndexKey("{$this->getNamespace()}_{$this->tenant}_{$collection}_{$id}");
951+
$keyName = $this->getShortKey("{$this->getNamespace()}_{$this->tenant}_{$collection}_{$id}");
952952

953953
$sql = "DROP INDEX IF EXISTS \"{$schemaName}\".\"{$keyName}\"";
954954
$sql = $this->trigger(Database::EVENT_INDEX_DELETE, $sql);
@@ -974,8 +974,8 @@ public function renameIndex(string $collection, string $old, string $new): bool
974974
$old = $this->filter($old);
975975
$new = $this->filter($new);
976976
$schema = $this->getDatabase();
977-
$oldIndexName = $this->getIndexKey("{$namespace}_{$this->tenant}_{$collection}_{$old}");
978-
$newIndexName = $this->getIndexKey("{$namespace}_{$this->tenant}_{$collection}_{$new}");
977+
$oldIndexName = $this->getShortKey("{$namespace}_{$this->tenant}_{$collection}_{$old}");
978+
$newIndexName = $this->getShortKey("{$namespace}_{$this->tenant}_{$collection}_{$new}");
979979

980980
$sql = "ALTER INDEX \"{$schema}\".\"{$oldIndexName}\" RENAME TO \"{$newIndexName}\"";
981981
$sql = $this->trigger(Database::EVENT_INDEX_RENAME, $sql);
@@ -2758,7 +2758,7 @@ protected function bindOperatorParams(\PDOStatement|PDOStatementProxy $stmt, Ope
27582758
* @param string $key
27592759
* @return string
27602760
*/
2761-
protected function getIndexKey(string $key): string
2761+
protected function getShortKey(string $key): string
27622762
{
27632763
if (\strlen($key) <= self::MAX_IDENTIFIER_NAME) {
27642764
return $key;
@@ -2785,7 +2785,7 @@ protected function getIndexKey(string $key): string
27852785
protected function getSQLTable(string $name): string
27862786
{
27872787
$table = "{$this->getNamespace()}_{$this->filter($name)}";
2788-
$table = $this->getIndexKey($table);
2788+
$table = $this->getShortKey($table);
27892789

27902790
return "{$this->quote($this->getDatabase())}.{$this->quote($table)}";
27912791
}

0 commit comments

Comments
 (0)