我目前正在为我的组织开发自定义Kong插件。我正在尝试利用Kongs的身份验证和授权功能来编写一个权限插件,该插件将允许某些人和团体将不同的API组件提升到环境中。在设计插件的初始迁移时,我遇到了一个问题,就是不知道如何在PostgreSQL中正确表示我的实体关系。
我环顾四周,发现以下表示法是一种选择
"components" UUID ARRAY ELEMENT REFERENCES "elpt_components" ("id"),
但是我不确定这是否适用,或者我是否应该采用典型的桥梁实体方法。
我的daos.lua实体之一
local elpt_users = {
primary_key = {"id"},
name = "elpt_users",
fields = {
{id = typedefs.uuid},
{consumer_id = {type = "foreign", reference = "consumers", required = true, on_delete = "cascade"}},
{components = {type = "array", required = true, elements = {type = "foreign", reference = "elpt_components"}}},
{environments = {type = "array", required = true, elements = {type = "foreign", reference = "elpt_environments"}}},
{earliest_hour = {type = "number", required = true}},
{earliest_minute = {type = "number", required = true}},
{latest_hour = {type = "number", required = true}},
{latest_minute = {type = "number", required = true}},
}
}
在我为Postgres迁移时相应的表创建。
CREATE TABLE IF NOT EXISTS "elpt_users" (
"id" UUID PRIMARY KEY,
"consumer_id" UUID REFERENCES "consumers" ("id") ON DELETE CASCADE,
"components" UUID ARRAY ELEMENT REFERENCES "elpt_components" ("id"),
"environments" UUID ARRAY ELEMENT REFERENCES "elpt_environments" ("id"),
"earliest_hour" INTEGER REQUIRED,
"earliest_minute" INTEGER REQUIRED,
"latest_hour" INTEGER REQUIRED,
"latest_minute" INTEGER REQUIRED,
);
什么是我的用例的最佳方法,为什么?