For the sake of an example, let's say I'm using Picasa, Flickr and 500px APIs, and that each of the services has limitations on these simplified parameters:
- overall account space
- individual file size
I have a database table called external_services
where I store the details about those services, my developer access tokens, etc., and I need to refer to the above limits in my application. I can think of the following ways to store that information:
1) Add columns to it to keep the information inline.
+--------+-------+--------+-
| Name | Space | File | …
+--------+-------+--------+-
| Flickr | 1 TB | 200 MB | …
+--------+-------+--------+-
| Picasa | 15 GB | 75 MB | …
+--------+-------+--------+-
| 500 px | 60 GB | ?? MB | …
+--------+-------+--------+-
2) Alternatively, keep a separate meta table called external_services_details
with a one-to-many relation.
+--------+------------+--------+
| Name | Parameter | Value |
+--------+------------+--------+
| Flickr | acct_space | 1 TB |
+--------+------------+--------+
| Flickr | max_file | 200 MB |
+--------+------------+--------+
| Picasa | acct_space | 15 GB |
+--------+------------+--------+
| Picasa | max_file | 75 MB |
+--------+------------+--------+
| 500 px | acct_space | 15 GB |
+--------+------------+--------+
| … | … | … |
My problem is I can't tell the difference between these two approaches in terms of both options being future-proof, I mean I can't foresee a scenario where there will be a difference. Will I regret picking one over another? The reason I ask this is that I'm sure better programmers than I am must have dealt with this before and learned their lessons, and that there already is an answer somewhere.
Now, on top of that, there are also specific limits of each of the services. For example, Flickr requires that Images can be no more than 31.25 times wider than they are tall, and in it's Fair Usage Policy, 500px limits new users to a maximum of 20 new photographs/images per week.
My thinking is this: if the requirements differ, it feels like a better way would be to store them in a meta table, with a flexible number of rows linked to each service. But if I start incorporating this logic into the app, I'll have to normalize the data I have anyway, that is, if Flickr limits the image ratio, I'd have to have an answer to that for each of the remaining services, even if they don't list that limitation - then I'd have to have ∞
stored there or something. Which kind of means that the structured table approach does actually make more sense here, as it enforces that structure.
What would be the effective way to handle this? Is there a name to this pattern?
I could have asked this on DBA, but a portion of this question deals with getting the right application logic, and that is software design.
Sorry about the poor table layout design
References. The values in the tables above are real, I researched. If someone somehow ends up on this page searching for the actual limits, here they are:
Strategy Pattern
. I would use a single table and store the details as JSON in a text field.