【发布时间】:2014-11-10 21:37:02
【问题描述】:
所以我对使用 Firebase 比较陌生,我试图弄清楚如何构建我的数据以使其安全和规范化。
我的数据需要基于用户的安全性,在概念上看起来像这样:
{
"users": {
"simplelogin:1": {
"email": "test@test.com",
"id": "1",
"name": "test",
"provider": "password",
"clients": {
"client1": {
"name": "testClient",
"projects": {
"project1": {
"name": "testProject",
"sites": {
"site1": {
"name": "testWobsite",
"hits": {
"hit1": {},
"hit2": {},
"hit3": {}
}
},
"site2": {}
}
},
"project2": {}
}
},
"client2": {
"name": "test",
"projects": {}
},
}
},
"simplelogin:2": {
"email": "test2@test2.com",
"id": "2",
"name": "test2",
"provider": "password",
"clients": {}
}
}
}
如你所见,这里的数据结构是极度嵌套的...
用户有客户,客户有项目,项目有网站,网站有点击量...
所以这是我的主要问题之一 - 我不完全确定如何构造这些数据以使其不那么嵌套。
我遇到的另一个问题是弄清楚如何使用 Firebase 安全规则。
本质上,我希望用户能够创建、更新和删除他们拥有的所有数据(客户、项目、网站和点击)
点击应该是公开可写的,但只有拥有它的用户才能读取。
用户应该能够注册和登录,但不能读取或写入任何其他人的数据。
如果有人对此有任何想法或任何提示或指示,将不胜感激任何建议!
谢谢!
编辑
这是我对数据进行规范化的尝试……有什么想法吗……?
{
"users": {
"simplelogin:1": {
"email": "test@test.com",
"id": "1",
"name": "test",
"provider": "password",
"clients": {
"testClient": "client1",
"test": "client2"
}
},
"simplelogin:2": {
"email": "test2@test2.com",
"id": "2",
"name": "test2",
"provider": "password",
"clients": {}
}
},
"clients": {
"client1": {
"owner": "simplelogin:1",
"parent": "",
"name": "testClient",
"projects": {
"testProject": "project1",
"testProject_2": "project2"
}
},
"client2": {
"owner": "simplelogin:1",
"parent": "",
"name": "test",
"projects": {}
}
},
"projects": {
"project1": {
"owner": "simplelogin:1",
"parent": "client1",
"name": "testProject",
"sites": {
"testWebsite": "site1",
"testWebsite2": "site2"
}
},
"project2": {
"owner": "simplelogin:1",
"parent": "client1",
"name": "testProject_2",
"sites": {}
}
},
"sites": {
"site1": {
"owner": "simplelogin:1",
"parent": "project1",
"name": "testWebsite",
"hits": {
"firstHit": "hit1",
"secondHit": "hit2",
"thirdHit": "hit3"
}
},
"site2": {
"owner": "simplelogin:1",
"parent": "project1",
"name": "testWebsite2",
"hits": {}
}
},
"hits": {
"hit1": {
"owner": "simplelogin:1",
"parent": "site1",
"name": "firstHit"
},
"hit2": {
"owner": "simplelogin:1",
"parent": "site1",
"name": "secondHit"
},
"hit3": {
"owner": "simplelogin:1",
"parent": "site1",
"name": "thirdHit"
}
}
}
【问题讨论】:
-
understanding data 上有一个完整的文档,structuring data 上有另一个文档,还有blog posts 和stack overflow questions。将它们放在自己的路径中,并使用记录 ID 来引用它们。
标签: database-design firebase firebase-security