-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
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-datasourcesthat will take in a path to a file e.g.lb4 import-lb3-datasources lb3app/servers/datasources.jsonand migrate all datasources similar to the example above- Remember to export the datasources from
src/datasources/index.ts
- Remember to export the datasources from
- Update documentation in Migrating datasources, and include limitations if any exist