loopbackio / loopbackio/loopback-next
Strong relations with referential integrity
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 5.1k
- フォーク
- 1.1k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 27
説明
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`.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、repository API と repository の lb4 migrate エントリーポイントをたどり、次に SQL データベース向けに設定されたリレーションがどのように表現されているかを確認します。要求されている FOREIGN KEY 制約と、NoSQL データベース向けに提案されている別個のリレーション型を比較します。サポート対象の repository および migration パス全体で、race condition なしに参照整合性が強制されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- sql, typescript
- 領域
- backend-api-design, databases
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100