Is there any way to achieve composite key functionality in strapi for postgres or any RDBMS?
Hi @AmreeshTyagi sadly at the moment we don’t have any good way to modify the structure of the primary key and we don’t currently have the mappings to support composite keys yet.
For Q4 2020 (this quarter) we are planning a major database refresh to support better customization of the database layer and even allowing users to create their own database connectors (ORMs).
Thanks. Really a good news.
For now, I found a workaround to prevent duplicate data insertion.
I am querying for count where a=1 and b=2 and c=3 .
Here a, b and c are my primary keys as a composite key and if count>0, skip insert from API.
Another workaround I’ve tried is creating a composite unique constraint, manually, in postgres via pgadmin. (As described here: Unique Constraint Dialog — pgAdmin 4 5.2 documentation)
It seems to be working with some simple tests I’ve performed as Strapi returns a ‘unique constraint error’ in the admin ui when I attempt to create a non-unique record. I’m just not sure if this will interfere with Strapi somewhere down the line.