Skip to content

Commit d692ca7

Browse files
committed
replaceAttribute setPermissions
1 parent 83aa680 commit d692ca7

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎src/Database/Trait/Attributes.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ public function updateAttribute(string $collection, string $key, Update $update)
234234
$this->writeAttributes($definition, $attributes);
235235
if ($renaming) {
236236
$this->writeIndexes($definition, $indexes);
237+
238+
// A grant names its column by key, so it follows the rename as the indexes above
239+
// do. Left alone it would name a key nothing has: it would reach nothing, and the
240+
// collection would hold a grant createCollection() refuses.
241+
$definition->setPermissions(Permission::renameColumn($definition->declaredPermissions() ?? [], $key, $newKey));
237242
}
238243

239244
if (

‎src/Database/Trait/Relationships.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,14 @@ private function replaceAttribute(string $collection, string $key, Attribute $at
788788
}
789789

790790
$definition->setAttribute(self::COLLECTION_ATTRIBUTES, \array_map(static fn (Attribute $stored): Document => $stored->toDocument(), $attributes));
791+
792+
// The one place a relationship's key changes on either side, so the one place a grant
793+
// naming it has to follow. Left alone it would name a key nothing has -- unreachable,
794+
// and a grant createCollection() refuses. deleteRelationship() drops them the same way
795+
// when the key goes entirely.
796+
if ($attribute->key !== $key) {
797+
$definition->setPermissions(Permission::renameColumn($definition->declaredPermissions() ?? [], $key, $attribute->key));
798+
}
791799
$this->updateMetadata(
792800
collection: $definition,
793801
rollbackOperation: null,

0 commit comments

Comments
 (0)