sourcefuse / loopback4-starter

Loopback 4 starter application. Multi-tenant architecture supported. Authentication, Authorization, Soft deletes, environment vars, Audit logs, included.
MIT License
158 stars 59 forks source link

npm run migrate --rebuild does not work as expected #75

Closed arnaud16571542 closed 3 years ago

arnaud16571542 commented 3 years ago

Describe the bug Using the command "npm run migrate --rebuild ", the '--rebuild' arg is not passed to arguments list. The program is kept using ALTER mode.

To Reproduce In command line, execute "npm run migrate --rebuild " The utility write "Migrating schemas (alter existing schema)" instead of "Migrating schemas (drop existing schema)"

Expected behavior The program should take into account the --rebuild flag

Additional context A dump of args show the --rebuild is not present.

I have upgraded my migrate function with the code below. However, I'm a new Loppback user, I think i saw it worked several month ago. I must have done something wrong somewhere :) (Note: I'm using npm version 7.6.2) .


export async function migrate(args: string[]) {
  console.log('=== Schema migration utility ===');
  console.log('Usage: npm run migrate [rebuild]');

  const existingSchema = args.includes('rebuild') ? 'drop' : 'alter';
  console.log('> Migrating schemas using %s mode', existingSchema.toUpperCase());

  console.log(" - Instanciating RESTApp...")
  const app = new RESTApp();
  console.log(" - Booting RESTApp...")
  await app.boot();
  console.log(" - Migrating schemas using %s mode...", existingSchema.toUpperCase())
  await app.migrateSchema({ existingSchema });
  console.log(" - Done. Exiting.")

  // Connectors usually keep a pool of opened connections,
  // this keeps the process running even after all work is done.
  // We need to exit explicitly.
  process.exit(0);
}
arnaud16571542 commented 3 years ago

How silly me....😅 The documentation here https://loopback.io/doc/en/lb4/Database-migrations.html state: npm run migrate -- --rebuild Sorry guys !