Skip to content

Import LB3 model JSON file to LB4 model class #2480

@bajtos

Description

@bajtos

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

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 User and AccessToken for 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 like lb4 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 _rev property 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions