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

Spike: Declarative definition of FOREIGN KEY and UNIQUE constraints #2606

Closed
5 tasks done
bajtos opened this issue Mar 18, 2019 · 5 comments
Closed
5 tasks done

Spike: Declarative definition of FOREIGN KEY and UNIQUE constraints #2606

bajtos opened this issue Mar 18, 2019 · 5 comments
Assignees
Labels

Comments

@bajtos
Copy link
Member

bajtos commented Mar 18, 2019

To support strong relations with referential integrity enforced by the database, we need a mechanism allowing models to define FOREIGN KEY and UNIQUE constraints in a declarative way.

Let's consider the relation "Customer has one Account", using account.customerId as the relational property. As part of the domain model definition, we need to define the following constraints:

  • FOREIGN KEY: the value stored in account.customerId must be an existing customer id.
  • UNIQUE: there can be at most one record (Account instance) with a given customer id.

Things to consider:

  • UNIQUE constraint can be composite. E.g. on GitHub, we want the combination of (user, repo) to be unique.

  • FOREIGN KEY constraints can be composite too. See e.g. here:

    FOREIGN KEY (ref_num, ref_type) REFERENCES accounts
      (acc_num, acc_type)
  • In LB3 (and loopback-datasource-juggler), we may already have partial support for foreign keys.

Acceptance criteria

  • Read through juggler code-base and find out what's the current implementation.
  • Describe the current implementation - what works, how does it works, what is missing. (E.g. composite constraints).
  • Propose a solution for expressing FK/UNIQUE constraints in model/property definitions. (No decorators involved here.)
  • Propose a solution for defining FK/UNIQUE constraints using TypeScript decorators. Do we want to define new decorators like @foreignKey() and @unique()?
  • Create a list of user stories to implement the proposals

There should be a pull request with any spike/PoC bits of code used to verify the proposals, and a /_SPIKE_.md file with the spike documentation (description or the current status, high-level overview of the proposals, etc.)

Out of scope

@bajtos bajtos changed the title Spike: declarative definition of FOREIGN KEY and UNIQUE constraints Spike: Declarative definition of FOREIGN KEY and UNIQUE constraints Mar 18, 2019
@emonddr
Copy link
Contributor

emonddr commented Mar 19, 2019

Timebox 2.5 weeks please.

@bajtos
Copy link
Member Author

bajtos commented Apr 9, 2019

spike pull request: #2712

@bajtos
Copy link
Member Author

bajtos commented Apr 18, 2019

Created the following follow-up stories:

Closing this spike as done.

@odykyi

This comment has been minimized.

@achrinza
Copy link
Member

achrinza commented Mar 19, 2020

@odykyi Thanks for the ethusiasm to help others! ❤️

However please refrain from re-posting the same solution on other issues unless it directly resolves the issue at hand.

This may pollute the contributors' (email) notifications which may make it difficult to sort through other issues.

For example, this is a spike for a new feature that has already been closed. Hence a workaround isn't needed.

For others closed/stale issues, it's better to open a new issue if you're experiencing a similar issue as the codebase may have changes significantly since the original issue was opened.

Nonetheless, I hope this doesn't discourage from future contributions to open source projects, including LoopBack 😃

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

No branches or pull requests

5 participants