From 2174f288d1684d52b7b8e08b7291f34002896db8 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 25 Mar 2021 22:20:28 +0000 Subject: [PATCH] [DB] Fix Doctrine errors due to lack of column uniqueness So, Doctrine doesn't like that `GSActorTag.tag` is not unique, even though composite key `[tagger, tag]` is. `tag` can't unique, but doctrine doesn't understand this. This seems like a Doctrine bug that should be investigated. For now we'll just not mark it as a foreign key --- src/Entity/GSActor.php | 5 ++++- src/Entity/GSActorCircle.php | 5 +++-- src/Entity/GSActorTagFollow.php | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Entity/GSActor.php b/src/Entity/GSActor.php index af4005e73f..8107888d2e 100644 --- a/src/Entity/GSActor.php +++ b/src/Entity/GSActor.php @@ -296,7 +296,10 @@ class GSActor extends Entity 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], 'primary key' => ['id'], - 'indexes' => [ + 'unique keys' => [ + 'gsactor_nickname_uniq' => ['nickname'], + ], + 'indexes' => [ 'gsactor_nickname_idx' => ['nickname'], ], 'fulltext indexes' => [ diff --git a/src/Entity/GSActorCircle.php b/src/Entity/GSActorCircle.php index e4444e452c..a16c272b3e 100644 --- a/src/Entity/GSActorCircle.php +++ b/src/Entity/GSActorCircle.php @@ -132,8 +132,9 @@ class GSActorCircle extends Entity 'name' => 'gsactor_circle', 'description' => 'a gsactor can have lists of gsactors, to separate their timeline', 'fields' => [ - 'tagger' => ['type' => 'int', 'foreign key' => true, 'target' => 'GSActor.id', 'multiplicity' => 'many to one', 'name' => 'gsactor_list_tagger_fkey', 'not null' => true, 'description' => 'user making the tag'], - 'tag' => ['type' => 'varchar', 'foreign key' => true, 'length' => 64, 'target' => 'GSActorTag.tag', 'multiplicity' => 'many to one', 'not null' => true, 'description' => 'gsactor tag'], // Join with GSActorTag + 'tagger' => ['type' => 'int', 'foreign key' => true, 'target' => 'GSActor.id', 'multiplicity' => 'many to one', 'name' => 'gsactor_list_tagger_fkey', 'not null' => true, 'description' => 'user making the tag'], + 'tag' => ['type' => 'varchar', 'length' => 64 //, 'foreign key' => true, 'target' => 'GSActorTag.tag', 'multiplicity' => 'many to one' // so, Doctrine doesn't like that the target is not unique, even though the pair is + , 'not null' => true, 'description' => 'gsactor tag', ], // Join with GSActorTag 'description' => ['type' => 'text', 'description' => 'description of the people tag'], 'private' => ['type' => 'bool', 'default' => false, 'description' => 'is this tag private'], 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], diff --git a/src/Entity/GSActorTagFollow.php b/src/Entity/GSActorTagFollow.php index b052909576..f1d9b421f5 100644 --- a/src/Entity/GSActorTagFollow.php +++ b/src/Entity/GSActorTagFollow.php @@ -95,10 +95,11 @@ class GSActorTagFollow extends Entity return [ 'name' => 'gsactor_tag_follow', 'fields' => [ - 'gsactor_tag' => ['type' => 'int', 'foreign key' => true, 'target' => 'GSActorTag.tag', 'multiplicity' => 'one to one', 'name' => 'gsactor_tag_follow_gsactor_tag_fkey', 'not null' => true, 'description' => 'foreign key to gsactor_tag'], 'gsactor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'GSActor.id', 'multiplicity' => 'one to one', 'name' => 'gsactor_tag_follow_gsactor_id_fkey', 'not null' => true, 'description' => 'foreign key to gsactor table'], - 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], - 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], + 'gsactor_tag' => ['type' => 'int', // 'foreign key' => true, 'target' => 'GSActorTag.tag', 'multiplicity' => 'one to one', // tag can't unique, but doctrine doesn't understand this + 'name' => 'gsactor_tag_follow_gsactor_tag_fkey', 'not null' => true, 'description' => 'foreign key to gsactor_tag', ], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], 'primary key' => ['gsactor_tag_id', 'gsactor_id'], 'indexes' => [