-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EPIC] Feat: /settings
+ settings.json
#363
Comments
I think the third option seems to be the least plausible out of the three. The only advantage is ease of development but you'd still need to parse the settings from it. Additionally, I think we still do need to transform the data. If not from the client but to the client. If we're using a statically-typed language (Dart) on mobile clients, it should expect specific fields and not parse them on runtime. Regardless, I'm torn between 1 and 2. However, I think the first one is the best option. Although the versatility that having a key-value store provides, it only makes sense when we expect to change the settings several times, which will most likely not be the case. I don't think the reduced efficiency outweighs the versatility factor. Not to say that I don't have a few constraints with the first option. Every time we want to add a customizable setting, we are forced to add a column and create a migration. In some cases, this can be cumbersome but for this use case, I think it's trivial. And with the added benefit of efficient querying, I believe the first option is the best one out of the three. |
@LuchoTurtle thank you for this insightful comment. 👌 Right now we only have a handful of migrations in the The closest example is defmodule App.Repo.Migrations.AddColorToTag do
use Ecto.Migration
def change do
alter table(:tags) do
add(:color, :text, default: "#FCA5A5")
end
end
end If we end up having a similar order of magnitude of settings as We could rapidly end up with many migrations as the columns/features would definitely not be added all at once. ⏳ For example I can imagine having considerably more settings than But to your point: if we are optimising for query speed so the |
@SimonLab would be good to get your thoughts on this if you have a few mins. 🙏 |
To facilitate "Progressive Interface / Experience" [ "PIE" 🥧😋 ] dwyl/product-roadmap#43
Each
person
using theApp
needs to have asettings.json
If we were using a
Document
DB like Mongo, Couch, etc. we would just store a doc in the format:{person_id}.json
But we're using
Postgres
(for better or worse; IMO better!) so we need to think about how we're doing this ...We want to have a single endpoint/controller that returns the settings "page" if queried with header
HTML
and returns the
settings.json
if requested withaccepts=JSON
or the.json
suffix.This is detailed in https://github.com/dwyl/content
There are at least 3 distinct ways to store
settings
data.String
JSONB
to store an arbitraryJSON
blob.What is our preference...? 🤷♂️
1. One Column per
setting
, One Row perperson
In this approach we store each
setting
as its' own column in the DB:The obvious advantage to this approach is efficiency of storage and immediately obvious which settings have been defined for a given
person
. The only disadvantage I can see is that the table will get very big very fast (number of columns) and may become difficult to read in ourPostgres GUI
. If we can live with this, I'd go with this approach.2. Row-level History with a Key:Value Store?
In the one row per
setting
key:value pair scenarioThus the
List
ofStructs
would be:The advantage of this approach is that we have built-in translatable descriptions/labels that are ready to be displayed in the interface.
3.
JSONB
?I was tempted to use
JSONB
to directly storeJSON
inPostgres
,see: https://fullstackphoenix.com/tutorials/add-jsonb-field-in-phoenix-and-ecto
But the author gives the following warning:
while
superficially it appears to make a lot of senseto store data we
expect
to be represented asJSON
asJSONB
,I get the feeling that we will benefit more from having a
schema
that we can verify against.and store using
papertrail
for full history.The advantages of
JSONB
over the other approaches to data storage listed above are obvious:there is almost no code to write to "transform" the data we just read it from the DB and send it to the client as-is.
To me the biggest disadvantages of
JSONB
are:settings
changes requires saving the entire blob ofJSON
each time.@SimonLab, @LuchoTurtle & @iteles it would be good to get your thoughts on this. 🙏 💬
The text was updated successfully, but these errors were encountered: