loopbackio / loopbackio/loopback-next

Strong relations with referential integrity

Aperta
#2,331 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

epic Relations
Lingua principale
TypeScript
Stelle
5.1k
Fork
1.1k
Merge medio
2g 21h
PR unite (30g)
27

Descrizione

Essentially, we see two levels of relations:

  • Weak relations, where the developer primarily wants to navigate related models (think of GraphQL) and referential integrity is either not important or already enforced by the (SQL) database.
  • Strong relations, where the referential integrity is guaranteed by the framework together with the database.

IMO, referential integrity must be guaranteed at repository level (or lower). For example, when a test helper invokes repository APIs to seed the database with sample data, then we want the referential integrity to be preserved. If we implemented referential integrity at controller level, then consumers of Repository API would be bypassing these checks and would be able to created corrupted data.

Implementation wise, it's important to implement referential integrity in way that does not create any race conditions. For example, a naive implementation calling findById on the source model before creating a new instance of the target model creates a race condition - if another request deletes the source model instance after findById received database response but before create command is set, then we end up with corrupted data.

With SQL databases, referential integrity is typically implemented by defining FOREIGN KEY constraints. In the context of LB4, this means that lb4 migrate must create such constraints based on the relations configured by the app.

With NoSQL databases, users should use different relation types than hasMany, for example referencesMany or embedsMany.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando le API dei repository e il punto di ingresso lb4 migrate nel repository, quindi esamina come vengono rappresentate le relazioni configurate per i database SQL. Confronta i vincoli FOREIGN KEY richiesti con i tipi di relazione separati suggeriti per i database NoSQL. Il lavoro è completato quando l’integrità referenziale viene applicata senza race condition lungo i percorsi di repository e migrazione supportati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
sql, typescript
Ambito
backend-api-design, databases
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.