loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.95k stars 1.07k forks source link

[Spike] Automigrate: no need to specify the order of tables to be migrated #2831

Closed dhmlau closed 3 years ago

dhmlau commented 5 years ago

Description / Steps to reproduce / Feature proposal

A follow-up story suggested by @bajtos from https://github.com/strongloop/loopback-next/pull/2448#discussion_r280759662

Capturing a summary here When calling the migrate script (npm run migrate) to create tables in PostgreSQL with foreign key constraints, we need to specify the order explicitly, i.e.

await app.migrateSchema({
  existingSchema,
  // The order of table creation is important.
  // A referenced table must exist before creating a
  // foreign key constraint.
  // For PostgreSQL connector, it does not create tables in the
  // right order.  Therefore, this change is needed.
  models: ['TodoList', 'Todo', 'TodoListImage'],

@bajtos suggested opening a new GH issue to find out how to improve our migration tool to not require that explicit order. Ideally, we can migrate tables first and define FK constraints second, then the order would not matter.

Acceptance Criteria

cc @bajtos @elv1s

stale[bot] commented 3 years ago

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[bot] commented 3 years ago

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.