bootstrapi
bootstrapi copied to clipboard
Add new entities to DB schema
SUPPOSITION
We have one main/meaningful entity provided by bootsrapi - USER. All the rest entities are either auxiliary for user operations (e.g. *_tokens, roles, rights, roles_to_rights) or system maintenance (e.g. migrations, seeds, ,logs). This is nice as a starting point at the very beginning. However, this is not enough even for a decent scaffolding.
PROPOSITION
Let's introduce additional general-purpose entity, reasonably called ENTITY
:) and some auxiliary/boilerplate entities in order to provide complex relations between entities and users. Proposed entities are:
ENITITY
--------
id BIGINT
type INT
status INT
owner_id BIGINT foreign key -> users.id
connector_id BIGINT foreign key -> connectors.id
attributes JSON
Entity represents arbitrary entity, owned by a USER (via owner_id
) and having arbitrary set of attributes.
CONNECTOR
--------------
id BIGINT
type INT
owner_type INT
Connector represents 'connection point' designed to provide relations between custom entities in the system (like entity
<-> entity
or user
<-> entity
, etc). Each entity in the system who intends to establish relations provides its 'connection point' - connector
in order to receive or to establish relations.
RELATION or may be called CONNECTION - named relatively to CONNECTOR above
-----------
id BIGINT
connector_id_a BIGINT foreign key -> connectors.id
connector_id_b BIGINT foreign key -> connectors.id
type INT
status INT
attributes JSON
Intended to setup a relation between two entities via their CONNECTOR
s
Possible relation/connection types:
-
b
is owned bya
-
b
is member ofa
-
b
is assigned toa
-
b
is child ofa
- ... etc ...
Also new attribute in USER entity would be needed - connector
USER
====
... all known fields
connector_id BIGINT foreign key -> connectors.id
Proposed structure would allow to build custom relations between all entity types in the system, opening direct way to construction of entity hierarchies owned by users, attach entities to another entities or users, etc
Imagine the following structure:
- entity of type 'event'
- entity of type 'collection'
- multiple entities of type 'note'
- relation 'event'-'collection' of type 'owned'
- relation 'note'-'collection' of type 'assigned to'
And as a result, we'll have 'event' with a 'collection' of 'notes' build on custom entity base.
PS. I can implement proposed update
DB schema is under discussion, let's produce some kind of generalized solution.