Skip to content

Commit a4ae384

Browse files
committed
docs: migrate datasources from lb3 to lb4
Add steps to migrate LB3 datasources to LB4
1 parent ce025b0 commit a4ae384

File tree

1 file changed

+80
-5
lines changed

1 file changed

+80
-5
lines changed

docs/site/migration/datasources.md

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,83 @@ sidebar: lb4_sidebar
66
permalink: /doc/en/lb4/migration-datasources.html
77
---
88

9-
{% include note.html content="
10-
This is a placeholder page, the task of adding content is tracked by the
11-
following GitHub issue:
12-
[loopback-next#3946](https://github.com/strongloop/loopback-next/issues/3946).
13-
" %}
9+
## Overview
10+
11+
LoopBack 3 datasources are compatible with LoopBack 4 datasources, so migrating
12+
datasources from LoopBack 3 to LoopBack 4 is simple.
13+
14+
In LoopBack 3, all datasources are defined in the `server/datasources.json`
15+
file, whereas in LoopBack 4 each datasource is defined in its own file in the
16+
`src/datasources` folder. Each LoopBack 4 datasource has a configuration file
17+
(e.g. `mysql-ds.datasource.config.json`) and a class file (e.g.
18+
`mysql-ds.datasource.ts`).
19+
20+
## Migration Steps
21+
22+
To migrate a datasource from LoopBack 3 to LoopBack 4, complete the following
23+
steps:
24+
25+
1. In the root of your LoopBack 4 application, use the `lb4 datasource` command
26+
to create a new datasource and enter the same datasource name as your
27+
LoopBack 3 application's datasource (e.g. `mysqlDs`):
28+
29+
```
30+
$ lb4 datasource
31+
? Datasource name: mysqlDs
32+
```
33+
34+
2. For the remaining prompts from the `lb4 datasource` command, use the defaults
35+
(press Enter for each one) since these will be replaced in the next step:
36+
37+
```
38+
? Select the connector for mysqlDs: In-memory db (supported by StrongLoop)
39+
? window.localStorage key to use for persistence (browser only):
40+
? Full path to file for persistence (server only):
41+
```
42+
43+
3. Replace the contents of the newly created
44+
`src/datasources/{dataSource.dataSourceName}.datasource.config.json` file in
45+
your LoopBack 4 application with the datasource configuration from
46+
`server/datasources.json` in your LoopBack 3 application.
47+
48+
{% include code-caption.html content="server/datasources.json" %}
49+
50+
```json
51+
{
52+
"mysqlDs": {
53+
"name": "mysqlDs",
54+
"connector": "mysql",
55+
"host": "demo.strongloop.com",
56+
"port": 3306,
57+
"database": "getting_started",
58+
"username": "demo",
59+
"password": "L00pBack"
60+
}
61+
}
62+
```
63+
64+
{% include code-caption.html content="src/datasources/mysql-ds.datasource.config.json" %}
65+
66+
```json
67+
{
68+
"name": "mysqlDs",
69+
"connector": "mysql",
70+
"host": "demo.strongloop.com",
71+
"port": 3306,
72+
"database": "getting_started",
73+
"username": "demo",
74+
"password": "L00pBack"
75+
}
76+
```
77+
78+
4. Repeat steps 1-3 for each datasource you want to migrate.
79+
80+
{% include note.html content="We are working on a CLI command `lb4 import-lb3-datasources` that will migrate datasources from a mounted LoopBack 3 application to a LoopBack 4 project automatically. See [GitHub issue #4346](https://github.com/strongloop/loopback-next/issues/4346) for more details." %}
81+
82+
## Compatibility
83+
84+
As mentioned before, LoopBack 3 datasources are compatible with LoopBack 4
85+
datasources. In both, a datasource is a connector instance that is used by
86+
`legacy-juggler-bridge`. For example, both a LoopBack 3 MySQL datasource and a
87+
LoopBack 4 MySQL datasource will use
88+
[`loopback-connector-mysql`](http://github.com/strongloop/loopback-connector-mysql).

0 commit comments

Comments
 (0)