Let's assume there are systems. systems contains subsystems. subsystems contains devices. devices contains measurementpoints.
Lets assume an Webinterface /get/systems where all the systems related to a user are returned.
Now let's say users can have their own visibility on the systems. So when user A gets his systems it is another set - based on visibility rights - than user B gets.
The schema
CREATE TABLE system( sid INT NOT NULL AUTO_INCREMENT, cid INT NOT NULL, PRIMARY KEY(sid) ); CREATE TABLE subsystem( subsid INT NOT NULL AUTO_INCREMENT, sid INT NOT NULL, PRIMARY KEY(subsid) ); CREATE TABLE device( did INT NOT NULL AUTO_INCREMENT, subsid INT NOT NULL, PRIMARY KEY(did) ); CREATE TABLE mspot( mid INT NOT NULL AUTO_INCREMENT, did INT NOT NULL, PRIMARY KEY(mid) ); For a complete set of systems, subsystems, devices and measurementpoints it's a join within these tables. If it shall be extended to visbilitys, what is a viable approach?
First shot was to create a table like
CREATE TABLE permittedsystems ( sid INT NOT NULL, uid INT NOT NULL, PRIMARY KEY(sid, uid) ); (permittedsubsystems, permitteddevices and permittedmspoints are not showed here)
One example query of getting a users system is
SELECT * FROM customer JOIN user ON customer.cid = user.cid JOIN system ON system.cid = customer.cid LEFT JOIN subsystem ON system.sid = subsystem.sid LEFT JOIN device ON device.subsid=subsystem.subsid LEFT JOIN mspot ON mspot.did = device.did JOIN permittedsystems ON permittedsystems.uid = user.uid AND permittedsystems.sid = system.sid JOIN permittedsubsystems ON permittedsubsystems.uid = user.uid AND permittedsubsystems.subsid = subsystem.subsid JOIN permitteddevices ON permitteddevices.uid = user.uid AND permitteddevices.did = device.did JOIN permittedmspots ON permittedmspots.uid = user.uid AND permittedmspots.mid = mspot.mid WHERE user.uid = 1;` Any alternatives?
Thanks in advance
CREATE TABLE mspot.