UUIDin Shopware 6?
Shopware 6 uses
UUID as the primary key for tables. How can we generate them? That's easy:
use Shopware\Core\Framework\Uuid\Uuid; $uuid = Uuid::randomHex();
You will get
UUID's like that:
b2797f53b1b84a82a70494270f2e9b1d ceb13f897cb342588270a0eaec046254 ff83a318808f412c9f657e9182f6ed78 ef880f9328d4497ba905fbba903a538f 6a2c6945d1714056993a42432e118b20 143ef23ebd304e4a8e002f4532d9ca44
Universally unique identifier (
UUID) is a random string containing the numbers
9 and the characters
f with a length of
Good question! As everything in life there are a long list of pro's and con's. Let me point out some reasons on both sides.
UUID's are great for API-first platforms because it prevents Race Condition. Data can come from all over the place such as mobile apps, marketplaces, social shopping, or local points of sale.
UUID's are great to enable these channel's to generate a unique primary key by themselves, without conflicting with other channels. Simple numbers would easily conflict among themselves
UUID's can be safe generated regardless of the database, since the primary key is not sequential
UUID's can make heavy operations slow. It can potentially become a bottleneck in terms of performance
UUID's take more space to be stored
See you on the next blogpost!