@@ -2195,4 +2195,50 @@ public function testCreateAttributesDelete(): void
21952195 $ this ->assertCount (1 , $ attrs );
21962196 $ this ->assertEquals ('b ' , $ attrs [0 ]['$id ' ]);
21972197 }
2198+
2199+ public function testCreateAttributeWhileMigrating (): void
2200+ {
2201+ /** @var Database $database */
2202+ $ database = $ this ->getDatabase ();
2203+
2204+ // Skip test if adapter doesn't support shared tables
2205+ if (!$ database ->getAdapter ()->getSharedTables ()) {
2206+ $ this ->expectNotToPerformAssertions ();
2207+ return ;
2208+ }
2209+
2210+ // Prepare collection
2211+ $ database ->createCollection ('migration_test ' );
2212+ $ database ->setMigrating (true );
2213+
2214+ // First creation, as usual
2215+ $ this ->assertTrue ($ database ->createAttribute ('migration_test ' , 'status ' , Database::VAR_STRING , 128 , true ));
2216+
2217+ $ collection = $ database ->getCollection ('migration_test ' );
2218+ $ attributes = $ collection ->getAttribute ('attributes ' );
2219+ $ this ->assertCount (1 , $ attributes );
2220+ $ this ->assertEquals ('status ' , $ attributes [0 ]['$id ' ]);
2221+
2222+ // Second creation, no exceptions, no duplicates
2223+ $ result = $ database ->createAttribute ('migration_test ' , 'status ' , Database::VAR_STRING , 128 , true );
2224+ $ this ->assertTrue ($ result );
2225+
2226+ $ collection = $ database ->getCollection ('migration_test ' );
2227+ $ attributes = $ collection ->getAttribute ('attributes ' );
2228+ $ this ->assertCount (1 , $ attributes );
2229+ $ this ->assertEquals ('status ' , $ attributes [0 ]['$id ' ]);
2230+
2231+ // Third creation, same as second, once more, just in case
2232+ $ result = $ database ->createAttribute ('migration_test ' , 'status ' , Database::VAR_STRING , 128 , true );
2233+ $ this ->assertTrue ($ result );
2234+
2235+ $ collection = $ database ->getCollection ('migration_test ' );
2236+ $ attributes = $ collection ->getAttribute ('attributes ' );
2237+ $ this ->assertCount (1 , $ attributes );
2238+ $ this ->assertEquals ('status ' , $ attributes [0 ]['$id ' ]);
2239+
2240+ // Cleanup
2241+ $ database ->setMigrating (false );
2242+ $ database ->deleteCollection ('migration_test ' );
2243+ }
21982244}
0 commit comments