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

Import LB3 DataSources to a LB4 Project #4346

Closed
3 tasks
nabdelgadir opened this issue Dec 30, 2019 · 4 comments
Closed
3 tasks

Import LB3 DataSources to a LB4 Project #4346

nabdelgadir opened this issue Dec 30, 2019 · 4 comments

Comments

@nabdelgadir
Copy link
Contributor

nabdelgadir commented Dec 30, 2019

Related to #3946.

Currently, users have to manually move their datasources from LB3 to LB4 using the steps defined in #4343. In order to automate this process, create a CLI command that will move the datasources from a mounted LB3 application to the LB4 project.

Since LB3 datasources are compatible with LB4, the same datasource configuration should be used when it's moved.

Example

Given this file in the mounted LB3 application:

lb3app/server/datasources.json

{
  "db": {
    "name": "db",
    "connector": "memory"
  },
  "mysqlDs": {
    "name": "mysqlDs",
    "connector": "mysql",
    "host": "demo.strongloop.com",
    "port": 3306,
    "database": "getting_started",
    "username": "demo",
    "password": "L00pBack"
  }
}

Create the following in the LB4 project:

src/datasources/db.datasource.config.json

{
  "name": "db",
  "connector": "memory"
}

src/datasources/db.datasource.ts

import {inject} from '@loopback/core';
import {juggler} from '@loopback/repository';
import config from './db.datasource.config.json';

export class DbDataSource extends juggler.DataSource {
  static dataSourceName = 'db';

  constructor(
    @inject('datasources.config.db', {optional: true})
    dsConfig: object = config,
  ) {
    super(dsConfig);
  }
}

src/datasources/mysqlds.datasource.config.json

{
   "name": "mysqlDs",
    "connector": "mysql",
    "host": "demo.strongloop.com",
    "port": 3306,
    "database": "getting_started",
    "username": "demo",
    "password": "L00pBack"
}

src/datasources/mysqlds.datasource.ts

import {inject} from '@loopback/core';
import {juggler} from '@loopback/repository';
import config from './mysqlds.datasource.config.json';

export class MysqlDsDataSource extends juggler.DataSource {
  static dataSourceName = 'mysqlDs';

  constructor(
    @inject('datasources.config.mysqlDs', {optional: true})
    dsConfig: object = config,
  ) {
    super(dsConfig);
  }
}

Acceptance criteria

  • Create a CLI flag lb4 import-lb3-datasources that will take in a path to a file e.g. lb4 import-lb3-datasources lb3app/servers/datasources.json and migrate all datasources similar to the example above
    • Remember to export the datasources from src/datasources/index.ts
  • Update documentation in Migrating datasources, and include limitations if any exist
@nabdelgadir
Copy link
Contributor Author

Note that since #5000 has landed, please follow the new format for the datasource definition.

@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
@nabdelgadir nabdelgadir removed the stale label Dec 31, 2020
@stale
Copy link

stale bot commented Jul 14, 2021

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 Jul 14, 2021
@stale
Copy link

stale bot commented Aug 13, 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 Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants