-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
As an LB3 user migrating my model definition files to LB4, I would like to call lb4 CLI to generate an LB4 model class from my LB3 model JSON file.
lb4 import-lb3-models legacy-lb3app/server/server.js
# load the LB3 app
# ask the user which models to import
# create src/models/product.ts etc.
The initial version should handle property definitions only.
For example, let's take an LB3 Product model with a name property:
{
"name": "Product",
"base": "PersistedModel",
"properties": {
"name": {
"type": "string",
"required": true
}
}
}
This LB3 definition should be translated into an LB4 TypeScript model class:
@model()
class Product extends Entity {
@property({required: true})
name: string;
}Acceptance criteria
- A new CLI flag for
lb4 model, or perhaps a new command, accepting a path to LB3 model file, that will scaffold (code-generate) an LB4 model file from LB3 definition. See Model Discovery #2245 for related prior work. (/cc @marvinirwin)
--> see CLI: Import LB3 model(s) into LB4 project [EXPERIMENTAL] #3688 - The following base model classes should be recognized and mapped to LB4:
Model->ModelPersistedModel->EntityKeyValueModel-> (to be determined)
When the base model class is not recognized, the CLI should abort with a descriptive error.
--> see CLI: Import LB3 model(s) into LB4 project [EXPERIMENTAL] #3688
- The following model settings should trigger a warning when a non-empty value is provided in LB3 model file:
relationsmethodmixinsacls
--> see CLI: Import LB3 model(s) into LB4 project [EXPERIMENTAL] #3688
- All other model settings should be copied as-is to LB4 model definition. IMPORTANT: settings can be specified either at top-level or inside
optionsproperty, we need to support both flavors. Notable settings to test & support:forceIdstrict- connector-specific config like SQL table name and MongoDB collection name
--> see CLI: Import LB3 model(s) into LB4 project [EXPERIMENTAL] #3688
- Documentation at CLI level
--> see CLI: Import LB3 model(s) into LB4 project [EXPERIMENTAL] #3688 - A blog post
- Follow-up stories for things that were left out of the initial implementation. Most notably support for non-default
basemodel classes and relations.
See #2036 for the next step that will allow developers to take LB4 model and expose it via REST with little to no configuration.
Open discussion points & todos
- Should we offer built-in models like
UserandAccessTokenfor importing? - Should we select all models by default?
- How to automate model selection? Should we introduce a cli option like
--models User,AccessToken? Use positional arguments likelb4 import-model my-lb3-app User AccessToken? - Process TODO & FIXME comments in the initial implementation CLI: Import LB3 model(s) into LB4 project [EXPERIMENTAL] #3688 and convert them to sub-tasks or follow-up issues
- Write automated test to verify import of models attached to the following connectors:
- SQL (MySQL or Postgres)
- MongoDB (how is ObjectID type handled?)
- Cloudant (how is
_revproperty handled?)
Out of scope
- relations
- remote methods
- ACLs
- mixins
- Custom model property settings must be preserved, e.g. SQL column names.
- A new section in the migration guide
sylvaindumont and uniconstructor