数据建模问题 [英] Data modeling question

查看:150
本文介绍了数据建模问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的客户在注册我的申请时使用下列其中一项:

My clients use one of the following when they sign up for my application:


  1. Foo API 需要 auth_key 密码电子邮件

  2. API (需要 secure_code 用户名密码

  3. Bar API (需要 xyz_code pass_key

  1. Foo API (requires a "auth_key", "password", "email")
  2. Acme API (requires a "secure_code", "username", "password")
  3. Bar API (requires a "xyz_code", "pass_key")

(假名,为简单起见还省略了15个)

(fake names, and about 15 more omitted for simplicity)

我不想在我的数据库中有10-15个表对于我提供的不同的API集成选项(特别是当他们都是相同的事情,他们只是从整个列表中选择1)。

I would prefer not to have 10-15 tables in my database just for the different API integration options I offer (particularly when they're all for the same thing and they just choose 1 from the whole list).

我的解决方案是:

使用 api_name 列创建一个 api_configuration 其中包含特定API的代码(例如foo_api

Make a api_configuration table with a column called api_name which holds a code for a specific API (e.g. "foo_api")

创建一个名为 credentials_attribute 返回 api_configuration ,一个名为 name 的列一个名为 value 的列。

Make a table called credentials_attribute with a foreign key back to api_configuration, a column called name, and a column called value.

然后我构建一个用于选择API的UI。如果他们选择Acme API,它会要求一个secure_code,username和password,并在 credentials_attribute 值对。

Then I build a UI for choosing an API. If they choose Acme API, it'll ask for a "secure_code", "username", and "password", and create a row in credentials_attribute for each of the name/value pairs.

在我的 api_configuration 的ORM模型上,我可以创建一个查找 api_name 的<> credentials_attribute 值。

On my ORM model for api_configuration I can make a method for looking up credentials_attribute values based on the current api_name.

或者有另一种方式,你会做到,如果你必须为这个问题建模一个解决方案?请解释你的理由(例如,更好的性能等)

Does this solution feel right, or is there another way you would do it, if you had to model a solution for this problem? Please explain your rationale as well (ie, better for performance, etc)

推荐答案

如果我正确理解的情况,还有gen-spec设计模式的另一种情况。查找泛化专业化关系建模。

If I understand the case correctly, it looks like yet another case of the gen-spec design pattern. Look up "generalization specialization relational modeling".

有关对象建模的教程通常涵盖gen-spec,但是关系建模教程通常不会。但很好理解,网上有一些优秀的文章。

Tutorials on object modeling usually cover gen-spec, but tutorials on relational modeling often do not. But it's well understood, and there are some excellent articles on the web.

这篇关于数据建模问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆