Skip to content

Import LB3 DataSources to a LB4 Project #4346

@nabdelgadir

Description

@nabdelgadir

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions