openclimatefix / pv-site-datamodel

Datamodel for PV sites
MIT License
2 stars 10 forks source link

Multiple Clients #73

Closed peterdudfield closed 10 months ago

peterdudfield commented 1 year ago

We want to upgrade the datamodel so we can have multiple clients viewing different sites.

Detailed Description

Currently, we have one client, that has all the sites attached to it.

We want to be able to do the following

  1. one user - can add or view one site
  2. one user, can add or view multiple sites
  3. Two users (for example from the sample company), want to look at one site
  4. Two users, wanting to look at multiple sites (could be added by another user). Any user from site group can add a site.
  5. OCF user want to see everything (admin)

Datamodel proposal:

  graph TD;
      User-- N:1 -->SiteGroup;
      SiteGroup-- N:N -->Site;
  1. one user - one site
  graph TD;
      A(User=Alice)-->B(SiteGroup=Alice1);
      B --> C(Site);
  1. one user - two sites
  graph TD;
      A(User=Alice)-->B(SiteGroup=Alice1);
      B --> C1(Site1);
B --> C2(Site2);
  1. Two users - one site
  graph TD;
      A1(User=Alice)-->B(SiteGroup);
A2(User=Bob)-->B(SiteGroup);
      B --> C1(Site1);
  1. Two users - two site
  graph TD;
      A1(User=Alice)-->B(SiteGroup);
A2(User=Bob)-->B(SiteGroup);
      B --> C1(Site1);
B --> C2(Site2);
  1. OCF can see everything
  graph TD;
      A1(User=Alice)-->B(SiteGroup1);
A2(User=Bob)-->B(SiteGroup1);
A3(User=OCF)-->B2(SiteGroup2);
      B --> C1(Site1);
B --> C2(Site2);
      B2 --> C1(Site1);
B2 --> C2(Site2);
B2 --> C3(Site3);

Context

Possible Implementation

dev

pro

peterdudfield commented 1 year ago

@braddf @devsjc I've written this up here.

Please add comments and questions on here (if you have any).

Note: sql relationships are sometimes hard, so happy to help out with that

peterdudfield commented 1 year ago

https://stackoverflow.com/questions/5756559/how-to-build-many-to-many-relations-using-sqlalchemy-a-good-example

Screenshot 2023-07-19 at 10 55 21

peterdudfield commented 1 year ago

I'm gona close this despite one task being open, but thats is stand alone

peterdudfield commented 1 year ago

Would be good to move some of these mermaid diagrams to the readme.md