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

Database migration should create SQL constraints for relations #2332

Closed
10 tasks
bajtos opened this issue Feb 4, 2019 · 5 comments
Closed
10 tasks

Database migration should create SQL constraints for relations #2332

bajtos opened this issue Feb 4, 2019 · 5 comments
Labels
epic feature Relations Model relations (has many, etc.) stale

Comments

@bajtos
Copy link
Member

bajtos commented Feb 4, 2019

See #1718 for background context.

As a user building an LB4 application with HasMany BelongsTo or HasOne relation, I want lb4 automigrate to define SQL constraints (foreign key, unique) in such way that referential integrity will be correctly enforced by the database.

Acceptance criteria

  • Improve the base SQL connector loopback-connector to include CONSTRAINT definitions when updating tables.
  • Find out how to test this functionality in automated way in our connectors. It's important to test both autoupdate (incremental changes to existing schema) and automigrate (creating new tables).

Ensure the new tests are executed as part of connector test suite and that they pass on our CI for the following connectors

Depending on how much work the following connectors will require, either improve them as part of this story or create follow-up stories:

@bajtos bajtos added feature Relations Model relations (has many, etc.) labels Feb 4, 2019
@nabdelgadir
Copy link
Contributor

We'll do mysql for this story and create follow-up stories for the remaining ones, as it's quite large.

@Microtribute
Copy link

Microtribute commented Apr 1, 2020

@bajtos @nabdelgadir I am able to create foreign key constraints by adding settings.foreignKeys configuration to a model. but the problem is loopback attempts to create foreign keys along with the table creation. A foreign key could reference a column of a table that is yet to be created. In this case, loopback migration script fails. Foreign key creation must be delayed until tables are all created. Here's an example of the error. That happened because the users table had not been created yet.
image

@klassicd
Copy link
Contributor

klassicd commented Apr 2, 2020

@authenticode You may be interested in loopbackio/loopback-connector#170 which forces migrations to be run in a series so you can effectively use the models option to migrateShema as mentioned here https://loopback.io/doc/en/lb4/todo-list-tutorial-sqldb.html#database-migration-using-npm-run-migrate-command

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Dec 25, 2020
@stale
Copy link

stale bot commented Jul 14, 2021

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic feature Relations Model relations (has many, etc.) stale
Projects
None yet
Development

No branches or pull requests

5 participants