Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V5] Database #52

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

[V5] Database #52

wants to merge 8 commits into from

Conversation

Marc-Roig
Copy link

This PR introduces a draft version of the database layer changes for the V5 major release.

You can read it here.

@strapi-cla
Copy link

strapi-cla commented Sep 4, 2023

CLA assistant check
All committers have signed the CLA.

@Marc-Roig Marc-Roig added the v5 label Sep 4, 2023

## Draft and Publish

Introducing a new version of draft & publish. One which allows having one draft and one published entry at the same time.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be possible to have more than 2 publication states. Think about having diffrent environments where you want to publish a collection type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate more on the example? What would be the new publication states in those cases?

One additional feature we had in mind is private drafts, but that's something that might come after having the v5 foundations ready.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi the setup in the case is like having multiple tenant and a collection that gets pubslihed to their different environments:

For example we have consultant that can have multiple web pages where they would be available.

consultant
| id | name | publication_state | publication_id |
| 1 | Karl Heinz | draft | 0 |
| 2 | Karl Heinz | live| 1 |
| 3 | Karl Heinz | live:immobilien | 1 |
| 4 | Karl Heinz | live:beratung | 1 |

Other use case we have are emails that can be sent (by mail) and published to a webpage, were we pin the mail publication state, but the live publication can be changed later (for example because of typos)

mail
| id | text | publication_state | publication_id |
| 1 | xxx | draft | 0 |
| 2 | xxx | mail | 1 |
| 3 | xxx | live | 1 |

rfcs/xxxx-v5-database.md Outdated Show resolved Hide resolved
The database schema of `links` join tables :

<p align="center">
<img src="https://github.com/strapi/rfcs/assets/20578351/f6ebb23e-c6e7-47b6-bdae-8030c80786a6" width="700px" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pivot_publicationState should be pivot_publication_state. And i think the names should not be prefixed.


Downsides:

- Links will not allow for bidirectionality. A relation that references an entry to a document introduces many complexities that prevents bidirectionality, or makes it rather difficult. The first versions of links will not have bidirectionality in mind.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think bidirectional should be included in v5, Otherwise parent/children relationsship of pages collection types are hard to implement in v5.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are trying to work on this, and how to make them work with documents. We will keep you all updated. 🙏

# Unresolved questions

- How do we manage life cycles?
- A database lifecycle would trigger at an entry level, not a document level. As everything will be document oriented, database life cycles might have less sense from a user perspective in V5.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a method to have lifecycles on document level as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! We will have a document service (similar to the current entity service) with it's own lifecycles.

@derrickmehaffy
Copy link
Member

I am quite worried that we won't be able to cover the use-cases properly for lifecycles. Within v4 lifecycles are the only means to directly impact both the content and admin APIs at the same time and we already have limitations around the relational data that doesn't exist within the lifecycles (not even to mention components and dynamic zones which don't have any lifecycle capability in v4 period).

Lifecycles IMO are quite important and something we should take a decision on before stable release and could prevent adoption and migration to v5 for those with more complex use-cases.

Plugin developers also do rely on our dynamic lifecycle injection in v4 quite often and many of our customers are actively using them as well for various reason, down to simple validation that we don't cover normally, all the way up to things like live updating data from external sources and data mirroring.

@derrickmehaffy
Copy link
Member

For example, lifecycle hooks for components alone has 75 votes: https://feedback.strapi.io/feature-requests/p/lifecycle-hooks-for-components

@pwizla
Copy link

pwizla commented Sep 22, 2023

Minor point here, but on the following schema, shouldn't article_document_id from the article_author table link to document_id and not id in the article table, or did I misunderstand something? 🤔

Screenshot 2023-09-22 at 11 20 37

@Marc-Roig
Copy link
Author

@pwizla good catch! Updated the diagram

@Marc-Roig
Copy link
Author

I am quite worried that we won't be able to cover the use-cases properly for lifecycles. Within v4 lifecycles are the only means to directly impact both the content and admin APIs at the same time and we already have limitations around the relational data that doesn't exist within the lifecycles (not even to mention components and dynamic zones which don't have any lifecycle capability in v4 period).

Lifecycles IMO are quite important and something we should take a decision on before stable release and could prevent adoption and migration to v5 for those with more complex use-cases.

Plugin developers also do rely on our dynamic lifecycle injection in v4 quite often and many of our customers are actively using them as well for various reason, down to simple validation that we don't cover normally, all the way up to things like live updating data from external sources and data mirroring.

@derrickmehaffy The idea is not to remove the database lifecycles, but to add new ones on the Service layer. Ones where you can hook to listen to document changes.
The database lifecycles will still be maintained and what we could do is an evaluation of which issues there could be on db lifecycles when introducing documents.

At the moment I can not think of any, and we plan to internally use the db lifecycles too!
Do you think we might want to elaborate on this more? @derrickmehaffy

@Boegie19
Copy link

Boegie19 commented Oct 2, 2023

@Marc-Roig Would the end of the entity-service layer not be better? since you could change the service its entity-service request or have entity-service decorators who change stuff. so the only place where you could do this the right way is the end of the entity-service or right of the end of the document service if the entity-service gets removed.

@Marc-Roig
Copy link
Author

What benefit would you see of having this in the ES rather than on the database layer?
Leaving lifecycles in DB is a must in V5 imo, as we aim to keep as much compatibility as possible.

@Boegie19
Copy link

Boegie19 commented Oct 2, 2023

@Marc-Roig

What benefit would you see of having this in the ES rather than on the database layer?

ES layer also knows about components and dynamic zones. so has more context. and this would mean if you blocked a request it would also block the components. and not only the highest level of the content-type.

Leaving lifecycles in DB is a must in V5 imo, as we aim to keep as much compatibility as possible.

Understandable I am not saying to remove them I am saying maby add a second layer of them.

@derrickmehaffy
Copy link
Member

Do you think we might want to elaborate on this more? @derrickmehaffy

Absolutely we need to, both in the changes we will make and the differences to v4 comparatively. I think some of the issues around lifecycles is we don't use them enough ourselves so leveraging them for our purposes would be a good test point.

@derrickmehaffy
Copy link
Member

What benefit would you see of having this in the ES rather than on the database layer? Leaving lifecycles in DB is a must in V5 imo, as we aim to keep as much compatibility as possible.

Agreed but I also agree with boegie here around implementing ES lifecycles too so each user can pick the right spot for their code to achieve what they want.

@Marc-Roig
Copy link
Author

Agreed but I also agree with boegie here around implementing ES lifecycles too so each user can pick the right spot for their code to achieve what they want.

Yes! The current proposal is to create lifecycles on the Document Service layer, which also will be responsible to handle components.
In my opinion, having lifecycles on that layer will make the DB lifecycles much less necessary for people (but we will keep them neverhteless)

@bglidwell
Copy link

Please keep and even further develop (by adding db support for things like cascade delete) the concept of "owned" records. ie. OneToMany OneToOne

These are critical structural distinctions that can easily be overlooked when pursuing versioning/i18n/etc

I am worried too much will be abstracted to the JS/TS side in strapi and the databases (and the data they store) will be useless outside the strapi application. Keep in mind several strapi devs are working on applications that store more than just marketing copy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants