Issues i faced with Strapi
The Headless CMS, which can be installed on premise, impressive UI & ease of development are all the reasons, why I picked it for the current project, & if you only use the API & UI to manage your data, maybe you will never run into these issues. [ 5-things-i-love-about-strapi ]
For my Use case, I would like a separately installed Postgres DB ( running in its own Docker ) & a custom server, that would connect to this DB directly, and make CRUD changes.
The same Postgres, is also what Strapi is connecting to.
ID & Unique Constraints
The ability to customize a primary key is no longer an option (for the time being). It is recommended to use the UUID plugin if you would like an additional unique, non-serial integer key. ( how-to-set-primary-key-in-strapi-other-then-id )
Well not a problem, I can always create another field, as suggested and mark it as unique
Now when i try to add an entry, from the strapi API, with the same wordId — it doesn’t allow me to. Awesome
But wait, If i were to navigate to the PostgresDB, connecting to it via pgAdmin, & move to the words table, there are no unique constraints.
Well what does it mean?
- That all the unique constraint checks are only implemented at the API level. If i try to add something from the UI, it would make a call to the DB, find if there are existing values, & if so, then show the popup.
- But the application is not taking advantage of the capabilities of the DB, given the fact that Strapi uses Knex.js , which does offer this capability.
- In my case, it means, that the custom server will also need to implement such a check. ( unnecessary work )
I might try to add a constraint directly to the DB, but the moment, I make a change to the model & save, it will overwrite everything.
This along with the fact, that i cannot customize the primary key, implies i will need to make un-necessary calls, expecially in case of many-to-many relations.
Again all of this will be taken care of, if I am using the Strapi APIs, but anything that i wish to do on the DB directly ( with custom Apis ), will need some more work.
Array data type
Postgres provides an Array field type, & so does Knex.
In fact there is also a post, to add array type in Strapi. I tried doing this and it did not work.
The data type in itself is very useful to store a list of hobbies, tags, list of ids etc, essentially a list of strings.
There are other ways of modelling it.
- One to many relation
- Repeatable Components ( Strapi ) — but these are array of objects, so not applicable.
- JSON type field with a key to hold an array.
All of these are possible solutions, but still they seem as workaround. I am hoping for the array type to work.
I will still however continue to evaluate & use Strapi for my current project. :)
As i have been evaluating Strapi & customizing it, I am also updating it here.
Customizing Strapi V4