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

Migrating MySQL and Mongo on the same project crush #4325

Closed
khlilturki97 opened this issue May 18, 2020 · 1 comment
Closed

Migrating MySQL and Mongo on the same project crush #4325

khlilturki97 opened this issue May 18, 2020 · 1 comment
Labels

Comments

@khlilturki97
Copy link

I followed this tutorial and everything worked fine. I managed to work with relations on MySQL db.

In my use case, i had to add another datasource based on Mongo and i had a bug while migrating

Unable to migrate models not associated with this data source

i had to translate it from french, the original text is

Impossible de migrer les modèles non associés à cette source de données

i digged a little in RepositoryMixin class, and found out that the problem came from migrateSchema method

i overrided the method (copy past x) ) and changed

for (const b of dsBindings) {
  const ds = await this.get(b.key);
  if (operation in ds && typeof ds[operation] === 'function') {
    debug('Migrating dataSource %s', b.key);
    await ds[operation](options.models);
  }
  else {
    debug('Skipping migration of dataSource %s', b.key);
  }
}

to

for (const b of dsBindings) {
      const ds = await this.get(b.key);
      // console.log(ds);
      // @ts-ignore
      if (operation in ds && typeof ds[operation] === 'function') {
        console.log('Migrating dataSource %s', b.key);
        // @ts-ignore
        if (!options?.models || options?.models.length === 0) {
          // @ts-ignore
          await ds[operation](options.models);
        } else {
          const models = [];
          for (const model of options?.models) {
            // @ts-ignore
            if (Object.keys(ds.definitions).includes(model)) {
              models.push(model);
            }
          }
          // @ts-ignore
          await ds[operation](models);
        }
      } else {
        // debug('Skipping migration of dataSource %s', b.key);
      }
    }

i hope this bug will be fixed soon

@deepakrkris
Copy link

duplicate of loopbackio/loopback-next#5479

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

2 participants